Browse Source

Add rebar.config, dialyzer fixes

Marc Worrell 3 years ago
parent
commit
67c8685bd5
4 changed files with 27 additions and 47 deletions
  1. 26 0
      rebar.config
  2. 1 0
      rebar.lock
  3. 0 2
      src/oauth.erl
  4. 0 45
      test.escript

+ 26 - 0
rebar.config

@@ -0,0 +1,26 @@
+%%
+%% rebar configuration file (https://github.com/rebar/rebar)
+%%
+
+{require_min_otp_vsn, "21"}.
+
+{erl_opts, [
+    debug_info,
+    fail_on_warning
+ ]
+}.
+
+{xref_checks, [
+    undefined_function_calls,
+    locals_not_used,
+    deprecated_function_calls
+]}.
+
+{xref_ignores, [
+]}.
+
+{dialyzer, [
+  {warnings, [
+      % no_return
+  ]}
+]}.

+ 1 - 0
rebar.lock

@@ -0,0 +1 @@
+[].

+ 0 - 2
src/oauth.erl

@@ -191,8 +191,6 @@ rsa_sha1_verify(Signature, BaseString, Consumer) when is_binary(BaseString) ->
 rsa_sha1_verify(Signature, BaseString, Consumer) when is_list(BaseString) ->
 rsa_sha1_verify(Signature, BaseString, Consumer) when is_list(BaseString) ->
   rsa_sha1_verify(Signature, list_to_binary(BaseString), Consumer).
   rsa_sha1_verify(Signature, list_to_binary(BaseString), Consumer).
 
 
-verify_in_constant_time(<<X/binary>>, <<Y/binary>>) ->
-  verify_in_constant_time(binary_to_list(X), binary_to_list(Y));
 verify_in_constant_time(X, Y) when is_list(X) and is_list(Y) ->
 verify_in_constant_time(X, Y) when is_list(X) and is_list(Y) ->
   case length(X) == length(Y) of
   case length(X) == length(Y) of
     true ->
     true ->

+ 0 - 45
test.escript

@@ -1,45 +0,0 @@
-#!/usr/bin/env escript
-
--include_lib("eunit/include/eunit.hrl").
-
-main([]) ->
-  code:add_path("ebin"),
-  Tests = lists:append([signature_base_string_tests(), plaintext_tests(), hmac_sha1_tests(), rsa_sha1_tests()]),
-  halt(case eunit:test(Tests) of ok -> 0; {error, _} -> 1 end).
-
-signature_base_string_tests() ->
-  test_with("base_string_test_*", [method, url, params, base_string], fun (Method, URL, Params, BaseString) ->
-    [?_assertEqual(BaseString, oauth:signature_base_string(Method, URL, Params))]
-  end).
-
-plaintext_tests() ->
-  test_with("plaintext_test_*", [consumer, token_secret, signature], fun (Consumer, TokenSecret, Signature) ->
-    SignatureTest = ?_assertEqual(Signature, oauth:plaintext_signature(Consumer, TokenSecret)),
-    VerifyTest = ?_assertEqual(true, oauth:plaintext_verify(Signature, Consumer, TokenSecret)),
-    [SignatureTest, VerifyTest]
-  end).
-
-hmac_sha1_tests() ->
-  test_with("hmac_sha1_test_*", [base_string, consumer, token_secret, signature], fun (BaseString, Consumer, TokenSecret, Signature) ->
-    SignatureTest = ?_assertEqual(Signature, oauth:hmac_sha1_signature(BaseString, Consumer, TokenSecret)),
-    VerifyTest = ?_assertEqual(true, oauth:hmac_sha1_verify(Signature, BaseString, Consumer, TokenSecret)),
-    [SignatureTest, VerifyTest]
-  end).
-
-rsa_sha1_tests() ->
-  Pkey = data_path("rsa_sha1_private_key.pem"),
-  Cert = data_path("rsa_sha1_certificate.pem"),
-  [BaseString, Signature] = read([base_string, signature], data_path("rsa_sha1_test")),
-  SignatureTest = ?_assertEqual(Signature, oauth:rsa_sha1_signature(BaseString, {"", Pkey, rsa_sha1})),
-  VerifyTest = ?_assertEqual(true, oauth:rsa_sha1_verify(Signature, BaseString, {"", Cert, rsa_sha1})),
-  [SignatureTest, VerifyTest].
-
-test_with(FilenamePattern, Keys, Fun) ->
-  lists:flatten(lists:map(fun (Path) -> apply(Fun, read(Keys, Path)) end, filelib:wildcard(data_path(FilenamePattern)))).
-
-data_path(Basename) ->
-  filename:join(["testdata", Basename]).
-
-read(Keys, Path) ->
-  {ok, Proplist} = file:consult(Path),
-  [proplists:get_value(K, Proplist) || K <- Keys].