Update ejabberd_auth_http by fixing Dialyzer error reports (#284)

This commit is contained in:
Badlop 2020-02-11 22:51:37 +01:00
parent 9d51b80051
commit 2fcf924747
1 changed files with 36 additions and 35 deletions

View File

@ -36,7 +36,7 @@
-spec start(binary()) -> ok. -spec start(binary()) -> ok.
start(Host) -> start(Host) ->
AuthOpts = ejabberd_config:get_option({auth_opts, Host}, fun(V) -> V end), AuthOpts = ejabberd_config:get_option({auth_opts, Host}),
{_, AuthHost} = lists:keyfind(host, 1, AuthOpts), {_, AuthHost} = lists:keyfind(host, 1, AuthOpts),
PoolSize = proplists:get_value(connection_pool_size, AuthOpts, 10), PoolSize = proplists:get_value(connection_pool_size, AuthOpts, 10),
Opts = proplists:get_value(connection_opts, AuthOpts, []), Opts = proplists:get_value(connection_opts, AuthOpts, []),
@ -46,29 +46,33 @@ start(Host) ->
ChildSpec = {Proc, {cuesport, start_link, ChildSpec = {Proc, {cuesport, start_link,
[pool_name(Host), PoolSize, ChildMods, ChildMFA]}, [pool_name(Host), PoolSize, ChildMods, ChildMFA]},
transient, 2000, supervisor, [cuesport | ChildMods]}, transient, 2000, supervisor, [cuesport | ChildMods]},
supervisor:start_child(ejabberd_backend_sup, ChildSpec). supervisor:start_child(ejabberd_backend_sup, ChildSpec),
ok.
-spec plain_password_required(binary()) -> false. -spec plain_password_required(binary()) -> false.
plain_password_required(Server) -> plain_password_required(_Server) ->
store_type(Server) == scram. false.
-spec store_type(binary()) -> external. -spec store_type(binary()) -> external.
store_type(_) -> store_type(_) ->
external. external.
-spec check_password(ejabberd:luser(), binary(), ejabberd:lserver(), binary()) -> boolean(). -spec check_password(binary(), binary(), binary(), binary()) -> {ets_cache:tag(), boolean()}.
check_password(LUser, _AuthzId, LServer, Password) -> check_password(LUser, _AuthzId, LServer, Password) ->
case scram2:enabled(LServer) of case scram2:enabled(LServer) of
false -> false ->
case make_req(get, <<"check_password">>, LUser, LServer, Password) of case make_req(get, <<"check_password">>, LUser, LServer, Password) of
{ok, <<"true">>} -> true; {ok, <<"true">>} -> {cache, true};
_ -> false _ -> {nocache, false}
end; end;
true -> true ->
{ok, true} =:= verify_scram_password(LUser, LServer, Password) case verify_scram_password(LUser, LServer, Password) of
{ok, true} -> {cache, true};
_ -> {nocache, false}
end
end. end.
-spec check_password(ejabberd:luser(), binary(), ejabberd:lserver(), binary(), binary(), fun()) -> boolean(). -spec check_password(binary(), binary(), binary(), binary(), binary(), fun()) -> boolean().
check_password(LUser, _AuthzId, LServer, Password, Digest, DigestGen) -> check_password(LUser, _AuthzId, LServer, Password, Digest, DigestGen) ->
case make_req(get, <<"get_password">>, LUser, LServer, <<"">>) of case make_req(get, <<"get_password">>, LUser, LServer, <<"">>) of
{error, _} -> {error, _} ->
@ -102,7 +106,7 @@ check_digest(Digest, DigestGen, Password, Passwd) ->
end. end.
-spec set_password(ejabberd:luser(), ejabberd:lserver(), binary()) -> ok | {error, term()}. -spec set_password(binary(), binary(), binary()) -> {ets_cache:tag(), {ok, binary()} | {error, not_allowed}}.
set_password(LUser, LServer, Password) -> set_password(LUser, LServer, Password) ->
PasswordFinal = case scram2:enabled(LServer) of PasswordFinal = case scram2:enabled(LServer) of
true -> scram2:serialize(scram2:password_to_scram( true -> scram2:serialize(scram2:password_to_scram(
@ -110,11 +114,11 @@ set_password(LUser, LServer, Password) ->
false -> Password false -> Password
end, end,
case make_req(post, <<"set_password">>, LUser, LServer, PasswordFinal) of case make_req(post, <<"set_password">>, LUser, LServer, PasswordFinal) of
{error, _} = Err -> Err; {error, _Error} -> {nocache, {error, not_allowed}};
_ -> ok {ok, _} -> {cache, {ok, Password}}
end. end.
-spec try_register(ejabberd:luser(), ejabberd:lserver(), binary()) -> ok | {error, atom()}. -spec try_register(binary(), binary(), binary()) -> {ets_cache:tag(), {ok, binary()} | {error, exists | not_allowed}}.
try_register(LUser, LServer, Password) -> try_register(LUser, LServer, Password) ->
PasswordFinal = case scram2:enabled(LServer) of PasswordFinal = case scram2:enabled(LServer) of
true -> scram2:serialize(scram2:password_to_scram( true -> scram2:serialize(scram2:password_to_scram(
@ -122,34 +126,31 @@ try_register(LUser, LServer, Password) ->
false -> Password false -> Password
end, end,
case make_req(post, <<"register">>, LUser, LServer, PasswordFinal) of case make_req(post, <<"register">>, LUser, LServer, PasswordFinal) of
{ok, created} -> ok; {ok, created} -> {cache, {ok, Password}};
{error, conflict} -> {error, exists}; {error, conflict} -> {nocache, {error, exists}};
Error -> Error _Error -> {nocache, {error, not_allowed}}
end. end.
-spec get_password(ejabberd:luser(), ejabberd:lserver()) -> error. -spec get_password(binary(), binary()) -> {cache, error}.
get_password(_, _) -> get_password(_, _) ->
error. {cache, error}.
-spec get_password_s(ejabberd:luser(), ejabberd:lserver()) -> binary(). -spec get_password_s(binary(), binary()) -> {cache, error}.
get_password_s(User, Server) -> get_password_s(User, Server) ->
case get_password(User, Server) of {cache, error}.
Pass when is_binary(Pass) -> Pass;
_ -> <<>>
end.
-spec user_exists(ejabberd:luser(), ejabberd:lserver()) -> boolean(). -spec user_exists(binary(), binary()) -> {ets_cache:tag(), boolean()}.
user_exists(LUser, LServer) -> user_exists(LUser, LServer) ->
case make_req(get, <<"user_exists">>, LUser, LServer, <<"">>) of case make_req(get, <<"user_exists">>, LUser, LServer, <<"">>) of
{ok, <<"true">>} -> true; {ok, <<"true">>} -> {cache, true};
_ -> false _ -> {nocache, false}
end. end.
-spec remove_user(ejabberd:luser(), ejabberd:lserver()) -> ok | not_exists | not_allowed | bad_request. -spec remove_user(binary(), binary()) -> ok | {error, db_failure | not_allowed}.
remove_user(LUser, LServer) -> remove_user(LUser, LServer) ->
remove_user_req(LUser, LServer, <<"">>, <<"remove_user">>). remove_user_req(LUser, LServer, <<"">>, <<"remove_user">>).
-spec remove_user(ejabberd:luser(), ejabberd:lserver(), binary()) -> ok | not_exists | not_allowed | bad_request. -spec remove_user(binary(), binary(), binary()) -> ok | {error, db_failure | not_allowed}.
remove_user(LUser, LServer, Password) -> remove_user(LUser, LServer, Password) ->
case scram2:enabled(LServer) of case scram2:enabled(LServer) of
false -> false ->
@ -157,21 +158,21 @@ remove_user(LUser, LServer, Password) ->
true -> true ->
case verify_scram_password(LUser, LServer, Password) of case verify_scram_password(LUser, LServer, Password) of
{ok, false} -> {ok, false} ->
not_allowed; {error, not_allowed};
{ok, true} -> {ok, true} ->
remove_user_req(LUser, LServer, <<"">>, <<"remove_user">>); remove_user_req(LUser, LServer, <<"">>, <<"remove_user">>);
{error, Error} -> {error, Error} ->
Error {error, db_failure}
end end
end. end.
-spec remove_user_req(binary(), binary(), binary(), binary()) -> -spec remove_user_req(binary(), binary(), binary(), binary()) ->
ok | not_exists | not_allowed | bad_request. ok | {error, not_allowed | db_failure}.
remove_user_req(LUser, LServer, Password, Method) -> remove_user_req(LUser, LServer, Password, Method) ->
case make_req(post, Method, LUser, LServer, Password) of case make_req(post, Method, LUser, LServer, Password) of
{error, not_allowed} -> not_allowed; {error, not_allowed} -> {error, not_allowed};
{error, not_found} -> not_exists; {error, not_found} -> {error, db_failure};
{error, _} -> bad_request; {error, _} -> {error, db_failure};
_ -> ok _ -> ok
end. end.
@ -184,7 +185,7 @@ remove_user_req(LUser, LServer, Password, Method) ->
make_req(_, _, LUser, LServer, _) when LUser == error orelse LServer == error -> make_req(_, _, LUser, LServer, _) when LUser == error orelse LServer == error ->
{error, {prep_failed, LUser, LServer}}; {error, {prep_failed, LUser, LServer}};
make_req(Method, Path, LUser, LServer, Password) -> make_req(Method, Path, LUser, LServer, Password) ->
AuthOpts = ejabberd_config:get_option({auth_opts, LServer}, fun(V) -> V end), AuthOpts = ejabberd_config:get_option({auth_opts, LServer}),
BasicAuth = case lists:keyfind(basic_auth, 1, AuthOpts) of BasicAuth = case lists:keyfind(basic_auth, 1, AuthOpts) of
{_, BasicAuth0} -> BasicAuth0; {_, BasicAuth0} -> BasicAuth0;
_ -> "" _ -> ""