Skip to content

Commit

Permalink
Remove unused code & improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekwegr committed Nov 20, 2023
1 parent 21547ff commit 4d75d36
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 86 deletions.
8 changes: 7 additions & 1 deletion big_tests/tests/cluster_commands_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ suite() ->
require_rpc_nodes([mim, mim2, mim3]) ++ escalus:suite().

clustering_two_tests() ->
[join_successful_prompt,
[commands_without_args,
join_successful_prompt,
join_successful_force,
leave_successful_prompt,
leave_successful_force,
Expand Down Expand Up @@ -187,6 +188,11 @@ one_to_one_message(ConfigIn) ->
%% Manage cluster commands tests
%%--------------------------------------------------------------------

commands_without_args(Config) ->
{Res1, 1} = mongooseimctl_interactive("join_cluster", [], "yes\n", Config),
?assertMatch({match, _}, re:run(Res1, "You have to provide other node's name")),
{Res2, 1} = mongooseimctl_interactive("remove_from_cluster", [], "yes\n",Config),
?assertMatch({match, _}, re:run(Res2, "You have to provide other node's name")).

join_successful_prompt(Config) ->
%% given
Expand Down
26 changes: 19 additions & 7 deletions big_tests/tests/graphql_account_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ admin_account_tests() ->
admin_check_password_non_existing_user,
admin_check_password_hash,
admin_check_password_hash_non_existing_user,
admin_check_plain_password_hash,
admin_check_plain_password_hash_md5,
admin_check_plain_password_hash_sha,
admin_check_user,
admin_check_non_existing_user,
admin_register_user,
Expand Down Expand Up @@ -135,7 +136,8 @@ domain_admin_clean_users(Config) ->
init_per_testcase(admin_register_user = C, Config) ->
Config1 = [{user, {<<"gql_admin_registration_test">>, domain_helper:domain()}} | Config],
escalus:init_per_testcase(C, Config1);
init_per_testcase(admin_check_plain_password_hash = C, Config) ->
init_per_testcase(C, Config) when C =:= admin_check_plain_password_hash_md5;
C =:= admin_check_plain_password_hash_sha ->
{_, AuthMods} = lists:keyfind(ctl_auth_mods, 1, Config),
case lists:member(ejabberd_auth_ldap, AuthMods) of
true ->
Expand Down Expand Up @@ -176,7 +178,8 @@ end_per_testcase(admin_register_user = C, Config) ->
{Username, Domain} = proplists:get_value(user, Config),
rpc(mim(), mongoose_account_api, unregister_user, [Username, Domain]),
escalus:end_per_testcase(C, Config);
end_per_testcase(admin_check_plain_password_hash, Config) ->
end_per_testcase(C, Config) when C =:= admin_check_plain_password_hash_md5;
C =:= admin_check_plain_password_hash_sha ->
mongoose_helper:restore_config(Config),
escalus:delete_users(Config, escalus:get_users([carol]));
end_per_testcase(admin_register_user_limit_error = C, Config) ->
Expand Down Expand Up @@ -297,12 +300,17 @@ admin_check_password_hash_non_existing_user(Config) ->
Resp3 = check_password_hash(?EMPTY_NAME_JID, EmptyHash, Method, Config),
get_coercion_err_msg(Resp3).

admin_check_plain_password_hash(Config) ->
admin_check_plain_password_hash_md5(Config) ->
admin_check_password_hash(Config, <<"md5">>, fun get_md5/1).

admin_check_plain_password_hash_sha(Config) ->
admin_check_password_hash(Config, <<"sha">>, fun get_sha/1).

admin_check_password_hash(Config, Method, HashFun) ->
UserJID = escalus_users:get_jid(Config, carol),
Password = lists:last(escalus_users:get_usp(Config, carol)),
Method = <<"md5">>,
Hash = list_to_binary(get_md5(Password)),
WrongHash = list_to_binary(get_md5(<<"wrong password">>)),
Hash = list_to_binary(HashFun(Password)),
WrongHash = list_to_binary(HashFun(<<"wrong password">>)),
Path = [data, account, checkPasswordHash],
% A correct hash
Resp = check_password_hash(UserJID, Hash, Method, Config),
Expand Down Expand Up @@ -609,6 +617,10 @@ get_md5(AccountPass) ->
lists:flatten([io_lib:format("~.16B", [X])
|| X <- binary_to_list(crypto:hash(md5, AccountPass))]).

get_sha(AccountPass) ->
lists:flatten([io_lib:format("~.16B", [X])
|| X <- binary_to_list(crypto:hash(sha, AccountPass))]).

%% Commands

user_unregister(User, Config) ->
Expand Down
2 changes: 1 addition & 1 deletion src/ejabberd_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -478,5 +478,5 @@ handle_cluster_operation(Operation, Args) ->
end.

cluster_command_without_arg() ->
?PRINT("You have to provide another node's name\n", []),
?PRINT("You have to provide other node's name\n", []),
?STATUS_ERROR.
35 changes: 1 addition & 34 deletions src/http_upload/mod_http_upload_api.erl
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
-module(mod_http_upload_api).

-export([get_urls/5, get_urls_mongooseimctl/5]).

-ignore_xref([get_urls_mongooseimctl/5]).

-spec get_urls_mongooseimctl(Domain :: jid:lserver(), Filename :: binary(), Size :: pos_integer(),
ContentType :: binary() | undefined, Timeout :: pos_integer()) ->
{ok | error, string()}.
get_urls_mongooseimctl(_Domain, _Filename, Size, _ContentType, _Timeout) when Size =< 0 ->
{error, "size must be positive integer"};
get_urls_mongooseimctl(_Domain, _Filename, _Size, _ContentType, Timeout) when Timeout =< 0 ->
{error, "timeout must be positive integer"};
get_urls_mongooseimctl(Domain, Filename, Size, ContentType, Timeout) ->
case get_urls(Domain, Filename, Size, ContentType, Timeout) of
{ok, #{<<"putUrl">> := PutURL, <<"getUrl">> := GetURL, <<"headers">> := Headers}} ->
{ok, generate_output_message(PutURL, GetURL, Headers)};
{_, Message} ->
{error, Message}
end.
-export([get_urls/5]).

-spec get_urls(Domain :: jid:lserver(), Filename :: nonempty_binary(), Size :: pos_integer(),
ContentType :: binary() | null | undefined, Timeout :: pos_integer()) ->
Expand Down Expand Up @@ -53,19 +36,3 @@ check_module_and_get_urls(HostType, Filename, Size, ContentType, Timeout) ->
false ->
{module_not_loaded_error, "mod_http_upload is not loaded for this host"}
end.

-spec generate_output_message(PutURL :: binary(),
GetURL :: binary(),
Headers :: [{ok, map()}]) -> string().
generate_output_message(PutURL, GetURL, Headers) ->
PutURLOutput = url_output("PutURL:", PutURL),
GetURLOutput = url_output("GetURL:", GetURL),
HeadersOutput = headers_output(Headers),
lists:flatten([PutURLOutput, GetURLOutput, HeadersOutput]).

url_output(Name, Url) ->
io_lib:format("~s ~s~n", [Name, Url]).

headers_output(Headers) ->
List = [{Name, Value} || {ok, #{<<"name">> := Name, <<"value">> := Value}} <- Headers],
io_lib:format("Header: ~p~n", [List]).
16 changes: 1 addition & 15 deletions src/mod_auth_token.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
-export([deserialize/1,
serialize/1]).

%% Command-line interface
-export([revoke_token_command/1]).

%% Test only!
-export([datetime_to_seconds/1,
seconds_to_datetime/1]).
Expand All @@ -51,7 +48,7 @@
-ignore_xref([
behaviour_info/1, datetime_to_seconds/1, deserialize/1,
expiry_datetime/3, get_key_for_host_type/2, process_iq/5,
revoke/2, revoke_token_command/1, seconds_to_datetime/1,
revoke/2, seconds_to_datetime/1,
serialize/1, token/3, token_with_mac/2
]).

Expand Down Expand Up @@ -405,17 +402,6 @@ key_name(access) -> token_secret;
key_name(refresh) -> token_secret;
key_name(provision) -> provision_pre_shared.

-spec revoke_token_command(Owner) -> ResTuple when
Owner :: binary(),
ResCode :: ok | not_found | error,
ResTuple :: {ResCode, string()}.
revoke_token_command(Owner) ->
JID = jid:from_binary(Owner),
case mod_auth_token_api:revoke_token_command(JID) of
{ok, _} = Result -> Result;
Error -> Error
end.

-spec clean_tokens(Acc, Params, Extra) -> {ok, Acc} when
Acc :: mongoose_acc:t(),
Params :: #{jid := jid:jid()},
Expand Down
11 changes: 0 additions & 11 deletions src/mongoose_server_api.erl
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
-module(mongoose_server_api).

-export([get_loglevel_mongooseimctl/0]).

-export([status/0, get_cookie/0, join_cluster/1, leave_cluster/0,
remove_from_cluster/1, stop/0, restart/0, remove_node/1, set_loglevel/1,
get_loglevel/0]).

-ignore_xref([get_loglevel_mongooseimctl/0]).

-spec get_loglevel_mongooseimctl() -> {ok, iolist()}.
get_loglevel_mongooseimctl() ->
Level = mongoose_logs:get_global_loglevel(),
Number = mongoose_logs:loglevel_keyword_to_number(Level),
String = io_lib:format("global loglevel is ~p, which means '~p'", [Number, Level]),
{ok, String}.

-spec get_loglevel() -> {ok, mongoose_logs:atom_log_level()}.
get_loglevel() ->
{ok, mongoose_logs:get_global_loglevel()}.
Expand Down
17 changes: 0 additions & 17 deletions src/stats_api.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
-module(stats_api).

-export([incoming_s2s_number/0, outgoing_s2s_number/0, stats/1, stats/2]).
-export([stats_mongooseimctl/1, stats_mongooseimctl/2]).

-ignore_xref([stats_mongooseimctl/1, stats_mongooseimctl/2]).

-include("mongoose.hrl").

Expand Down Expand Up @@ -36,17 +33,3 @@ stats(<<"onlineusers">>, Host) ->
{ok, ejabberd_sm:get_vh_session_number(Host)};
stats(_Name, _Host) ->
{not_found, "Stats not found"}.

-spec stats_mongooseimctl(binary()) -> {ok | not_found, string()}.
stats_mongooseimctl(Name) ->
case stats(Name) of
{ok, Stat} -> {ok, integer_to_list(Stat)};
Error -> Error
end.

-spec stats_mongooseimctl(binary(), binary()) -> {ok | not_found, string()}.
stats_mongooseimctl(Name, Host) ->
case stats(Name, Host) of
{ok, Stat} -> {ok, integer_to_list(Stat)};
Error -> Error
end.

0 comments on commit 4d75d36

Please sign in to comment.