Permalink
Browse files

Add PropEr support and fix specs accordingly

  • Loading branch information...
bipthelin committed Nov 28, 2012
1 parent 8592dc9 commit 9afded8a3e40260430444c1e7e5ff20ff0b24613
View
@@ -39,10 +39,8 @@
,verify_redirection_uri/2
]).
-%%% Internal types
--type proplist(TyKey, TyVal) :: [{TyKey, TyVal}].
-
%%% Exported types
+-type proplist(TyKey, TyVal) :: [{TyKey, TyVal}].
-type token() :: binary().
-type lifetime() :: non_neg_integer().
-type scope() :: list(binary()) | binary().
@@ -56,6 +54,7 @@
,lifetime/0
,scope/0
,error/0
+ ,proplist/2
]).
%%%===================================================================
View
@@ -52,7 +52,7 @@ new(Path) when is_binary(Path) ->
%% @doc Returns the union of Set1 and Set2, i.e., a set such that
%% any path present in either Set1 or Set2 is also present in the result.
%% @end
--spec union(Set1 :: priv_set(), Set2 :: priv_set) -> Union :: priv_set().
+-spec union(Set1 :: priv_set(), Set2 :: priv_set()) -> Union :: priv_set().
union([H1={node, Name1, _}|T1], [H2={node, Name2, _}|T2]) when Name1 < Name2 ->
[H1|union(T1, [H2|T2])];
union([H1={node, Name1, _}|T1], [H2={node, Name2, _}|T2]) when Name1 > Name2 ->
@@ -67,7 +67,7 @@ union([], Set) ->
Set;
union(Set, []) ->
Set.
-
+
%% @doc Return true if Set1 is a subset of Set2, i.e., if
%% every privilege held by Set1 is also held by Set2.
%% @end
@@ -95,7 +95,7 @@ is_subset(_, _) ->
%% @doc Returns true if Path is present in Set, i.e, if
%% the privilege denoted by Path is contained within Set.
%% @end
--spec is_member(Path :: binary() | [binary()], Set :: priv_set()) -> boolean().
+-spec is_member(Path :: binary(), Set :: priv_set()) -> boolean().
is_member(Path, Set) ->
is_subset(make_forest(Path), Set).
View
@@ -82,7 +82,7 @@ new(AccessToken, ExpiresIn) ->
-spec new(AccessToken, ExpiresIn, ResOwner, Scope) -> response() when
AccessToken :: oauth2:token(),
- ExpiresIn :: oaut2:lifetime(),
+ ExpiresIn :: oauth2:lifetime(),
ResOwner :: term(),
Scope :: oauth2:scope().
new(AccessToken, ExpiresIn, ResOwner, Scope) ->
@@ -93,7 +93,7 @@ new(AccessToken, ExpiresIn, ResOwner, Scope) ->
-spec new(AccessToken, ExpiresIn, ResOwner, Scope, RefreshToken) -> response() when
AccessToken :: oauth2:token(),
- ExpiresIn :: oaut2:lifetime(),
+ ExpiresIn :: oauth2:lifetime(),
ResOwner :: term(),
Scope :: oauth2:scope(),
RefreshToken :: oauth2:token().
@@ -106,7 +106,7 @@ new(AccessToken, ExpiresIn, ResOwner, Scope, RefreshToken) ->
-spec new(_AccessToken, ExpiresIn, ResOwner, Scope, _RefreshToken, AccessCode) -> response() when
_AccessToken :: oauth2:token(),
- ExpiresIn :: oaut2:lifetime(),
+ ExpiresIn :: oauth2:lifetime(),
ResOwner :: term(),
Scope :: oauth2:scope(),
_RefreshToken :: oauth2:token(),
@@ -129,7 +129,10 @@ access_token(#response{access_token = AccessToken}) ->
access_token(Response, NewAccessToken) ->
Response#response{access_token = NewAccessToken}.
--spec access_code(response()) -> {ok, AccessToken :: oauth2:token()}.
+-spec access_code(response()) -> {ok, AccessCode} | {error, not_set} when
+ AccessCode :: oauth2:token().
+access_code(#response{access_code = undefined}) ->
+ {error, not_set};
access_code(#response{access_code = AccessCode}) ->
{ok, AccessCode}.
@@ -184,7 +187,7 @@ resource_owner(#response{resource_owner = ResOwner}) ->
resource_owner(Response, NewResOwner) ->
Response#response{resource_owner = NewResOwner}.
--spec to_proplist(response()) -> oauth2:proplist().
+-spec to_proplist(response()) -> oauth2:proplist(binary(), binary()).
to_proplist(Response) ->
Keys = lists:map(fun to_binary/1, record_info(fields, response)),
Values = tl(tuple_to_list(Response)), %% Head is 'response'!
@@ -194,9 +197,15 @@ to_proplist(Response) ->
%%% Internal functions
%%%===================================================================
+to_binary(Binary) when is_binary(Binary) ->
+ Binary;
+to_binary(List) when is_list(List) ->
+ to_binary(list_to_binary(List));
to_binary(Atom) when is_atom(Atom) ->
- list_to_binary(atom_to_list(Atom));
+ to_binary(atom_to_list(Atom));
+to_binary(Float) when is_float(Float) ->
+ to_binary(float_to_list(Float));
to_binary(Integer) when is_integer(Integer) ->
- list_to_binary(integer_to_list(Integer));
-to_binary(Binary) when is_binary(Binary) ->
- Binary.
+ to_binary(integer_to_list(Integer));
+to_binary(Term) ->
+ to_binary(term_to_binary(Term)).
@@ -26,12 +26,18 @@
-module(oauth2_priv_set_tests).
+-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
%%%===================================================================
%%% Test cases
%%%===================================================================
+proper_type_spec_test_() ->
+ {timeout, 1200, [{?LINE,
+ fun() -> proper:check_specs(oauth2_priv_set,
+ [{to_file, user}]) end}]}.
+
new_test_() ->
[
?_assert(oauth2_priv_set:is_member(
@@ -26,6 +26,7 @@
-module(oauth2_response_tests).
+-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
-define(ACCESS, <<"9bX9iFUOsXbM12OOjfDW175IXXOELp6K">>).
@@ -39,6 +40,11 @@
%%% Test cases
%%%===================================================================
+proper_type_spec_test_() ->
+ {timeout, 1200, [{?LINE,
+ fun() -> proper:check_specs(oauth2_response,
+ [{to_file, user}]) end}]}.
+
new_1_test_() ->
{setup,
fun() -> oauth2_response:new(?ACCESS) end,
View
@@ -26,6 +26,7 @@
-module(oauth2_tests).
+-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
%%% Placeholder values that the mock backend will recognize.
@@ -45,6 +46,11 @@
%%% Test cases
%%%===================================================================
+proper_type_spec_test_() ->
+ {timeout, 1200, [{?LINE,
+ fun() -> proper:check_specs(oauth2,
+ [{to_file, user}]) end}]}.
+
bad_authorize_password_test_() ->
{setup,
fun start/0,
@@ -27,12 +27,18 @@
-module(oauth2_token_tests).
-include("oauth2.hrl").
+-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
%%%===================================================================
%%% Test cases
%%%===================================================================
+proper_type_spec_test_() ->
+ {timeout, 1200, [{?LINE,
+ fun() -> proper:check_specs(oauth2_token,
+ [{to_file, user}]) end}]}.
+
generate_test() ->
Token = oauth2_token:generate(),
?assertEqual(byte_size(Token), ?TOKEN_LENGTH),

0 comments on commit 9afded8

Please sign in to comment.