Skip to content

Commit 396d05b

Browse files
authored
chore: modernise the repository a bit (#18)
* Pin specific versions and help Renovate This way it's easier for us to reason on the updates semantically. * Add a few "good practice" compiler warnings As per https://github.com/kivra/erlang_template * "Temporarily" prevent jose's deprecation warning from compiling self * Add `dialyzer` options * Act on dialyzer's `unmatched_returns` * Prevent Dialyzer's "Unknown function jsx:decode" ... while applying the good practice to list all deps under .app.src * xref: stop caring about "unused exports" It's either this or flagging all "interface API" functions as -ignore_xref, which is potentially more difficult to maintain. Choices (?) * Enable test coverage * Don't fight Elvis on this (work around it) If we fix for Elvis we get a compiler warning * Fix compiler warnings * Act on CI results: fix for `rebar3_lint` * Own it
1 parent 8450b8f commit 396d05b

10 files changed

+47
-15
lines changed

.github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# the project is owned by the platform team
2+
* @kivra/platform-team

rebar.config

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
{erl_opts, [debug_info]}.
1+
{erl_opts, [
2+
debug_info,
3+
warnings_as_errors,
4+
warn_export_vars,
5+
warn_unused_import,
6+
warn_keywords
7+
]}.
8+
9+
{dialyzer, [
10+
{plt_apps, all_deps},
11+
incremental,
12+
{warnings, [unmatched_returns]}
13+
]}.
14+
15+
{overrides, [
16+
{override, jose, [{erl_opts, [debug_info, no_warnings_as_errors]}]}
17+
]}.
18+
219
{deps, [ {jsx, {git, "https://github.com/talentdeficit/jsx.git" , {tag, "v3.1.0"}}}
320
, {jose, {git, "https://github.com/potatosalad/erlang-jose.git" , {tag, "1.11.5"}}}
421
, {hackney, {git, "https://github.com/benoitc/hackney.git" , {tag, "1.18.0"}}}
@@ -15,9 +32,19 @@
1532

1633
{profiles,
1734
[{test, [
35+
{cover_enabled, true},
36+
{cover_opts, [verbose]},
1837
{erl_opts, [nowarn_export_all]},
19-
{deps, [ proper
38+
{deps, [ {proper, "1.4.0"}
2039
, {meck, "0.8.13"}
2140
]}
2241
]}
2342
]}.
43+
44+
{xref_checks, [
45+
undefined_function_calls,
46+
undefined_functions,
47+
locals_not_used,
48+
deprecated_function_calls,
49+
deprecated_functions
50+
]}.

src/ets_pubkeys_storage.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ put(#{<<"kid">> := Kid} = Key) ->
3434

3535
%% gen_server callbacks
3636
init(A) ->
37-
ets:new(?MODULE, ?ETS_OPTIONS),
37+
?MODULE = ets:new(?MODULE, ?ETS_OPTIONS),
3838
{ok, A}.
3939
handle_call(_, _, S) -> {noreply, S}.
4040
handle_cast(_, S) -> {noreply, S}.

src/id_token.app.src

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
[kernel,
88
stdlib,
99
hackney,
10-
jose
10+
jose,
11+
jsx
1112
]},
1213
{env,[]},
1314
{modules, []},

src/id_token_provider.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ add_provider(Name, Uri) ->
4646
%%% gen_server callbacks
4747
%%%===================================================================
4848
init([]) ->
49-
ets:new(?ID_TOKEN_CACHE, ?ETS_OPTIONS),
49+
?ID_TOKEN_CACHE = ets:new(?ID_TOKEN_CACHE, ?ETS_OPTIONS),
5050
Providers = id_token_jwks:get_providers(),
5151
lists:foreach(fun add_provider/1, Providers),
5252
case application:get_env(id_token, async_revalidate, false) of
@@ -79,7 +79,7 @@ handle_info({refresh, Provider}, State) ->
7979
%% the price and re-initiate async_revalidate-loop after 10 seconds
8080
10_000
8181
end,
82-
timer:send_after(Delay, self(), {refresh, Provider}),
82+
{ok, _} = timer:send_after(Delay, self(), {refresh, Provider}),
8383
{noreply, State}.
8484

8585
maybe_refresh(Provider, #{force_refresh := true}) ->

src/id_token_pubkeys_storage.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
-define(call_callback(Args),
2929
begin
3030
Mod = ?BACKEND,
31-
code:ensure_loaded(Mod),
31+
_ = code:ensure_loaded(Mod),
3232
case erlang:function_exported(Mod, ?FUNCTION_NAME, ?FUNCTION_ARITY) of
3333
true -> erlang:apply(Mod, ?FUNCTION_NAME, Args);
3434
false -> {error, not_exported}

src/id_token_sign.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ add_key_for(Alg, Options) ->
4646
%%%===================================================================
4747
init([]) ->
4848
id_token_pubkeys_storage:start(),
49-
ets:new(?MODULE, ?ETS_OPTIONS),
49+
?MODULE = ets:new(?MODULE, ?ETS_OPTIONS),
5050
SignKeys = application:get_env(id_token, sign_keys, []),
5151
Timers = lists:sort([put_key_for(Alg, Opts) || {Alg, Opts} <- SignKeys]),
5252
{ok, Timers, timeout(Timers)}.

test/prop_id_token_jwt.erl

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<<"RS256">>, <<"RS384">>, <<"RS512">>,
1111
<<"ES256">>, <<"ES384">>, <<"ES512">>]).
1212

13+
-elvis([{elvis_style, used_ignored_variable, disable}]).
14+
1315
%%%%%%%%%%%%%%%%%%%%
1416
%%% Eunit runner %%%
1517
%%%%%%%%%%%%%%%%%%%%
@@ -38,7 +40,7 @@ prop_valid_signature() ->
3840
end).
3941

4042
prop_invalid_signature() ->
41-
?FORALL({{JWK, PublicKeyMap}, {OtherJWK, OtherPublicKeyMap}, Claims},
43+
?FORALL({{JWK, _PublicKeyMap}, {OtherJWK, OtherPublicKeyMap}, Claims},
4244
{key_pair(), key_pair(), jwt_claims()},
4345
begin
4446
#jose_jwk{fields = OtherFields} = OtherJWK,
@@ -49,7 +51,7 @@ prop_invalid_signature() ->
4951
end).
5052

5153
prop_no_matching_key() ->
52-
?FORALL({[{JWK, PublicKeyMap} | OtherKeys], Claims},
54+
?FORALL({[{JWK, _PublicKeyMap} | OtherKeys], Claims},
5355
{non_empty(list(key_pair())), jwt_claims()},
5456
begin
5557
JWT = id_token_jws:sign(Claims, JWK),

test/prop_id_token_sign.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
%%%%%%%%%%%%%%%%%%%%
1616
eunit_test_() ->
1717
Opts = [{numtests, 30}],
18-
?_assert(proper:quickcheck(prop_test(), Opts)).
18+
?_assert(proper:quickcheck(prop_test2(), Opts)).
1919

2020
%%%%%%%%%%%%%%%%%%
2121
%%% PROPERTIES %%%
2222
%%%%%%%%%%%%%%%%%%
23-
prop_test() ->
23+
prop_test2() ->
2424
?FORALL(Cmds, commands(?MODULE),
2525
begin
2626
id_token_sign:start_link(),

test/prop_pubkeys_storage.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
%%%%%%%%%%%%%%%%%%%%
1212
eunit_test_() ->
1313
Opts = [{numtests, 30}],
14-
?_assert(proper:quickcheck(prop_test(), Opts)).
14+
?_assert(proper:quickcheck(prop_test1(), Opts)).
1515

1616
%%%%%%%%%%%%%%%%%%
1717
%%% PROPERTIES %%%
1818
%%%%%%%%%%%%%%%%%%
19-
prop_test() ->
19+
prop_test1() ->
2020
?FORALL(Cmds, commands(?MODULE),
2121
begin
2222
id_token_pubkeys_storage:start(),
@@ -54,7 +54,7 @@ postcondition(State, {call, _Mod, get_all, _Args}, {ok, Res}) ->
5454
lists:sort(maps:values(State)) =:= lists:sort(Res);
5555
postcondition(State, {call, _Mod, get, [Kid]}, Res) ->
5656
case {maps:find(Kid, State), Res} of
57-
{{ok, _V}, {ok, _V}} -> true;
57+
{{ok, V}, {ok, V}} -> true;
5858
{error, {error, not_found}} -> true;
5959
_ -> false
6060
end;

0 commit comments

Comments
 (0)