From ae20a9f35c08ad4490eec29e9d2c24bd87b93f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:41:36 +0200 Subject: [PATCH 1/8] Fix the check if mod_private is running Was for domain, should be for host type. --- src/admin_extra/service_admin_extra_private.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/admin_extra/service_admin_extra_private.erl b/src/admin_extra/service_admin_extra_private.erl index 2cb307d593..57f7d2a0c2 100644 --- a/src/admin_extra/service_admin_extra_private.erl +++ b/src/admin_extra/service_admin_extra_private.erl @@ -122,11 +122,11 @@ private_set2(Username, Host, Xml) -> {user_does_not_exist, io_lib:format("User ~s does not exist", [jid:to_binary(JID)])} end. -do_private_set2(#jid{lserver = Host} = JID, Xml) -> - case is_private_module_loaded(Host) of +do_private_set2(#jid{lserver = Domain} = JID, Xml) -> + {ok, HostType} = mongoose_domain_api:get_domain_host_type(Domain), + case is_private_module_loaded(HostType) of true -> From = To = JID, - {ok, HostType} = mongoose_domain_api:get_domain_host_type(From#jid.lserver), IQ = {iq, <<"">>, set, ?NS_PRIVATE, <<"">>, #xmlel{ name = <<"query">>, attrs = [{<<"xmlns">>, ?NS_PRIVATE}], @@ -134,13 +134,13 @@ do_private_set2(#jid{lserver = Host} = JID, Xml) -> Acc = mongoose_acc:new(#{ location => ?LOCATION, from_jid => From, to_jid => To, - lserver => From#jid.lserver, + lserver => Domain, host_type => HostType, element => jlib:iq_to_xml(IQ) }), mod_private:process_iq(Acc, From, To, IQ, #{}), {ok, ""}; false -> - {not_loaded, io_lib:format("Module mod_private is not loaded on host ~s", [Host])} + {not_loaded, io_lib:format("Module mod_private is not loaded on domain ~s", [Domain])} end. -spec is_private_module_loaded(jid:server()) -> true | false. From 88f7dfbc8b342a20c5f9dea9ff19b0095f64b8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:43:00 +0200 Subject: [PATCH 2/8] Sum up user counts from all domains The previous code was working only for static ones. Note: this code can be very heavy on some installations, we might want to emphasise this in the docs. --- src/admin_extra/service_admin_extra_stats.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/admin_extra/service_admin_extra_stats.erl b/src/admin_extra/service_admin_extra_stats.erl index 9af0ca1392..fe23e6199f 100644 --- a/src/admin_extra/service_admin_extra_stats.erl +++ b/src/admin_extra/service_admin_extra_stats.erl @@ -69,9 +69,9 @@ stats(Name) -> <<"uptimeseconds">> -> trunc(element(1, erlang:statistics(wall_clock))/1000); <<"registeredusers">> -> - lists:sum([ - ejabberd_auth:get_vh_registered_users_number(Server) - || Server <- ejabberd_config:get_global_option(hosts) ]); + Domains = lists:flatmap(fun mongoose_domain_api:get_domains_by_host_type/1, + ?ALL_HOST_TYPES), + lists:sum([ejabberd_auth:get_vh_registered_users_number(Domain) || Domain <- Domains]); <<"onlineusersnode">> -> ejabberd_sm:get_node_sessions_number(); <<"onlineusers">> -> From d616c68e6575f4aa760d0677c0b03442a5c276b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:44:40 +0200 Subject: [PATCH 3/8] Call get_urls with the host type, not domain --- src/admin_extra/service_admin_extra_upload.erl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/admin_extra/service_admin_extra_upload.erl b/src/admin_extra/service_admin_extra_upload.erl index e6bddfc6f0..3cc3994615 100644 --- a/src/admin_extra/service_admin_extra_upload.erl +++ b/src/admin_extra/service_admin_extra_upload.erl @@ -26,16 +26,17 @@ commands() -> [ } ]. --spec get_urls(HostType :: mongooseim:host_type(), Filename :: binary(), Size :: pos_integer(), +-spec get_urls(Domain :: jid:lserver(), Filename :: binary(), Size :: pos_integer(), ContentType :: binary() | undefined, Timeout :: pos_integer()) -> {ok, string()} | {error, string()}. -get_urls(_HostType, _Filename, Size, _ContentType, _Timeout) when Size =< 0-> +get_urls(_Domain, _Filename, Size, _ContentType, _Timeout) when Size =< 0-> {error, "size must be positive integer"}; -get_urls(_HostType, _Filename, _Size, _ContentType, Timeout) when Timeout =< 0-> +get_urls(_Domain, _Filename, _Size, _ContentType, Timeout) when Timeout =< 0-> {error, "timeout must be positive integer"}; -get_urls(HostType, Filename, Size, <<"">>, Timeout) -> - get_urls(HostType, Filename, Size, undefined, Timeout); -get_urls(HostType, Filename, Size, ContentType, Timeout) -> +get_urls(Domain, Filename, Size, <<"">>, Timeout) -> + get_urls(Domain, Filename, Size, undefined, Timeout); +get_urls(Domain, Filename, Size, ContentType, Timeout) -> + {ok, HostType} = mongoose_domain_api:get_domain_host_type(Domain), case gen_mod:is_loaded(HostType, mod_http_upload) of true -> {PutURL, GetURL, Header} = From 1491dc37dfef243ffa3ce4689cf49783971b6035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:45:17 +0200 Subject: [PATCH 4/8] Do not repeat tests in ejabberdctl_SUITE --- big_tests/tests/ejabberdctl_SUITE.erl | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/big_tests/tests/ejabberdctl_SUITE.erl b/big_tests/tests/ejabberdctl_SUITE.erl index 496ec72366..fbf17c0e29 100644 --- a/big_tests/tests/ejabberdctl_SUITE.erl +++ b/big_tests/tests/ejabberdctl_SUITE.erl @@ -115,20 +115,19 @@ all() -> ]. groups() -> - G = [{accounts, [sequence], accounts()}, - {sessions, [sequence], sessions()}, - {vcard, [sequence], vcard()}, - {roster, [sequence], roster()}, - {last, [sequence], last()}, - {private, [sequence], private()}, - {stanza, [sequence], stanza()}, - {roster_advanced, [sequence], roster_advanced()}, - {basic, [sequence], basic()}, - {stats, [sequence], stats()}, - {upload, [], upload()}, - {upload_with_acl, [], upload_enabled()}, - {upload_without_acl, [], upload_enabled()}], - ct_helper:repeat_all_until_all_ok(G). + [{accounts, [sequence], accounts()}, + {sessions, [sequence], sessions()}, + {vcard, [sequence], vcard()}, + {roster, [sequence], roster()}, + {last, [sequence], last()}, + {private, [sequence], private()}, + {stanza, [sequence], stanza()}, + {roster_advanced, [sequence], roster_advanced()}, + {basic, [sequence], basic()}, + {stats, [sequence], stats()}, + {upload, [], upload()}, + {upload_with_acl, [], upload_enabled()}, + {upload_without_acl, [], upload_enabled()}]. basic() -> [simple_register, From 477acad5af1753bc1778557ecd960fc25184afd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:40:02 +0200 Subject: [PATCH 5/8] Restore auth config for host type, not for domain --- big_tests/tests/mongoose_helper.erl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/big_tests/tests/mongoose_helper.erl b/big_tests/tests/mongoose_helper.erl index c9915390ff..e8716ca760 100644 --- a/big_tests/tests/mongoose_helper.erl +++ b/big_tests/tests/mongoose_helper.erl @@ -462,11 +462,10 @@ backup_sasl_mechanisms_config(Config) -> [{global_sasl_mechanisms, GlobalSASLMechanisms}, {host_sasl_mechanisms, HostSASLMechanisms} | Config]. - restore_auth_config(Config) -> - XMPPDomain = escalus_ejabberd:unify_str_arg(ct:get_config({hosts, mim, domain})), + HostType = domain_helper:host_type(), AuthOpts = proplists:get_value(auth_opts, Config), - rpc(mim(), ejabberd_config, add_local_option, [{auth_opts, XMPPDomain}, AuthOpts]). + rpc(mim(), ejabberd_config, add_local_option, [{auth_opts, HostType}, AuthOpts]). restore_sasl_mechanisms_config(Config) -> XMPPDomain = escalus_ejabberd:unify_str_arg(ct:get_config({hosts, mim, domain})), From 1d98986e62aced0522e73130af0d57d9f7c51157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:39:21 +0200 Subject: [PATCH 6/8] Make test roster items independent of the domain --- big_tests/tests/ejabberdctl_SUITE_data/roster.template | 7 ------- big_tests/tests/ejabberdctl_SUITE_data/roster.template.in | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 big_tests/tests/ejabberdctl_SUITE_data/roster.template create mode 100644 big_tests/tests/ejabberdctl_SUITE_data/roster.template.in diff --git a/big_tests/tests/ejabberdctl_SUITE_data/roster.template b/big_tests/tests/ejabberdctl_SUITE_data/roster.template deleted file mode 100644 index fc8240f640..0000000000 --- a/big_tests/tests/ejabberdctl_SUITE_data/roster.template +++ /dev/null @@ -1,7 +0,0 @@ -[ - {"alice", "localhost", "Group", "Alice"}, - {"bob", "localhost", "Group", "Bob"}, - {"kate", "localhost", "Group", "Kate"}, - {"mike", "localhost", "Group", "Mike"}, - {"unicoder-иии", "localhost", "Group-иии", "Unicoder-иии"} -]. diff --git a/big_tests/tests/ejabberdctl_SUITE_data/roster.template.in b/big_tests/tests/ejabberdctl_SUITE_data/roster.template.in new file mode 100644 index 0000000000..337a8b60a6 --- /dev/null +++ b/big_tests/tests/ejabberdctl_SUITE_data/roster.template.in @@ -0,0 +1,7 @@ +[ + {"alice", "Group", "Alice"}, + {"bob", "Group", "Bob"}, + {"kate", "Group", "Kate"}, + {"mike", "Group", "Mike"}, + {"unicoder-иии", "Group-иии", "Unicoder-иии"} +]. From 98669307a358f44edf5af1b0b8ab26dd733c878d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:46:38 +0200 Subject: [PATCH 7/8] Prepare roster template for the configured domain --- big_tests/tests/ejabberdctl_SUITE.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/big_tests/tests/ejabberdctl_SUITE.erl b/big_tests/tests/ejabberdctl_SUITE.erl index fbf17c0e29..ceeb30f9b5 100644 --- a/big_tests/tests/ejabberdctl_SUITE.erl +++ b/big_tests/tests/ejabberdctl_SUITE.erl @@ -191,13 +191,21 @@ init_per_suite(Config) -> Node = mim(), Config1 = ejabberd_node_utils:init(Node, Config), Config2 = escalus:init_per_suite([{ctl_auth_mods, AuthMods}, - {roster_template, TemplatePath} | Config1]), + {roster_template, TemplatePath} | Config1]), + prepare_roster_template(TemplatePath, domain()), %% dump_and_load requires at least one mnesia table %% ensure, that passwd table is available Host = ct:get_config({hosts, mim, domain}), catch rpc_call(ejabberd_auth_internal, start, [Host]), escalus:create_users(Config2, escalus:get_users([alice, mike, bob, kate])). +prepare_roster_template(TemplatePath, Domain) -> + {ok, [RosterIn]} = file:consult(TemplatePath ++ ".in"), + DomainStr = binary_to_list(Domain), + Roster = [{User, DomainStr, Group, Name} || {User, Group, Name} <- RosterIn], + FormattedRoster = io_lib:format("~tp.~n", [Roster]), + file:write_file(TemplatePath, FormattedRoster). + end_per_suite(Config) -> Config1 = lists:keydelete(ctl_auth_mods, 1, Config), delete_users(Config1), From 73a5fe3b057e35ec516fca977b7b435d2a1f850a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Wed, 15 Sep 2021 13:48:28 +0200 Subject: [PATCH 8/8] Adapt ejabberdctl_SUITE for dynamic domains Also: - Do not skip some tests for RDBMS as the schema contains the server now --- big_tests/tests/ejabberdctl_SUITE.erl | 47 ++++++++++----------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/big_tests/tests/ejabberdctl_SUITE.erl b/big_tests/tests/ejabberdctl_SUITE.erl index ceeb30f9b5..5f124de19f 100644 --- a/big_tests/tests/ejabberdctl_SUITE.erl +++ b/big_tests/tests/ejabberdctl_SUITE.erl @@ -26,6 +26,7 @@ -import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]). +-import(domain_helper, [host_type/0]). -define(HTTP_UPLOAD_FILENAME, "tmp.txt"). -define(HTTP_UPLOAD_FILESIZE, "5"). @@ -39,7 +40,7 @@ -define(HTTP_UPLOAD_PARAMS_WITH_TIMEOUT(X), ?HTTP_UPLOAD_PARAMS(?HTTP_UPLOAD_FILENAME, ?HTTP_UPLOAD_FILESIZE, "", X)). -define(HTTP_UPLOAD_PARAMS(FileName, FileSize, ContentType, Timeout), - [ct:get_config({hosts, mim, domain}), FileName, FileSize, ContentType, Timeout]). + [domain(), FileName, FileSize, ContentType, Timeout]). -define(CTL_ERROR(Messsage), "Error: \"" ++ Messsage ++ "\"\n"). -define(HTTP_UPLOAD_NOT_ENABLED_ERROR, ?CTL_ERROR("mod_http_upload is not loaded for this host")). @@ -195,8 +196,7 @@ init_per_suite(Config) -> prepare_roster_template(TemplatePath, domain()), %% dump_and_load requires at least one mnesia table %% ensure, that passwd table is available - Host = ct:get_config({hosts, mim, domain}), - catch rpc_call(ejabberd_auth_internal, start, [Host]), + catch rpc_call(ejabberd_auth_internal, start, [host_type()]), escalus:create_users(Config2, escalus:get_users([alice, mike, bob, kate])). prepare_roster_template(TemplatePath, Domain) -> @@ -212,30 +212,24 @@ end_per_suite(Config) -> escalus:end_per_suite(Config1). init_per_group(vcard, Config) -> - case rpc(mim(), gen_mod, get_module_opt, - [ct:get_config({hosts, mim, domain}), mod_vcard, backend, mnesia]) - of + case rpc(mim(), gen_mod, get_module_opt, [host_type(), mod_vcard, backend, mnesia]) of ldap -> {skip, vcard_set_not_supported_with_ldap}; _ -> Config end; init_per_group(roster_advanced, Config) -> - case rpc(mim(), gen_mod, get_module_opt, - [ct:get_config({hosts, mim, domain}), mod_roster, backend, mnesia]) - of + case rpc(mim(), gen_mod, get_module_opt, [host_type(), mod_roster, backend, mnesia]) of mnesia -> Config; _ -> {skip, command_process_rosteritems_supports_only_mnesia} end; init_per_group(upload_without_acl, Config) -> - Host = ct:get_config({hosts, mim, domain}), - dynamic_modules:start(Host, mod_http_upload, ?MINIO_OPTS(false)), + dynamic_modules:start(host_type(), mod_http_upload, ?MINIO_OPTS(false)), [{with_acl, false} | Config]; init_per_group(upload_with_acl, Config) -> - Host = ct:get_config({hosts, mim, domain}), - dynamic_modules:start(Host, mod_http_upload, ?MINIO_OPTS(true)), + dynamic_modules:start(host_type(), mod_http_upload, ?MINIO_OPTS(true)), [{with_acl, true} | Config]; init_per_group(_GroupName, Config) -> Config. @@ -259,25 +253,21 @@ end_per_group(Rosters, Config) when (Rosters == roster) or (Rosters == roster_ad Config; end_per_group(UploadGroup, Config) when UploadGroup =:= upload_without_acl; UploadGroup =:= upload_with_acl -> - Host = ct:get_config({hosts, mim, domain}), - dynamic_modules:stop(Host, mod_http_upload), + dynamic_modules:stop(host_type(), mod_http_upload), Config; end_per_group(_GroupName, Config) -> Config. get_registered_users() -> - Host = ct:get_config({hosts, mim, domain}), - Users = rpc(mim(), ejabberd_auth, get_vh_registered_users, [Host]). + rpc(mim(), ejabberd_auth, get_vh_registered_users, [domain()]). init_per_testcase(CaseName, Config) - % these cases are incompatible with domainless rdbms schema when CaseName == delete_old_users_vhost orelse CaseName == stats_global orelse CaseName == stats_host -> {_, AuthMods} = lists:keyfind(ctl_auth_mods, 1, Config), - case lists:member(ejabberd_auth_rdbms, AuthMods) orelse - lists:member(ejabberd_auth_ldap, AuthMods) of - true -> {skip, vhost_rdbms_incompatible}; + case lists:member(ejabberd_auth_ldap, AuthMods) of + true -> {skip, "not supported for LDAP"}; false -> escalus:init_per_testcase(CaseName, Config) end; init_per_testcase(check_password_hash, Config) -> @@ -1093,7 +1083,7 @@ stats_host(Config) -> simple_register(Config) -> %% given - Domain = ct:get_config({hosts, mim, domain}), + Domain = domain(), {Name, Password} = {<<"tyler">>, <<"durden">>}, %% when {R1, 0} = ejabberdctl("registered_users", [Domain], Config), @@ -1108,7 +1098,7 @@ simple_register(Config) -> simple_unregister(Config) -> %% given - Domain = ct:get_config({hosts, mim, domain}), + Domain = domain(), {Name, _} = {<<"tyler">>, <<"durden">>}, %% when {_, 0} = ejabberdctl("unregister", [Name, Domain], Config), @@ -1118,7 +1108,7 @@ simple_unregister(Config) -> register_twice(Config) -> %% given - Domain = ct:get_config({hosts, mim, domain}), + Domain = domain(), {Name, Password} = {<<"tyler">>, <<"durden">>}, %% when {_, 0} = ejabberdctl("register_identified", [Name, Domain, Password], Config), @@ -1208,8 +1198,8 @@ remove_old_messages_test(Config) -> OfflineOld = generate_offline_message(JidRecordAlice, JidRecordBob, Msg1, OldTimestamp), OfflineNew = generate_offline_message(JidRecordAlice, JidRecordBob, Msg2, os:system_time(microsecond)), {jid, _, _, _, LUser, LServer, _} = JidRecordBob, - HostType = domain_helper:host_type(), - rpc_call(mod_offline_backend, write_messages, [HostType, LUser, LServer, [OfflineOld, OfflineNew]]), + HostType = host_type(), + rpc_call(mod_offline_backend, write_messages, [host_type(), LUser, LServer, [OfflineOld, OfflineNew]]), %% when {_, 0} = ejabberdctl("delete_old_messages", [LServer, "1"], Config), {ok, SecondList} = rpc_call(mod_offline_backend, pop_messages, [HostType, JidRecordBob]), @@ -1246,7 +1236,7 @@ remove_expired_messages_test(Config) -> ExpirationTimeFuture), {jid, _, _, _, LUser, LServer, _} = JidRecordKate, Args = [OfflineOld, OfflineNow, OfflineFuture, OfflineFuture2], - HostType = domain_helper:host_type(), + HostType = host_type(), rpc_call(mod_offline_backend, write_messages, [HostType, LUser, LServer, Args]), %% when {_, 0} = ejabberdctl("delete_expired_messages", [LServer], Config), @@ -1296,9 +1286,8 @@ get_sha(AccountPass) -> || X <- binary_to_list(crypto:hash(sha, AccountPass))]). set_last(User, Domain, TStamp) -> - HostType = domain_helper:host_type(), rpc(mim(), mod_last, store_last_info, - [HostType, escalus_utils:jid_to_lower(User), Domain, TStamp, <<>>]). + [host_type(), escalus_utils:jid_to_lower(User), Domain, TStamp, <<>>]). delete_users(Config) -> Users = escalus_users:get_users([alice, bob, kate, mike]),