Skip to content

Commit

Permalink
Remove leftovers of the legacy CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekwegr committed Nov 16, 2023
1 parent a416630 commit a6dd81c
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 113 deletions.
11 changes: 7 additions & 4 deletions big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ all() ->
].

groups() ->
%% **DON'T** make any of these groups parallel, because calling mongooseimctl
%% in parallel is broken!
[
{retrieve_personal_data, [], [
retrieve_vcard,
Expand Down Expand Up @@ -174,7 +176,7 @@ init_per_suite(Config) ->
#{node := MimNode} = distributed_helper:mim(),
Config1 = [{{ejabberd_cwd, MimNode}, get_mim_cwd()} | dynamic_modules:save_modules(host_type(), Config)],
muc_helper:load_muc(),
Config2 = graphql_helper:init_admin_handler(Config1),
Config2 = graphql_helper:init_admin_cli(Config1),
escalus:init_per_suite(Config2).

end_per_suite(Config) ->
Expand Down Expand Up @@ -1521,14 +1523,15 @@ retrieve_inbox_for_multiple_messages(Config) ->
retrieve_logs(Config) ->
escalus:fresh_story(Config, [{alice, 1}],
fun(Alice) ->
User = escalus_client:username(Alice),
Domain = escalus_client:server(Alice),
User = string:to_lower(binary_to_list(escalus_client:username(Alice))),
Domain = string:to_lower(binary_to_list(escalus_client:server(Alice))),
JID = string:to_upper(binary_to_list(escalus_client:short_jid(Alice))),
#{node := MIM2NodeName} = MIM2Node = distributed_helper:mim2(),
mongoose_helper:successful_rpc(net_kernel, connect_node, [MIM2NodeName]),
mongoose_helper:successful_rpc(MIM2Node, error_logger, error_msg,
["event=disturbance_in_the_force, jid=~s", [JID]]),
Dir = request_and_unzip_personal_data(User, Domain, Config),
Dir = request_and_unzip_personal_data(list_to_binary(User), list_to_binary(Domain),
Config),
Filename = filename:join(Dir, "logs-" ++ atom_to_list(MIM2NodeName) ++ ".txt"),
{ok, Content} = file:read_file(Filename),
{match, _} = re:run(Content, "disturbance_in_the_force")
Expand Down
1 change: 1 addition & 0 deletions big_tests/tests/metrics_roster_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ init_per_suite(Config) ->
[{mongoose_metrics, MongooseMetrics} | escalus:init_per_suite(Config)].

end_per_suite(Config) ->
escalus_fresh:clean(),
escalus:end_per_suite(Config).

init_per_group(_GroupName, Config) ->
Expand Down
230 changes: 230 additions & 0 deletions big_tests/tests/mongooseimctl_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
%%==============================================================================
%% Copyright 2013 Erlang Solutions Ltd.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================
-module(mongooseimctl_SUITE).
-compile([export_all, nowarn_export_all, nowarn_shadow_vars]).
-include_lib("escalus/include/escalus.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("exml/include/exml.hrl").
-include_lib("eunit/include/eunit.hrl").

-import(mongooseimctl_helper, [mongooseimctl/3]).
-import(distributed_helper, [mim/0, require_rpc_nodes/1]).
-import(domain_helper, [domain/0]).

%%--------------------------------------------------------------------
%% Suite configuration
%%--------------------------------------------------------------------

all() ->
[
{group, graphql},
{group, help},
{group, server}
].

groups() ->
[{graphql, [], graphql()},
{help, [], help()},
{server, [], server()}].

graphql() ->
[graphql_wrong_arguments_number,
can_execute_admin_queries_with_permissions,
can_handle_execution_error,
graphql_error_unknown_command_with_args,
graphql_error_unknown_command_without_args,
graphql_error_unknown_category_with_args,
graphql_error_unknown_category_without_args,
graphql_no_command,
graphql_error_invalid_args,
graphql_error_invalid_arg_value,
graphql_error_no_arg_value,
graphql_error_missing_args,
graphql_error_unknown_arg,
graphql_arg_help,
graphql_command].

help() ->
[default_help,
help_with_dual_mode,
help_with_long_mode].

server() ->
[server_status,
server_is_started].

suite() ->
require_rpc_nodes([mim]) ++ escalus:suite().

init_per_suite(Config) ->
Node = mim(),
Config1 = ejabberd_node_utils:init(Node, Config),
Config1.

end_per_suite(_Config) ->
ok.

init_per_testcase(CaseName, Config) ->
escalus:init_per_testcase(CaseName, Config).

end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).

%%--------------------------------------------------------------------
%% mongoose_graphql tests
%%--------------------------------------------------------------------

can_execute_admin_queries_with_permissions(Config) ->
Query = "query { checkAuth { authStatus } }",
Res = mongooseimctl("graphql", [Query], Config),
?assertMatch({_, 0}, Res),
Data = element(1, Res),
?assertNotEqual(nomatch, string:find(Data, "AUTHORIZED")).

can_handle_execution_error(Config) ->
Query = "{}",
Res = mongooseimctl("graphql", [Query], Config),
?assertMatch({_, 1}, Res),
Data = element(1, Res),
?assertNotEqual(nomatch, string:find(Data, "parser_error")).

graphql_wrong_arguments_number(Config) ->
ExpectedFragment = "This command requires",
ResNoArgs = mongooseimctl("graphql", [], Config),
?assertMatch({_, 1}, ResNoArgs),
Data1 = element(1, ResNoArgs),
?assertNotEqual(nomatch, string:find(Data1, ExpectedFragment)),

ResTooManyArgs = mongooseimctl("graphql", ["{}", "{}"], Config),
?assertMatch({_, 1}, ResTooManyArgs),
Data2 = element(1, ResTooManyArgs),
?assertNotEqual(nomatch, string:find(Data2, ExpectedFragment)).

%% Generic GraphQL command tests
%% Specific commands are tested in graphql_*_SUITE

graphql_error_unknown_command_with_args(Config) ->
{Res, 1} = mongooseimctl("account", ["makeCoffee", "--strength", "medium"], Config),
?assertMatch({match, _}, re:run(Res, "Unknown command")),
expect_existing_commands(Res).

graphql_error_unknown_command_without_args(Config) ->
{Res, 1} = mongooseimctl("account", ["makeCoffee"], Config),
?assertMatch({match, _}, re:run(Res, "Unknown command")),
expect_existing_commands(Res).

graphql_error_unknown_category_with_args(Config) ->
{Res, 1} = mongooseimctl("cafe", ["makeCoffee"], Config),
?assertMatch({match, _}, re:run(Res, "Unknown category")),
expect_category_list(Res).

graphql_error_unknown_category_without_args(Config) ->
{Res, 1} = mongooseimctl("cafe", [], Config),
?assertMatch({match, _}, re:run(Res, "Unknown category")),
expect_category_list(Res).

graphql_no_command(Config) ->
%% Not an error - lists commands in the given category
{Res, 0} = mongooseimctl("account", [], Config),
expect_existing_commands(Res).

graphql_error_invalid_args(Config) ->
{Res, 1} = mongooseimctl("account", ["countUsers", "now"], Config),
?assertMatch({match, _}, re:run(Res, "Could not parse")),
expect_command_arguments(Res).

graphql_error_invalid_arg_value(Config) ->
{Res, 1} = mongooseimctl("vcard", ["setVcard", "--user", "user@host", "--vcard", "x"], Config),
%% vCard should be provided in JSON
?assertMatch({match, _}, re:run(Res, "Invalid value 'x' of argument 'vcard'")),
?assertMatch({match, _}, re:run(Res, "vcard\s+VcardInput!")).

graphql_error_no_arg_value(Config) ->
{Res, 1} = mongooseimctl("account", ["countUsers", "--domain"], Config),
?assertMatch({match, _}, re:run(Res, "Could not parse")),
expect_command_arguments(Res).

graphql_error_missing_args(Config) ->
{Res, 1} = mongooseimctl("account", ["countUsers"], Config),
?assertMatch({match, _}, re:run(Res, "Missing mandatory arguments")),
expect_command_arguments(Res).

graphql_error_unknown_arg(Config) ->
{Res, 1} = mongooseimctl("account", ["countUsers", "--domain", "localhost",
"--x", "y"], Config),
?assertMatch({match, _}, re:run(Res, "Unknown argument")),
expect_command_arguments(Res).

graphql_arg_help(Config) ->
{Res, 0} = mongooseimctl("account", ["countUsers", "--help"], Config),
expect_command_arguments(Res).

graphql_command(Config) ->
{ResJSON, 0} = mongooseimctl("account", ["countUsers", "--domain", "localhost"], Config),
#{<<"data">> := Data} = rest_helper:decode(ResJSON, #{return_maps => true}),
?assertMatch(#{<<"account">> := #{<<"countUsers">> := _}}, Data).

expect_existing_commands(Res) ->
?assertMatch({match, _}, re:run(Res, "countUsers")).

expect_command_arguments(Res) ->
?assertMatch({match, _}, re:run(Res, "domain\s+DomainName!")).

%%-----------------------------------------------------------------
%% Help tests
%%-----------------------------------------------------------------

default_help(Config) ->
#{node := Node} = mim(),
CtlCmd = distributed_helper:ctl_path(Node, Config),
{Res, 2} = mongooseimctl_helper:run(CtlCmd, []),
expect_category_list(Res).

help_with_dual_mode(Config) ->
{Res1, 2} = mongooseimctl("help", ["--dual"], Config),
expect_category_list(Res1),
{Res2, 2} = mongooseimctl("help", ["--nonexistent"], Config),
expect_category_list(Res2),
{Res3, 2} = mongooseimctl("help", [], Config),
expect_category_list(Res3).

help_with_long_mode(Config) ->
{Res, 2} = mongooseimctl("help", ["--long"], Config),
io:format("Res: ~p", [Res]),
?assertMatch({match, _}, re:run(Res, "Usage")),
?assertMatch({match, _}, re:run(Res, "account \n\s+Account management")).

%%-----------------------------------------------------------------
%% Server management tests
%%-----------------------------------------------------------------

server_status(Config) ->
{Res, 0} = mongooseimctl("status", [], Config),
?assertMatch({match, _}, re:run(Res, "Erlang VM status: started")).

server_is_started(Config) ->
%% Wait for the server to start, but it is already running
{Res, 0} = mongooseimctl("started", [], Config),
%% Expect only whitespace
?assertMatch(nomatch, re:run(Res, "\S")).

%%-----------------------------------------------------------------
%% Helpers
%%-----------------------------------------------------------------

expect_category_list(Res) ->
?assertMatch({match, _}, re:run(Res, "Usage")),
?assertMatch({match, _}, re:run(Res, "account\s+Account management")).
15 changes: 0 additions & 15 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ general() ->
<<"route_subdomains">> => #option{type = atom,
validate = {enum, [s2s]},
wrap = host_config},
<<"mongooseimctl_access_commands">> => #section{
items = #{default => ctl_access_rule()},
wrap = global_config},
<<"routing_modules">> => #list{items = #option{type = atom,
validate = module},
process = fun xmpp_router:expand_routing_modules/1,
Expand Down Expand Up @@ -220,22 +217,10 @@ general_defaults() ->
<<"component_backend">> => mnesia,
<<"s2s_backend">> => mnesia,
<<"rdbms_server_type">> => generic,
<<"mongooseimctl_access_commands">> => #{},
<<"routing_modules">> => mongoose_router:default_routing_modules(),
<<"replaced_wait_timeout">> => 2000,
<<"hide_service_name">> => false}.

ctl_access_rule() ->
#section{
items = #{<<"commands">> => #list{items = #option{type = atom,
validate = non_empty}},
<<"argument_restrictions">> =>
#section{items = #{default => #option{type = string}}}
},
defaults = #{<<"commands">> => all,
<<"argument_restrictions">> => #{}}
}.

