Skip to content

Commit

Permalink
Merge pull request #3095 from esl/multi-tenancy-phase-1
Browse files Browse the repository at this point in the history
Multi tenancy phase 1
  • Loading branch information
chrzaszcz authored Apr 23, 2021
2 parents b6c4fed + 64dbf33 commit d15d4d9
Show file tree
Hide file tree
Showing 134 changed files with 5,227 additions and 1,899 deletions.
1 change: 1 addition & 0 deletions big_tests/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
{suites, "tests", vcard_simple_SUITE}.
{suites, "tests", websockets_SUITE}.
{suites, "tests", xep_0352_csi_SUITE}.
{suites, "tests", service_domain_db_SUITE}.
{suites, "tests", domain_isolation_SUITE}.

{config, ["test.config"]}.
Expand Down
13 changes: 12 additions & 1 deletion big_tests/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,18 @@
{password, <<"scramshaplus">>},
{starttls, required},
{tls_module, fast_tls}
]}
]},
{alice3, [ %% used in dynamic_domains_pm_SUITE
{username, <<"alice">>},
{server, <<"example.com">>},
{host, <<"localhost">>},
{password, <<"makota2">>}]},
{bob3, [
{username, <<"bob">>},
{server, <<"example.org">>},
{host, <<"localhost">>},
{password, <<"makota3">>},
{port, 5232}]}
]}.

{escalus_anon_users, [
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/connect_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ end_per_group(_, Config) ->
Config.

init_per_testcase(close_connection_if_service_type_is_hidden = CN, Config) ->
OptName = {hide_service_name, <<"localhost">>},
OptName = hide_service_name,
mongoose_helper:successful_rpc(ejabberd_config, add_local_option, [OptName, true]),
escalus:init_per_testcase(CN, Config);
init_per_testcase(replaced_session_cannot_terminate = CN, Config) ->
Expand All @@ -197,7 +197,7 @@ init_per_testcase(CaseName, Config) ->
escalus:init_per_testcase(CaseName, Config).

end_per_testcase(close_connection_if_service_type_is_hidden = CN, Config) ->
OptName = {hide_service_name, <<"localhost">>},
OptName = hide_service_name,
mongoose_helper:successful_rpc(ejabberd_config, del_local_option, [OptName]),
escalus:end_per_testcase(CN, Config);
end_per_testcase(replaced_session_cannot_terminate = CN, Config) ->
Expand Down
90 changes: 90 additions & 0 deletions big_tests/tests/dynamic_domains_pm_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
-module(dynamic_domains_pm_SUITE).

%% API
-compile(export_all).
-import(distributed_helper, [mim/0, mim2/0, require_rpc_nodes/1, rpc/4]).

-define(TEST_NODES, [mim() | ?CLUSTER_NODES]).
-define(CLUSTER_NODES, [mim2()]).
-define(DOMAINS, [<<"example.com">>, <<"example.org">>]).
-define(HOST_TYPE, <<"test type">>). %% preconfigured in the toml file

suite() ->
require_rpc_nodes([mim, mim2]).

all() ->
[can_authenticate,
pm_messages,
disconnected_on_domain_disabling,
auth_domain_removal_is_triggered_on_hook].

init_per_suite(Config0) ->
Config = cluster_nodes(?CLUSTER_NODES, Config0),
insert_domains(?TEST_NODES, ?DOMAINS),
escalus:init_per_suite(Config).

end_per_suite(Config0) ->
Config = escalus:end_per_suite(Config0),
remove_domains(?TEST_NODES, ?DOMAINS),
uncluster_nodes(?CLUSTER_NODES, Config).

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

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

can_authenticate(Config) ->
UserSpecA = escalus_users:get_userspec(Config, alice3),
{ok, ClientA, _} = escalus_connection:start(UserSpecA),
UserSpecB = escalus_users:get_userspec(Config, bob3),
{ok, ClientB, _} = escalus_connection:start(UserSpecB),
escalus_connection:stop(ClientA),
escalus_connection:stop(ClientB).

pm_messages(Config) ->
StoryFn =
fun(Alice, Bob) ->
escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"OH, HAI!">>)),
escalus:assert(is_chat_message, [<<"OH, HAI!">>], escalus:wait_for_stanza(Bob)),
escalus:send(Bob, escalus_stanza:chat_to(Alice, <<"Hello there!">>)),
escalus:assert(is_chat_message, [<<"Hello there!">>], escalus:wait_for_stanza(Alice))
end,
escalus:story(Config, [{alice3, 1}, {bob3, 1}], StoryFn).

