~umgeher/canola

2507f698b4dc1156b07dbf568fc651730942fe73 — Martin Sumner 1 year, 7 months ago 9bdfee8 + 15ca8c8
Merge pull request #3 from basho/develop-3.2

Develop 3.2
10 files changed, 164 insertions(+), 55 deletions(-)

A .github/workflows/erlang.yml
M .gitignore
M Makefile
D rebar
M rebar.config
A rebar.lock
A rebar3
M src/canola.erl
A test/canola_tests.erl
D tools.mk
A .github/workflows/erlang.yml => .github/workflows/erlang.yml +37 -0
@@ 0,0 1,37 @@
name: Erlang CI

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]


jobs:

  build:

    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        otp:
          - "25.1"
          - "24.3"
          - "22.3"

    container:
      image: erlang:${{ matrix.otp }}

    steps:
      - uses: lukka/get-cmake@latest
      - uses: actions/checkout@v2
      - name: Pre-Compile
        run: apt-get update && apt-get install -y libpam0g-dev
      - name: Compile
        run: ./rebar3 compile
      - name: Run xref and dialyzer
        run: ./rebar3 do xref, dialyzer
      - name: Run eunit
        run: ./rebar3 as gha do eunit

M .gitignore => .gitignore +3 -0
@@ 1,3 1,6 @@
*.o
*.d
ebin
priv/canola-port
_build
_DS_Store

M Makefile => Makefile +16 -7
@@ 1,13 1,22 @@
.PHONY: all compile clean

all: compile
.PHONY: compile rel cover test dialyzer
REBAR=./rebar3

compile:
	./rebar compile
	$(REBAR) compile

clean:
	./rebar clean
	$(REBAR) clean

cover: test
	$(REBAR) cover

test: compile
	$(REBAR) as test do eunit

dialyzer:
	$(REBAR) dialyzer

DIALYZER_APPS = kernel stdlib erts sasl eunit syntax_tools compiler crypto
xref:
	$(REBAR) xref

include tools.mk
check: test dialyzer xref

D rebar => rebar +0 -0
M rebar.config => rebar.config +21 -0
@@ 1,3 1,24 @@
{port_specs, [{"priv/canola-port", ["c_src/canola-port.c"]}]}.

{port_env, [{"LDFLAGS", "$LDFLAGS -lpam"}]}.
{cover_enabled, true}.

{plugins, [pc]}.

{profiles, [
    {gha, [{erl_opts, [{d, 'GITHUBEXCLUDE'}]}]}
]}.

{provider_hooks,
 [
  {pre,
   [
    {compile, {pc, compile}},
    {clean, {pc, clean}}
   ]
  }
 ]
}.

{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
    deprecated_function_calls, deprecated_functions]}.

A rebar.lock => rebar.lock +1 -0
@@ 0,0 1,1 @@
[].

A rebar3 => rebar3 +0 -0
M src/canola.erl => src/canola.erl +15 -3
@@ 35,7 35,9 @@ auth(Username, Password, Service, Port) when is_binary(Username), is_binary(Pass
            error;
        {Port, {exit_status, _}} ->
            erlang:error(badarg)
    end.
    end;
auth(_, _, _, _) ->
    erlang:error(badarg).

close(Port) ->
    port_close(Port).


@@ 49,5 51,15 @@ open2(Debug) ->
               _ ->
                   []
           end,
    Dir = filename:dirname(code:which(?MODULE)),
    open_port({spawn_executable, Dir++"/../priv/canola-port"}, [{args, Args}, {packet, 4}, exit_status]).
    PortBin = case code:priv_dir(ebloom) of
                 {error, bad_name} ->
                     case code:which(?MODULE) of
                         Filename when is_list(Filename) ->
                             filename:join([filename:dirname(Filename),"../priv", "canola-port"]);
                         _ ->
                             filename:join("priv", "canola-port")
                     end;
                 Dir ->
                     filename:join(Dir, "canpola-port")
             end,
    open_port({spawn_executable, PortBin}, [{args, Args}, {packet, 4}, exit_status]).

A test/canola_tests.erl => test/canola_tests.erl +71 -0
@@ 0,0 1,71 @@
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2017 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License.  You may obtain
%% a copy of the License at
%%
%%   http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied.  See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------

-module(canola_tests).

-include_lib("eunit/include/eunit.hrl").


-ifdef(GITHUBEXCLUDE).

user_test() ->
    P = canola:open_debug(),
    canola:close(P).

-else.

auth_test_() ->
    {timeout, 30, fun() ->
        BogusPW = <<"ReallyHopeThisIsntYourPassword">>,
        FakeSvc = <<"ThereShouldntBeAServiceWithThisName">>,
        RealSvc = <<"login">>,
        FakeUsr = <<"NoSuchUserWeHope">>,
        UsrName = 
            case os:getenv("USER") of
                false ->
                    os:getenv("LOGNAME");
                Name ->
                    Name
            end,
        P = canola:open_debug(),
        ?assert(erlang:is_list(UsrName)),
        RealUsr = erlang:list_to_binary(UsrName),

        Ret1 = canola:auth(RealSvc, RealUsr, BogusPW, P),
        % ?debugVal(Ret1),
        ?assertEqual(error, Ret1),

        Ret2 = canola:auth(FakeSvc, RealUsr, BogusPW, P),
        % ?debugVal(Ret2),
        ?assertEqual(error, Ret2),

        Ret3 = canola:auth(RealSvc, <<"root">>, <<"password">>, P),
        % ?debugVal(Ret3),
        ?assertEqual(error, Ret3),

        Ret4 = canola:auth(RealSvc, FakeUsr, BogusPW, P),
        % ?debugVal(Ret4),
        ?assertEqual(error, Ret4),

        ?assertError(badarg, canola:auth(RealSvc, UsrName, BogusPW, P)),
        canola:close(P)
    end}.

-endif.
\ No newline at end of file

D tools.mk => tools.mk +0 -45
@@ 1,45 0,0 @@
test: compile
	./rebar eunit skip_deps=true

docs:
	./rebar doc skip_deps=true

PLT ?= $(HOME)/.riak_combo_dialyzer_plt
LOCAL_PLT = .local_dialyzer_plt
DIALYZER_FLAGS ?= -Wunmatched_returns

${PLT}: compile
ifneq (,$(wildcard $(PLT)))
	dialyzer --check_plt --plt $(PLT) --apps $(DIALYZER_APPS) && \
		dialyzer --add_to_plt --plt $(PLT) --output_plt $(PLT) --apps $(DIALYZER_APPS) ; test $$? -ne 1
else
	dialyzer --build_plt --output_plt $(PLT) --apps $(DIALYZER_APPS); test $$? -ne 1
endif

${LOCAL_PLT}: compile
ifneq (,$(wildcard deps/*))
ifneq (,$(wildcard $(LOCAL_PLT)))
	dialyzer --check_plt --plt $(LOCAL_PLT) deps/*/ebin  && \
		dialyzer --add_to_plt --plt $(LOCAL_PLT) --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
else
	dialyzer --build_plt --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
endif
endif

dialyzer: ${PLT} ${LOCAL_PLT}
	@echo "==> $(shell basename $(shell pwd)) (dialyzer)"
	@if [ -f $(LOCAL_PLT) ]; then \
		dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin; \
	else \
		dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin; \
	fi

cleanplt:
	@echo 
	@echo "Are you sure?  It takes several minutes to re-build."
	@echo Deleting $(PLT) and $(LOCAL_PLT) in 5 seconds.
	@echo 
	sleep 5
	rm $(PLT)
	rm $(LOCAL_PLT)