Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy CLI commands #4160

Merged
merged 8 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions big_tests/tests/cluster_commands_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@

all() ->
[{group, clustered},
{group, mnesia},
{group, clustering_two},
{group, clustering_three}].

groups() ->
[{clustered, [], [one_to_one_message]},
{clustering_two, [], clustering_two_tests()},
{clustering_three, [], clustering_three_tests()},
{mnesia, [], [set_master_test]}].
{clustering_three, [], clustering_three_tests()}].

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 @@ -184,33 +183,16 @@ one_to_one_message(ConfigIn) ->
Stanza2 = escalus:wait_for_stanza(Alice, 5000),
escalus:assert(is_chat_message, [<<"Oh hi!">>], Stanza2)
end).
%%--------------------------------------------------------------------
%% mnesia tests
%%--------------------------------------------------------------------

set_master_test(ConfigIn) ->
%% To ensure that passwd table exists.
%% We also need at least two nodes for set_master to work.
catch distributed_helper:rpc(mim(), ejabberd_auth_internal, start, [host_type(mim1)]),
catch distributed_helper:rpc(mim2(), ejabberd_auth_internal, start, [host_type(mim2)]),

TableName = passwd,
NodeList = rpc_call(mnesia, system_info, [running_db_nodes]),
mongooseimctl("set_master", ["self"], ConfigIn),
[MasterNode] = rpc_call(mnesia, table_info, [TableName, master_nodes]),
true = lists:member(MasterNode, NodeList),
RestNodesList = lists:delete(MasterNode, NodeList),
OtherNode = hd(RestNodesList),
mongooseimctl("set_master", [atom_to_list(OtherNode)], ConfigIn),
[OtherNode] = rpc_call(mnesia, table_info, [TableName, master_nodes]),
mongooseimctl("set_master", ["self"], ConfigIn),
[MasterNode] = rpc_call(mnesia, table_info, [TableName, master_nodes]).


%%--------------------------------------------------------------------
%% Manage cluster commands tests
%%--------------------------------------------------------------------

commands_without_args(Config) ->
{Res1, 1} = mongooseimctl_interactive("join_cluster", [], "yes\n", Config),
?assertMatch({match, _}, re:run(Res1, "This command requires one argument: other node's name")),
{Res2, 1} = mongooseimctl_interactive("remove_from_cluster", [], "yes\n",Config),
?assertMatch({match, _}, re:run(Res2, "This command requires one argument: other node's name")).

join_successful_prompt(Config) ->
%% given
Expand Down
75 changes: 36 additions & 39 deletions big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("escalus/include/escalus.hrl").
-include_lib("exml/include/exml.hrl").
-include_lib("eunit/include/eunit.hrl").
-include("muc_light.hrl").

-export([suite/0, all/0, groups/0]).
Expand Down Expand Up @@ -52,15 +53,13 @@
remove_pubsub_push_node/1,
remove_pubsub_pep_node/1
]).
-export([
data_is_not_retrieved_for_missing_user/1
]).

-import(mongooseimctl_helper, [mongooseimctl/3]).
-import(distributed_helper, [mim/0, subhost_pattern/1, rpc/4]).
-import(muc_light_helper, [room_bin_jid/1]).
-import(domain_helper, [host_type/0]).
-import(config_parser_helper, [default_mod_config/1, mod_config/2]).
-import(graphql_helper, [execute_command/4, get_ok_value/2]).

-define(ROOM, <<"tt1">>).

Expand All @@ -74,7 +73,6 @@ suite() ->
all() ->
[
{group, retrieve_personal_data},
{group, retrieve_negative},
{group, remove_personal_data}
].

Expand Down Expand Up @@ -111,9 +109,6 @@ groups() ->
dont_retrieve_other_user_private_xml,
retrieve_multiple_private_xmls
]},
{retrieve_negative, [], [
data_is_not_retrieved_for_missing_user
]},
{retrieve_personal_data_mam, [], [
{group, retrieve_personal_data_mam_rdbms},
{group, retrieve_personal_data_mam_cassandra},
Expand Down Expand Up @@ -181,11 +176,13 @@ 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(),
escalus:init_per_suite(Config1).
Config2 = graphql_helper:init_admin_cli(Config1),
escalus:init_per_suite(Config2).

end_per_suite(Config) ->
delete_files(),
escalus_fresh:clean(),
graphql_helper:clean(),
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).

Expand Down Expand Up @@ -478,7 +475,7 @@ remove_vcard(Config) ->
= escalus:send_and_wait(Alice, escalus_stanza:vcard_update(AliceFields)),
escalus:assert(is_iq_result, AliceSetResultStanza),

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(Alice, [{vcard,["jid","vcard"],[]}])

Expand All @@ -500,7 +497,7 @@ remove_private(Config) ->
<<"<item xmlns='alice:private_remove:ns'>Something to declare</item>">>}]}]),

