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

Prepare for dynamic domains in big tests #3109

Merged
merged 3 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions big_tests/dynamic_domains.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{domain, <<"domain.example.com">>},
{secondary_domain, <<"domain.example.org">>},
{dynamic_domains, [<<"domain.example.com">>, <<"domain.example.org">>]},
{host_type, <<"test type">>},
{vars, "mim1"},
{cluster, mim},
{s2s_port, 5269},
Expand Down
2 changes: 1 addition & 1 deletion big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%% http://www.erlang.org/doc/apps/common_test/run_test_chapter.html#test_specifications
{include, "tests"}.

{suites, "tests", domain_isolation_SUITE}.
{suites, "tests", acc_e2e_SUITE}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we remove domain_isolation_SUITE?

Copy link
Member Author

@chrzaszcz chrzaszcz May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suite was passing only because filter_local_packet was executed per domain. The mod_domain_isolation module does not support dynamic domains yet. The tests suite itself also does not use host types correctly and it needs to be addressed. I think it should be done in a separate story.


{config, ["dynamic_domains.config", "test.config"]}.
{logdir, "ct_report"}.
Expand Down
7 changes: 4 additions & 3 deletions big_tests/tests/acc_e2e_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ acc_test_helper_code(Config) ->
binary_to_list(Code).

add_handler(Hook, F, Seq) ->
rpc(mim(), ejabberd_hooks, add, [Hook, host(), acc_test_helper, F, Seq]).
rpc(mim(), ejabberd_hooks, add, handler(Hook, F, Seq)).

remove_handler(Hook, F, Seq) ->
rpc(mim(), ejabberd_hooks, delete, [Hook, host(), acc_test_helper, F, Seq]).
rpc(mim(), ejabberd_hooks, delete, handler(Hook, F, Seq)).

host() -> <<"localhost">>.
handler(Hook, F, Seq) ->
[Hook, domain_helper:host_type(mim), acc_test_helper, F, Seq].

%% creates a temporary ets table keeping refs and some attrs of accumulators created in c2s
recreate_table() ->
Expand Down
28 changes: 18 additions & 10 deletions big_tests/tests/domain_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@

-export([insert_configured_domains/0,
delete_configured_domains/0,
insert_domain/2,
delete_domain/2]).
insert_domain/3,
delete_domain/2,
host_type/1,
host_type/2]).

-import(distributed_helper, [get_or_fail/1, rpc/4]).

host_type(NodeKey) ->
host_type(NodeKey, domain).

host_type(NodeKey, DomainKey) ->
Node = #{node => get_or_fail({hosts, NodeKey, node})},
Domain = get_or_fail({hosts, NodeKey, DomainKey}),
{ok, HostType} = rpc(Node, mongoose_domain_core, get_host_type, [Domain]),
HostType.

insert_configured_domains() ->
for_each_configured_domain(fun insert_domain/2).
for_each_configured_domain(fun insert_domain/3).

delete_configured_domains() ->
for_each_configured_domain(fun delete_domain/2).
for_each_configured_domain(fun(Node, Domain, _) -> delete_domain(Node, Domain) end).

insert_domain(Node, Domain) ->
ok = rpc(Node, mongoose_domain_core, insert, [Domain, host_type(), dummy_source]).
insert_domain(Node, Domain, HostType) ->
ok = rpc(Node, mongoose_domain_core, insert, [Domain, HostType, dummy_source]).

delete_domain(Node, Domain) ->
ok = rpc(Node, mongoose_domain_core, delete, [Domain]).