disconnected_on_domain_disabling(Config) ->
StoryFn =
fun(Alice, Bob) ->
remove_domains(?TEST_NODES, ?DOMAINS),
escalus_connection:wait_for_close(Alice, timer:seconds(5)),
escalus_connection:wait_for_close(Bob, timer:seconds(5)),
insert_domains(?TEST_NODES, ?DOMAINS)
end,
escalus:story(Config, [{alice3, 1}, {bob3, 1}], StoryFn).

auth_domain_removal_is_triggered_on_hook(_Config) ->
ok = rpc(mim(), meck, new, [ejabberd_auth_dummy, [passthrough, no_link]]),
Params = [?HOST_TYPE, <<"dummy.domain.name">>],
rpc(mim(), mongoose_hooks, remove_domain, Params),
1 = rpc(mim(), meck, num_calls, [ejabberd_auth_dummy, remove_domain, Params]),
rpc(mim(), meck, unload, [ejabberd_auth_dummy]).

%% helper functions
insert_domains(Nodes, Domains) ->
Source = dummy_source, %% can be anything, we don't care about it
[ok = rpc(Node, mongoose_domain_core, insert, [Domain, ?HOST_TYPE, Source]) ||
Node <- Nodes, Domain <- Domains].

remove_domains(Nodes, Domains) ->
[ok = rpc(Node, mongoose_domain_core, delete, [Domain]) ||
Node <- Nodes, Domain <- Domains].

cluster_nodes([], Config) -> Config;
cluster_nodes([Node | T], Config) ->
NewConfig = distributed_helper:add_node_to_cluster(Node, Config),
cluster_nodes(T, NewConfig).

uncluster_nodes([], Config) -> Config;
uncluster_nodes([Node | T], Config) ->
NewConfig = distributed_helper:remove_node_from_cluster(Node, Config),
cluster_nodes(T, NewConfig).
2 changes: 1 addition & 1 deletion big_tests/tests/ejabberdctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ end_per_group(Rosters, Config) when (Rosters == roster) or (Rosters == roster_ad
[#{ location => {?MODULE, ?FUNCTION_NAME, ?LINE},
lserver => SB,
element => undefined }]),
rpc(mim(), ejabberd_hooks, run_fold, [remove_user, SB, Acc, [UB, SB]]);
rpc(mim(), mongoose_hooks, remove_user, [SB, Acc, UB]);
_ ->
ok
end
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/login_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ verify_format(GroupName, {_User, Props}) ->
Server = proplists:get_value(server, Props),
Password = proplists:get_value(password, Props),
JID = mongoose_helper:make_jid(Username, Server),
SPassword = rpc(mim(), ejabberd_auth, get_password, [JID]),
{SPassword, _} = rpc(mim(), ejabberd_auth, get_passterm_with_authmodule, [JID]),
do_verify_format(GroupName, Password, SPassword).


Expand Down
6 changes: 3 additions & 3 deletions big_tests/tests/oauth_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ verify_format(GroupName, {_User, Props}) ->
Server = proplists:get_value(server, Props),
Password = proplists:get_value(password, Props),
JID = mongoose_helper:make_jid(Username, Server),
SPassword = rpc(mim(), ejabberd_auth, get_password, [JID]),
{SPassword, _} = rpc(mim(), ejabberd_auth, get_passterm_with_authmodule, [JID]),
do_verify_format(GroupName, Password, SPassword).

do_verify_format(login_scram, _Password, SPassword) ->
Expand Down Expand Up @@ -422,8 +422,8 @@ extract_bound_jid(BindReply) ->
cdata]).

get_provision_key(Domain) ->
RPCArgs = [get_key, Domain, [], [{provision_pre_shared, Domain}]],
[{_, RawKey}] = rpc(mim(), ejabberd_hooks, run_fold, RPCArgs),
RPCArgs = [Domain, provision_pre_shared],
[{_, RawKey}] = rpc(mim(), mongoose_hooks, get_key, RPCArgs),
RawKey.

make_vcard(Config, User) ->
Expand Down
Loading

0 comments on commit d15d4d9

Please sign in to comment.