%% path: general.domain_certfile
domain_cert() ->
#section{
Expand Down
9 changes: 1 addition & 8 deletions src/ejabberd_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
-module(ejabberd_admin).
-author('mickael.remond@process-one.net').

-export([start/0, stop/0,
%% Server
-export([%% Server
status/0,
%% Accounts
register/3, register/2, unregister/2,
Expand All @@ -48,12 +47,6 @@

-include("mongoose.hrl").

start() ->
ok.

stop() ->
ok.

%%%
%%% Commands
%%%
Expand Down
1 change: 0 additions & 1 deletion src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ do_start() ->
mongoose_modules:start(),
service_mongoose_system_metrics:verify_if_configured(),
mongoose_listener:start(),
ejabberd_admin:start(),
mongoose_metrics:init_mongooseim_metrics(),
gen_hook:reload_hooks(),
update_status_file(started),
Expand Down
8 changes: 2 additions & 6 deletions src/ejabberd_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
%%% TODO: Update the guide
%%% TODO: Mention this in the release notes
%%% Note: the commands with several words use now the underline: _
%%% It is still possible to call the commands with dash: -
%%% but this is deprecated, and may be removed in a future version.


-module(ejabberd_ctl).
Expand Down Expand Up @@ -154,15 +152,15 @@ process(["help" | Mode]) ->
?STATUS_USAGE;
[_] ->
print_usage(dual, MaxC, ShCode),
?STATUS_SUCCESS
?STATUS_USAGE

Check warning on line 155 in src/ejabberd_ctl.erl

View check run for this annotation

Codecov / codecov/patch

src/ejabberd_ctl.erl#L154-L155

Added lines #L154 - L155 were not covered by tests
end;
process(Args) ->
case mongoose_graphql_commands:process(Args) of
#{status := executed, result := Result} ->
handle_graphql_result(Result);
#{status := error, reason := no_args} = Ctx ->
print_usage(Ctx),
?STATUS_ERROR;
?STATUS_USAGE;

Check warning on line 163 in src/ejabberd_ctl.erl

View check run for this annotation

Codecov / codecov/patch

src/ejabberd_ctl.erl#L162-L163

Added lines #L162 - L163 were not covered by tests
#{status := error} = Ctx ->
?PRINT(error_message(Ctx) ++ "\n\n", []),
print_usage(Ctx),
Expand All @@ -184,8 +182,6 @@ error_message(#{reason := {unknown_arg, ArgName}, command := Command}) ->
error_message(#{reason := {invalid_arg_value, ArgName, ArgValue}, command := Command}) ->
io_lib:format("Invalid value '~s' of argument '~s' for command '~s'",
[ArgValue, ArgName, Command]);
error_message(#{reason := no_args, command := Command}) ->
io_lib:format("No arguments provided for command '~s'", [Command]);
error_message(#{reason := {missing_args, MissingArgs}, command := Command}) ->
io_lib:format("Missing mandatory arguments for command '~s': ~s",
[Command, ["'", lists:join("', '", MissingArgs), "'"]]).
Expand Down
5 changes: 4 additions & 1 deletion src/mod_roster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
-ignore_xref([get_user_rosters_length/2,
item_to_xml/1,
process_subscription_t/6,
transaction/2]).
transaction/2,
broadcast_item/3,
set_items/3
]).

-include("mongoose.hrl").
-include("jlib.hrl").
Expand Down
5 changes: 5 additions & 0 deletions src/mongoose_account_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
check_password_hash/4,
import_users/1]).

-ignore_xref([ban_account/3,
check_account/2,
check_password/3,
check_password_hash/4]).

-type register_result() :: {ok | exists | invalid_jid | cannot_register |
limit_per_domain_exceeded, iolist()}.

Expand Down
Loading

0 comments on commit a6dd81c

Please sign in to comment.