for_each_configured_domain(F) ->
[F(#{node => proplists:get_value(node, Opts)}, Domain) ||
[F(#{node => proplists:get_value(node, Opts)}, Domain, proplists:get_value(host_type, Opts)) ||
{_, Opts} <- ct:get_config(hosts),
Domain <- proplists:get_value(dynamic_domains, Opts, [])].

host_type() ->
<<"test type">>. %% preconfigured in the toml file
2 changes: 1 addition & 1 deletion big_tests/tests/dynamic_domains_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ iq_handling_for_subdomain(Config) ->

%% helper functions
insert_domains(Nodes, Domains) ->
[domain_helper:insert_domain(Node, Domain) || Node <- Nodes, Domain <- Domains].
[domain_helper:insert_domain(Node, Domain, ?HOST_TYPE) || Node <- Nodes, Domain <- Domains].

remove_domains(Nodes, Domains) ->
[domain_helper:delete_domain(Node, Domain) || Node <- Nodes, Domain <- Domains].
Expand Down
1 change: 1 addition & 0 deletions big_tests/tests/ejabberdctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ end_per_group(Rosters, Config) when (Rosters == roster) or (Rosters == roster_ad
Acc = rpc(mim(), mongoose_acc, new,
[#{ location => {?MODULE, ?FUNCTION_NAME, ?LINE},
lserver => SB,
host_type => SB,
element => undefined }]),
rpc(mim(), mongoose_hooks, remove_user, [SB, Acc, UB]);
_ ->
Expand Down
2 changes: 1 addition & 1 deletion src/admin_extra/service_admin_extra_gdpr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ get_data_from_modules(Username, Domain) ->

-spec get_data_from_modules(jid:jid()) -> gdpr:personal_data().
get_data_from_modules(JID) ->
{ok, HostType} = mongoose_domain_api:get_host_type(JID#jid.lserver),
{ok, HostType} = mongoose_domain_api:get_domain_host_type(JID#jid.lserver),
mongoose_hooks:get_personal_data(HostType, JID).

-spec to_csv_file(CsvFilename :: binary(), gdpr:schema(), gdpr:entities(), file:name()) -> ok.
Expand Down
2 changes: 2 additions & 0 deletions src/admin_extra/service_admin_extra_roster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ unsubscribe(LocalJID, RemoteJID) ->
[jids_nick_subs_ask_grp()].
get_roster(User, Server) ->
UserJID = jid:make(User, Server, <<>>),
{ok, HostType} = mongoose_domain_api:get_domain_host_type(UserJID#jid.lserver),
Acc = mongoose_acc:new(#{location => ?LOCATION,
host_type => HostType,
lserver => UserJID#jid.lserver,
element => undefined}),
Acc2 = mongoose_hooks:roster_get(Acc, UserJID),
Expand Down
4 changes: 2 additions & 2 deletions src/auth/ejabberd_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ entropy(IOList) ->
%% use auth_modules_for_host_type/1 function instead.
-spec auth_modules(Server :: jid:lserver()) -> [authmodule()].
auth_modules(LServer) ->
case mongoose_domain_api:get_host_type(LServer) of
case mongoose_domain_api:get_domain_host_type(LServer) of
{ok, HostType} -> auth_modules_for_host_type(HostType);
{error, not_found} -> []
end.
Expand Down Expand Up @@ -476,7 +476,7 @@ get_type_information(_IOContent, [Digit, Printable, LowLetter, HiLetter, _Other]
-spec call_auth_modules_for_domain(jid:lserver(), host_type_mod_fun(), call_opts()) ->
mod_res() | [mod_res()].
call_auth_modules_for_domain(Domain, F, Opts = #{default := Default}) ->
case mongoose_domain_api:get_host_type(Domain) of
case mongoose_domain_api:get_domain_host_type(Domain) of
{ok, HostType} ->
StepF = bind_host_type(HostType, F),
case maps:take(metric, Opts) of
Expand Down
2 changes: 1 addition & 1 deletion src/auth/ejabberd_auth_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ scram_passwords(Server, ScramIterationCount) ->
ScramIterationCount :: pos_integer().
scram_passwords(Server, Count, Interval, ScramIterationCount) ->
LServer = jid:nameprep(Server),
{ok, HostType} = mongoose_domain_api:get_host_type(LServer),
{ok, HostType} = mongoose_domain_api:get_domain_host_type(LServer),
?LOG_INFO(#{what => scram_passwords, server => Server,
text => <<"Converting the stored passwords into SCRAM bits">>}),
Selected = execute_count_users_without_scram(HostType, LServer),
Expand Down
12 changes: 11 additions & 1 deletion src/domain/mongoose_domain_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ get_domain_host_type(Domain) ->
-spec get_subdomain_host_type(domain()) ->
{ok, host_type()} | {error, not_found}.
get_subdomain_host_type(Subdomain) ->
mongoose_subdomain_core:get_host_type(Subdomain).
case mongoose_subdomain_core:get_host_type(Subdomain) of
{error, not_found} ->
case mongoose_subhosts:get_host(Subdomain) of
{ok, Domain} ->
get_domain_host_type(Domain);
undefined ->
{error, not_found}
end;
{ok, HostType} ->
{ok, HostType}
end.

%% Subdomain should be nameprepped using `jid:nameprep'
-spec get_subdomain_info(domain()) ->
Expand Down
2 changes: 1 addition & 1 deletion src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ handle_stream_start({xmlstreamstart, _Name, Attrs}, #state{} = S0) ->
Lang = get_xml_lang(Attrs),
S = S0#state{server = Server, lang = Lang, stream_mgmt = StreamMgmtConfig},
case {xml:get_attr_s(<<"xmlns:stream">>, Attrs),
mongoose_domain_api:get_host_type(Server)} of
mongoose_domain_api:get_domain_host_type(Server)} of
{?NS_STREAM, {ok, HostType}} ->
change_shaper(S, jid:make_noprep(<<>>, Server, <<>>)),
Version = xml:get_attr_s(<<"version">>, Attrs),
Expand Down
2 changes: 1 addition & 1 deletion src/ejabberd_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ start_link() ->
%% and implement two functions:
%% filter/3 - should return either 'drop' atom or its args
%% route/3, which should either:
%% - deliver the message locally by calling mongoose_local_delivery:do_local_route/3
%% - deliver the message locally by calling mongoose_local_delivery:do_route/5
%% and return 'done'
%% - deliver the message it its own way and return 'done'
%% - return its args
Expand Down
2 changes: 1 addition & 1 deletion src/ejabberd_s2s_in.erl
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ send_element(StateData, El) ->

-spec stream_features(binary()) -> [exml:element()].
stream_features(Domain) ->
case mongoose_domain_api:get_host_type(Domain) of
case mongoose_domain_api:get_domain_host_type(Domain) of
{ok, HostType} -> mongoose_hooks:s2s_stream_features(HostType, Domain);
{error, not_found} -> []
end.
Expand Down
34 changes: 21 additions & 13 deletions src/ejabberd_sm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,35 @@ start_link() ->
Packet :: exml:element() | mongoose_acc:t() | ejabberd_c2s:broadcast(),
Acc :: mongoose_acc:t().
route(From, To, #xmlel{} = Packet) ->
Acc = mongoose_acc:new(#{ location => ?LOCATION,
lserver => To#jid.lserver,
element => Packet,
from_jid => From,
to_jid => To }),
Acc = new_acc(From, To, Packet),
route(From, To, Acc);
route(From, To, {broadcast, #xmlel{} = Payload}) ->
Acc = mongoose_acc:new(#{ location => ?LOCATION,
from_jid => From,
to_jid => To,
lserver => To#jid.lserver,
element => Payload }),
Acc = new_acc(From, To, Payload),
route(From, To, Acc, {broadcast, Payload});
route(From, To, {broadcast, Payload}) ->
Acc = mongoose_acc:new(#{ location => ?LOCATION,
lserver => To#jid.lserver,
element => undefined }),
Acc = new_acc(To),
route(From, To, Acc, {broadcast, Payload});
route(From, To, Acc) ->
route(From, To, Acc, mongoose_acc:element(Acc)).

-spec new_acc(jid:jid(), jid:jid(), exml:element()) -> mongoose_acc:t().
new_acc(From, To = #jid{lserver = LServer}, Packet) ->
{ok, HostType} = mongoose_domain_api:get_domain_host_type(To#jid.lserver),
mongoose_acc:new(#{location => ?LOCATION,
host_type => HostType,
lserver => LServer,
element => Packet,
from_jid => From,
to_jid => To}).

-spec new_acc(jid:jid()) -> mongoose_acc:t().
new_acc(To = #jid{lserver = LServer}) ->
{ok, HostType} = mongoose_domain_api:get_domain_host_type(To#jid.lserver),
mongoose_acc:new(#{location => ?LOCATION,
host_type => HostType,
lserver => LServer,
element => undefined}).

route(From, To, Acc, {broadcast, Payload}) ->
try
do_route(Acc, From, To, {broadcast, Payload})
Expand Down
21 changes: 10 additions & 11 deletions src/ejabberd_sm_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,19 @@ cleanup(Node) ->
[{#session{sid = {'_', '$1'}, _ = '_'},
[{'==', {node, '$1'}, Node}],
['$_']}]),
lists:foreach(fun(#session{ usr = {U, S, R}, sid = SID }) ->
mnesia:delete({session, SID}),
Acc = mongoose_acc:new(
#{location => ?LOCATION,
lserver => S,
element => undefined}),
mongoose_hooks:session_cleanup(S,
Acc,
U, R, SID)
end, Es)

lists:foreach(fun cleanup_session/1, Es)
end,
mnesia:async_dirty(F).

cleanup_session(#session{usr = {U, S, R}, sid = SID}) ->
{ok, HostType} = mongoose_domain_api:get_domain_host_type(S),
mnesia:delete({session, SID}),
Acc = mongoose_acc:new(
#{location => ?LOCATION,
host_type => HostType,
lserver => S,
element => undefined}),
mongoose_hooks:session_cleanup(S, Acc, U, R, SID).

-spec total_count() -> integer().
total_count() ->
Expand Down
2 changes: 2 additions & 0 deletions src/ejabberd_sm_redis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ cleanup(Node) ->
%% Add possible removed ":" from encoded SID
SID = binary_to_term(mongoose_bin:join(SIDEncoded, <<":">>)),
delete_session(SID, U, S, R),
{ok, HostType} = mongoose_domain_api:get_domain_host_type(S),
Acc = mongoose_acc:new(
#{location => ?LOCATION,
host_type => HostType,
lserver => S,
element => undefined}),
mongoose_hooks:session_cleanup(S,
Expand Down
2 changes: 1 addition & 1 deletion src/ejabberd_users.erl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ code_change(_OldVsn, State, _Extra) ->

-spec does_stored_user_exist(jid:jid()) -> boolean().
does_stored_user_exist(JID = #jid{lserver = LServer}) ->
case mongoose_domain_api:get_host_type(LServer) of
case mongoose_domain_api:get_domain_host_type(LServer) of
{ok, HostType} ->
case ejabberd_auth:does_stored_user_exist(HostType, JID) of
true -> true;
Expand Down
5 changes: 4 additions & 1 deletion src/event_pusher/mod_event_pusher_push_plugin_defaults.erl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ publish_via_hook(Acc0, Host, To, {PubsubJID, Node, Form}, PushPayload) ->
any().
publish_via_pubsub(Host, To, {PubsubJID, Node, Form}, PushPayload) ->
Stanza = push_notification_iq(Node, Form, PushPayload),
%% TODO host type should be provided to this function
{ok, HostType} = mongoose_domain_api:get_domain_host_type(Host),
Acc = mongoose_acc:new(#{ location => ?LOCATION,
lserver => To#jid.lserver,
host_type => HostType,
lserver => Host,
element => jlib:iq_to_xml(Stanza),
from_jid => To,
to_jid => PubsubJID }),
Expand Down
6 changes: 4 additions & 2 deletions src/inbox/mod_inbox.erl
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ forward_messages(Acc, List, QueryId, To) when is_list(List) ->
[send_message(Acc, To, Msg) || Msg <- Msgs].

-spec send_message(mongoose_acc:t(), jid:jid(), exml:element()) -> mongoose_acc:t().
send_message(Acc, To, Msg) ->
send_message(Acc, To = #jid{lserver = LServer}, Msg) ->
BareTo = jid:to_bare(To),
{ok, HostType} = mongoose_domain_api:get_domain_host_type(LServer),
NewAcc0 = mongoose_acc:new(#{location => ?LOCATION,
lserver => To#jid.lserver,
host_type => HostType,
lserver => LServer,
element => Msg,
from_jid => BareTo,
to_jid => To}),
Expand Down
4 changes: 2 additions & 2 deletions src/inbox/mod_inbox_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ direction(From, To) ->
Packet :: packet().
handle_outgoing_message(Host, Room, To, Packet) ->
maybe_reset_unread_count(Host, To, Room, Packet),
Acc = mongoose_acc:new(#{location => ?LOCATION, lserver => Host, host_type => undefined}),
Acc = mongoose_acc:new(#{location => ?LOCATION, lserver => Host}),
maybe_write_to_inbox(Host, To, Room, Packet, Acc, fun write_to_sender_inbox/5).

-spec handle_incoming_message(Host, Room, To, Packet) -> term() when
Expand All @@ -102,7 +102,7 @@ handle_outgoing_message(Host, Room, To, Packet) ->
To :: receiver_bare_user_jid(),
Packet :: packet().
handle_incoming_message(Host, Room, To, Packet) ->
Acc = mongoose_acc:new(#{location => ?LOCATION, lserver => Host, host_type => undefined}),
Acc = mongoose_acc:new(#{location => ?LOCATION, lserver => Host}),
maybe_write_to_inbox(Host, Room, To, Packet, Acc, fun write_to_receiver_inbox/5).

maybe_reset_unread_count(Host, User, Room, Packet) ->
Expand Down
Loading