Skip to content

Commit

Permalink
Merge pull request #3537 from esl/module-opts-map-adhoc
Browse files Browse the repository at this point in the history
  • Loading branch information
gustawlippa committed Feb 10, 2022
2 parents 6eeb6b4 + 9152e0e commit 7f04df9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
23 changes: 12 additions & 11 deletions big_tests/tests/adhoc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ all() ->

groups() ->
[{adhoc, [parallel], common_disco_cases() ++ hidden_disco_cases() ++ [ping]},
{disco_visible, [parallel], common_disco_cases() ++ visible_disco_cases()}].
{disco_visible, [parallel], common_disco_cases() ++ visible_disco_cases()}].

common_disco_cases() ->
[disco_info,
Expand Down Expand Up @@ -76,17 +76,18 @@ init_per_testcase(CaseName, Config) ->
end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).

init_modules(disco_visible, Config) ->
init_modules(GroupName, Config) ->
Config1 = escalus:init_per_suite(dynamic_modules:save_modules(host_type(), Config)),
dynamic_modules:ensure_modules(host_type(), [{mod_adhoc, [{report_commands_node, true}]}]),
Config1;
init_modules(_, Config) ->
Config.

restore_modules(disco_visible, Config) ->
dynamic_modules:restore_modules(Config);
restore_modules(_, _Config) ->
ok.
dynamic_modules:ensure_modules(host_type(), [{mod_adhoc, adhoc_opts(GroupName)}]),
Config1.

restore_modules(_GroupName, Config) ->
dynamic_modules:restore_modules(Config).

adhoc_opts(disco_visible) ->
#{iqdisc => one_queue, report_commands_node => true};
adhoc_opts(_GroupName) ->
#{iqdisc => one_queue, report_commands_node => false}.

%%--------------------------------------------------------------------
%% Adhoc tests
Expand Down
16 changes: 10 additions & 6 deletions src/mod_adhoc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@
-include("adhoc.hrl").
-include("mongoose_config_spec.hrl").

start(HostType, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),

-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
start(HostType, #{iqdisc := IQDisc}) ->
[gen_iq_handler:add_iq_handler_for_domain(HostType, ?NS_COMMANDS, Component, Fn, #{}, IQDisc) ||
{Component, Fn} <- iq_handlers()],
ejabberd_hooks:add(hooks(HostType)).

-spec stop(mongooseim:host_type()) -> ok.
stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)),
[gen_iq_handler:remove_iq_handler_for_domain(HostType, ?NS_COMMANDS, Component) ||
{Component, _Fn} <- iq_handlers()].
{Component, _Fn} <- iq_handlers()],
ok.

iq_handlers() ->
[{ejabberd_local, fun ?MODULE:process_local_iq/5},
Expand All @@ -90,7 +91,10 @@ hooks(HostType) ->
config_spec() ->
#section{
items = #{<<"report_commands_node">> => #option{type = boolean},
<<"iqdisc">> => mongoose_config_spec:iqdisc()}
<<"iqdisc">> => mongoose_config_spec:iqdisc()},
defaults = #{<<"report_commands_node">> => false,
<<"iqdisc">> => one_queue},
format_items = map
}.

-spec supported_features() -> [atom()].
Expand Down Expand Up @@ -172,7 +176,7 @@ disco_sm_items(Acc) ->
Acc.

are_commands_visible(HostType) ->
gen_mod:get_module_opt(HostType, ?MODULE, report_commands_node, false).
gen_mod:get_module_opt(HostType, ?MODULE, report_commands_node).

item(LServer, Node, Name, Lang) ->
#{jid => LServer, node => Node, name => translate:translate(Lang, Name)}.
Expand Down
17 changes: 9 additions & 8 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1575,23 +1575,24 @@ s2s_max_retry_delay(_Config) ->
%% modules

