Skip to content

Commit

Permalink
Port to rebar3
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Feb 9, 2018
1 parent 9bdfee8 commit 246e63f
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.o
ebin
priv/canola-port
_build
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: erlang

otp_release:
- 20.1

script: ./rebar3 as test do eunit, dialyzer, xref
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Binary file removed rebar
Binary file not shown.
16 changes: 16 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
{port_specs, [{"priv/canola-port", ["c_src/canola-port.c"]}]}.

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

{plugins, [pc]}.

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

{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
deprecated_function_calls, deprecated_functions]}.
1 change: 1 addition & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[].
Binary file added rebar3
Binary file not shown.
4 changes: 3 additions & 1 deletion src/canola.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
76 changes: 76 additions & 0 deletions test/canola_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
%% -------------------------------------------------------------------
%%
%% 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").

%%
%% If there's a known account in PAM on your local system for testing,
%% define this to the service, username, and password for a live test.
%% DO NOT commit a dependency on your local configuration!
%%
% -define(TEST_LOCAL_USER, {<<"cups">>, <<"guest">>, <<"">>}).

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}.

-ifdef(TEST_LOCAL_USER).

user_test() ->
P = canola:open_debug(),
{Service, Username, Password} = ?TEST_LOCAL_USER,
?assertEqual(ok, canola:auth(Service, Username, Password, P)),
canola:close(P).

-endif. % TEST_USER_NAME_PASS
45 changes: 0 additions & 45 deletions tools.mk

This file was deleted.

0 comments on commit 246e63f

Please sign in to comment.