%% Remove Alice
{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

%% Expect Alice's data to be gone
assert_personal_data_via_rpc(Alice, [{private, ["ns","xml"], []}])
Expand All @@ -518,7 +515,7 @@ dont_remove_other_user_private_xml(Config) ->
send_and_assert_private_stanza(Bob, BobNS, BobContent),

%% Remove Alice
{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

%% Expect Alice's data to be gone
assert_personal_data_via_rpc(Alice, [{private, ["ns","xml"], []}]),
Expand Down Expand Up @@ -559,7 +556,7 @@ remove_multiple_private_xmls(Config) ->
Alice, Config, "private", ExpectedHeader, ExpectedItems),

%% Remove Alice
{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

%% Expect all of Alice's data to be gone
assert_personal_data_via_rpc(Alice, [{private, ["ns","xml"], []}])
Expand Down Expand Up @@ -587,7 +584,7 @@ remove_roster(Config) ->
#{ "jid" => [{contains, AliceU}, {contains, AliceS}] }
],

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(Alice, [{roster, expected_header(mod_roster), []}]),
retrieve_and_validate_personal_data(
Expand Down Expand Up @@ -795,7 +792,7 @@ remove_mam_pm(Config) ->
#{"message" => [{contains, Msg2}], "from" => [{jid, BobJID}]}
],

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(Alice, [{mam_pm, ExpectedHeader, []}]),

Expand Down Expand Up @@ -990,7 +987,7 @@ remove_offline(Config) ->
[host_type(), AliceU, AliceS, 10])
end, 3),

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(
Alice, [{offline, ["timestamp","from", "to", "packet"],[]}])
Expand Down Expand Up @@ -1082,7 +1079,7 @@ remove_pubsub_subscriptions(Config) ->
pubsub_tools:create_node(Alice, Node, []),
pubsub_tools:subscribe(Bob, Node, []),

{0, _} = unregister(Bob, Config),
unregister(Bob, Config),