mod_adhoc(_Config) ->
check_iqdisc(mod_adhoc),
M = fun(K, V) -> modopts(mod_adhoc, [{K, V}]) end,
check_module_defaults(mod_adhoc),
check_iqdisc_map(mod_adhoc),
P = [modules, mod_adhoc],
T = fun(K, V) -> #{<<"modules">> => #{<<"mod_adhoc">> => #{K => V}}} end,
%% report_commands_node is boolean
?cfgh(M(report_commands_node, true), T(<<"report_commands_node">>, true)),
?cfgh(M(report_commands_node, false), T(<<"report_commands_node">>, false)),
?cfgh(P ++ [report_commands_node], true, T(<<"report_commands_node">>, true)),
?cfgh(P ++ [report_commands_node], false, T(<<"report_commands_node">>, false)),
%% not boolean
?errh(T(<<"report_commands_node">>, <<"hello">>)).

mod_auth_token(_Config) ->
check_module_defaults(mod_auth_token),
check_iqdisc_map(mod_auth_token),
P = [modules, mod_auth_token, validity_period],
T = fun(X) ->
Opts = #{<<"validity_period">> => X},
#{<<"modules">> => #{<<"mod_auth_token">> => Opts}}
end,
check_module_defaults(mod_auth_token),
P = [modules, mod_auth_token, validity_period],
?cfgh(P ++ [access], #{unit => minutes, value => 13},
T(#{<<"access">> => #{<<"value">> => 13, <<"unit">> => <<"minutes">>}})),
?cfgh(P ++ [refresh], #{unit => days, value => 31},
Expand Down Expand Up @@ -1692,13 +1693,13 @@ mod_disco(_Config) ->
?errh(T(<<"server_info">>, [maps:remove(<<"urls">>, Info)])).

mod_extdisco(_Config) ->
check_module_defaults(mod_extdisco),
check_iqdisc_map(mod_extdisco),
P = [modules, mod_extdisco, service],
T = fun(Opts) -> #{<<"modules">> =>
#{<<"mod_extdisco">> =>
#{<<"service">> => [Opts]}}}
end,
check_module_defaults(mod_extdisco),
P = [modules, mod_extdisco, service],
RequiredOpts = #{<<"type">> => <<"stun">>, <<"host">> => <<"stun1">>},
Service = #{type => stun, host => <<"stun1">>},
?cfgh(P, [Service], T(RequiredOpts)),
Expand Down
8 changes: 6 additions & 2 deletions test/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ all_modules() ->
{plugin_module, mod_event_pusher_push_plugin_defaults},
{virtual_pubsub_hosts, [{fqdn, <<"host1">>}, {fqdn, <<"host2">>}]},
{wpool, [{workers, 200}]}],
mod_adhoc => [{iqdisc, one_queue}, {report_commands_node, true}],
mod_adhoc => #{iqdisc => one_queue, report_commands_node => true},
mod_mam_rdbms_arch_async => [{pm, []}],
mod_keystore =>
[{keys,
Expand Down Expand Up @@ -642,7 +642,8 @@ all_modules() ->
{stale_h_repeat_after, 1800}]}]}.

pgsql_modules() ->
#{mod_adhoc => [], mod_amp => [], mod_blocking => [], mod_bosh => [],
#{mod_adhoc => default_mod_config(mod_adhoc),
mod_amp => [], mod_blocking => [], mod_bosh => [],
mod_carboncopy => [], mod_commands => [],
mod_disco => [{users_can_see_hidden_services, false}],
mod_last => [{backend, rdbms}],
Expand Down Expand Up @@ -750,6 +751,9 @@ pgsql_access() ->
register => [#{acl => all, value => allow}],
s2s_shaper => [#{acl => all, value => fast}]}.

default_mod_config(mod_adhoc) ->
#{iqdisc => one_queue,
report_commands_node => false};
default_mod_config(mod_auth_token) ->
#{iqdisc => no_queue,
validity_period => #{access => #{unit => hours, value => 1},
Expand Down

0 comments on commit 7f04df9

Please sign in to comment.