assert_personal_data_via_rpc(Bob,
[{pubsub_payloads,["node_name","item_id","payload"],[]},
Expand All @@ -1106,7 +1103,7 @@ remove_pubsub_dont_remove_flat_pubsub_node(Config) ->
Node1 = {_,NodeName} = pubsub_tools:pubsub_node_with_num(1),
pubsub_tools:create_nodes([{Alice, Node1, []}]),

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(Alice,
[{pubsub_payloads,["node_name","item_id","payload"],[]},
Expand All @@ -1133,7 +1130,7 @@ remove_pubsub_push_node(Config) ->
escalus:send(Bob, PublishIQ),
escalus:assert(is_iq_result, escalus:wait_for_stanza(Bob)),

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(Alice, [{pubsub_payloads,["node_name","item_id","payload"],[]},
{pubsub_nodes,["node_name","type"],[]},
Expand All @@ -1149,7 +1146,7 @@ remove_pubsub_pep_node(Config) ->
{Alice, PepNode, []}
]),

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(Alice, [{pubsub_payloads,["node_name","item_id","payload"],[]},
{pubsub_nodes,["node_name","type"],[]},
Expand All @@ -1164,7 +1161,7 @@ remove_pubsub_dont_remove_node_when_only_publisher(Config) ->
AffChange = [{Bob, <<"publish-only">>}],
pubsub_tools:set_affiliations(Alice, Node1, AffChange, []),

{0, _} = unregister(Bob, Config),
unregister(Bob, Config),

assert_personal_data_via_rpc(Alice,
[{pubsub_payloads,["node_name","item_id","payload"],[]},
Expand Down Expand Up @@ -1209,7 +1206,7 @@ remove_pubsub_all_data(Config) ->
pubsub_tools:publish(Bob, BobToNode3, Node3, [{with_payload, {true, BinItem4}}]),
pubsub_tools:receive_item_notification(Alice, BobToNode3, Node3, []),

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

[{pubsub_payloads,["node_name","item_id","payload"], AlicePayloads},
{pubsub_nodes,["node_name","type"], AliceNodes},
Expand Down Expand Up @@ -1431,7 +1428,7 @@ remove_inbox(Config) ->

ExpectedHeader = ["jid", "content", "unread_count", "timestamp"],

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

assert_personal_data_via_rpc(Alice, [{inbox, ExpectedHeader, []}]),

Expand All @@ -1457,7 +1454,7 @@ remove_inbox_muclight(Config) ->

ExpectedHeader = ["jid", "content", "unread_count", "timestamp"],

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

%% MUC Light affiliations are also stored in inbox
%% 1. Added to the room
Expand Down Expand Up @@ -1499,7 +1496,7 @@ remove_inbox_muc(Config) ->

ExpectedHeader = ["jid", "content", "unread_count", "timestamp"],

{0, _} = unregister(Alice, Config),
unregister(Alice, Config),

escalus:wait_for_stanza(Bob),
assert_personal_data_via_rpc(Alice, [{inbox, ExpectedHeader, []}]),
Expand Down Expand Up @@ -1543,18 +1540,13 @@ retrieve_logs(Config) ->
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")
end).

%% ------------------------- Data retrieval - Negative case -------------------------

data_is_not_retrieved_for_missing_user(Config) ->
{Filename, 1, _} = retrieve_personal_data("non-person", "oblivion", Config),
{error, _} = file:read_file_info(Filename).

%% -------------------------------------------------------------
%% Internal functions
%% -------------------------------------------------------------
Expand Down Expand Up @@ -1695,7 +1687,9 @@ retrieve_all_personal_data(Client, Config) ->
request_and_unzip_personal_data(User, Domain, Config).

request_and_unzip_personal_data(User, Domain, Config) ->
{Filename, 0, _} = retrieve_personal_data(User, Domain, Config),
{Filename, Res} = retrieve_personal_data(User, Domain, Config),
ParsedResult = get_ok_value([data, gdpr, retrievePersonalData], Res),
?assertEqual(<<"Data retrieved">>, ParsedResult),
FullPath = get_mim_cwd() ++ "/" ++ Filename,
Dir = make_dir_name(Filename, User),
ct:log("extracting logs ~s", [Dir]),
Expand All @@ -1709,15 +1703,18 @@ make_dir_name(Filename, User) when is_list(User) ->

retrieve_personal_data(User, Domain, Config) ->
Filename = random_filename(Config),
{CommandOutput, Code} = mongooseimctl("retrieve_personal_data",
[User, Domain, Filename], Config),
{Filename, Code, CommandOutput}.
Vars = #{<<"username">> => User, <<"domain">> => Domain,
<<"resultFilepath">> => list_to_binary(Filename)},
Result = execute_command(<<"gdpr">>, <<"retrievePersonalData">>, Vars, Config),
{Filename, Result}.

unregister(Client, Config) ->
User = escalus_client:username(Client),
Domain = escalus_client:server(Client),
{CommandOutput, Code} = mongooseimctl("unregister", [User, Domain], Config),
{Code, CommandOutput}.
User = escalus_client:full_jid(Client),
Path = [data, account, removeUser, message],
Vars = #{<<"user">> => User},
Resp = execute_command(<<"account">>, <<"removeUser">>, Vars, Config),
?assertNotEqual(nomatch, binary:match(get_ok_value(Path, Resp),
<<"successfully unregister">>)).

random_filename(Config) ->
TCName = atom_to_list(?config(tc_name, Config)),
Expand Down
29 changes: 21 additions & 8 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 @@ -490,8 +498,9 @@ admin_import_users_http(Config) ->
<<"notAllowed">> => null},
get_ok_value([data, account, importUsers], Resp2)),
Domain = domain_helper:domain(),
JID = mongoose_helper:make_jid(<<"john">>, Domain),
mongoose_helper:wait_until(fun() ->
rpc(mim(), mongoose_account_api, check_account, [<<"john">>, Domain])
rpc(mim(), mongoose_account_api, check_account, [JID])
end,
{ok, io_lib:format("User ~s exists", [<<"john@", Domain/binary>>])},
#{time_left => timer:seconds(20),
Expand Down Expand Up @@ -608,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
Loading