Skip to content

Commit

Permalink
Update tests after converting access commands to maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Chrząszcz committed May 26, 2022
1 parent c3ca728 commit 4f53d01
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
23 changes: 14 additions & 9 deletions test/commands_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,28 @@ old_exec(_C) ->

old_access_ctl(_C) ->
%% with no auth method it is all fine
checkauth(true, [], noauth),
checkauth(true, #{}, noauth),
%% noauth fails if first item is not 'all' (users)
checkauth(account_unprivileged, [{none, none, []}], noauth),
checkauth(account_unprivileged, #{none => command_rules(all)}, noauth),
%% if here we allow all commands to noauth
checkauth(true, [{all, all, []}], noauth),
checkauth(true, #{all => command_rules(all)}, noauth),
%% and here only command_one
checkauth(true, [{all, [command_one], []}], noauth),
checkauth(true, #{all => command_rules([command_one])}, noauth),
%% so this'd fail
checkauth(account_unprivileged, [{all, [command_two], []}], noauth),
checkauth(account_unprivileged, #{all => command_rules([command_two])}, noauth),
% now we provide a role name, this requires a user and triggers password and acl check
% this fails because password is bad
checkauth(invalid_account_data, [{some_acl_role, [command_one], []}], {<<"zenek">>, <<"localhost">>, <<"bbb">>}),
checkauth(invalid_account_data, #{some_acl_role => command_rules([command_one])},
{<<"zenek">>, <<"localhost">>, <<"bbb">>}),
% this, because of acl
checkauth(account_unprivileged, [{some_acl_role, [command_one], []}], {<<"zenek">>, <<"localhost">>, <<"">>}),
checkauth(account_unprivileged, #{some_acl_role => command_rules([command_one])},
{<<"zenek">>, <<"localhost">>, <<"">>}),
% and this should work, because we define command_one as available to experts only, while acls in config
% (see ggo/1) state that experts-only funcs are available to coders and managers, and zenek is a coder, gah.
checkauth(true, [{experts_only, [command_one], []}], {<<"zenek">>, <<"localhost">>, <<"">>}),
checkauth(true, #{experts_only => command_rules([command_one])},
{<<"zenek">>, <<"localhost">>, <<"">>}),
ok.


new_type_checker(_C) ->
true = t_check_type({msg, binary}, <<"zzz">>),
true = t_check_type({msg, integer}, 127),
Expand Down Expand Up @@ -603,6 +605,9 @@ mc_holder() ->
end,
erlang:exit(Pid, kill).

command_rules(Commands) ->
#{commands => Commands, argument_restrictions => #{}}.

checkauth(true, AccessCommands, Auth) ->
B = <<"bzzzz">>,
B = ejabberd_commands:execute_command(AccessCommands, Auth, command_one, [B]);
Expand Down
15 changes: 9 additions & 6 deletions test/common/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ options("host_types") ->
{language, <<"en">>},
{listen, []},
{loglevel, warning},
{mongooseimctl_access_commands, []},
{mongooseimctl_access_commands, #{}},
{outgoing_pools, []},
{rdbms_server_type, generic},
{registration_timeout, 600},
Expand Down Expand Up @@ -78,7 +78,8 @@ options("miscellaneous") ->
})]},
{loglevel, warning},
{mongooseimctl_access_commands,
[{local, ["join_cluster"], [{node, "mongooseim@prime"}]}]},
#{local => #{commands => [join_cluster],
argument_restrictions => #{node => "mongooseim@prime"}}}},
{outgoing_pools, []},
{rdbms_server_type, mssql},
{registration_timeout, 600},
Expand Down Expand Up @@ -109,7 +110,7 @@ options("modules") ->
{language, <<"en">>},
{listen, []},
{loglevel, warning},
{mongooseimctl_access_commands, []},
{mongooseimctl_access_commands, #{}},
{outgoing_pools, []},
{rdbms_server_type, generic},
{registration_timeout, 600},
Expand Down Expand Up @@ -240,7 +241,7 @@ options("mongooseim-pgsql") ->
]},
{loglevel, warning},
{max_fsm_queue, 1000},
{mongooseimctl_access_commands, []},
{mongooseimctl_access_commands, #{}},
{outgoing_pools,
lists:map(
fun pool_config/1,
Expand Down Expand Up @@ -318,7 +319,7 @@ options("outgoing_pools") ->
{language, <<"en">>},
{listen, []},
{loglevel, warning},
{mongooseimctl_access_commands, []},
{mongooseimctl_access_commands, #{}},
{outgoing_pools,
lists:map(
fun pool_config/1,
Expand Down Expand Up @@ -389,7 +390,7 @@ options("s2s_only") ->
{language, <<"en">>},
{listen, []},
{loglevel, warning},
{mongooseimctl_access_commands, []},
{mongooseimctl_access_commands, #{}},
{outgoing_pools, []},
{rdbms_server_type, generic},
{registration_timeout, 600},
Expand Down Expand Up @@ -1072,6 +1073,8 @@ extra_service_listener_config() ->
hidden_components => false,
conflict_behaviour => disconnect}.

default_config([general, mongooseimctl_access_commands, _Key]) ->
#{commands => all, argument_restrictions => #{}};
default_config([listen, http]) ->
(common_listener_config())#{module => ejabberd_cowboy,
transport => default_config([listen, http, transport]),
Expand Down
31 changes: 11 additions & 20 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -408,26 +408,17 @@ route_subdomains(_Config) ->
?errh(#{<<"general">> => #{<<"route_subdomains">> => <<"c2s">>}}).

mongooseimctl_access_commands(_Config) ->
?cfg(mongooseimctl_access_commands, [], #{}), % default
AccessRule = #{<<"commands">> => [<<"join_cluster">>],
<<"argument_restrictions">> => #{<<"node">> => <<"mim1@host1">>}},
?cfg(mongooseimctl_access_commands, [{local, ["join_cluster"], [{node, "mim1@host1"}]}],
#{<<"general">> => #{<<"mongooseimctl_access_commands">> =>
#{<<"local">> => AccessRule}}}),
?cfg(mongooseimctl_access_commands, [{local, all, [{node, "mim1@host1"}]}],
#{<<"general">> => #{<<"mongooseimctl_access_commands">> =>
#{<<"local">> => maps:remove(<<"commands">>, AccessRule)}}}),
?cfg(mongooseimctl_access_commands, [{local, ["join_cluster"], []}],
#{<<"general">> => #{<<"mongooseimctl_access_commands">> =>
#{<<"local">> => maps:remove(<<"argument_restrictions">>,
AccessRule)}}}),
?cfg(mongooseimctl_access_commands, [{local, all, []}],
#{<<"general">> => #{<<"mongooseimctl_access_commands">> => #{<<"local">> => #{}}}}),
?err(#{<<"general">> => #{<<"mongooseimctl_access_commands">> =>
#{<<"local">> => #{<<"commands">> => <<"all">>}}}}),
?err(#{<<"general">> => #{<<"mongooseimctl_access_commands">> =>
#{<<"local">> => #{<<"argument_restrictions">> =>
[<<"none">>]}}}}).
?cfg(mongooseimctl_access_commands, #{}, #{}), % default
P = [mongooseimctl_access_commands, local],
T = fun(Opts) ->
#{<<"general">> => #{<<"mongooseimctl_access_commands">> => #{<<"local">> => Opts}}}
end,
?cfg(P, default_config([general, mongooseimctl_access_commands, local]), T(#{})),
?cfg(P ++ [commands], [join_cluster], T(#{<<"commands">> => [<<"join_cluster">>]})),
?cfg(P ++ [argument_restrictions], #{node => "mim1@host1"},
T(#{<<"argument_restrictions">> => #{<<"node">> => <<"mim1@host1">>}})),
?err(T(#{<<"commands">> => [<<>>]})),
?err(T(#{<<"argument_restrictions">> => #{<<"node">> => 1}})).

routing_modules(_Config) ->
?cfg(routing_modules, mongoose_router:default_routing_modules(), #{}), % default
Expand Down
2 changes: 1 addition & 1 deletion test/mongoose_config_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ minimal_config_opts() ->
{language, <<"en">>},
{listen, []},
{loglevel, warning},
{mongooseimctl_access_commands, []},
{mongooseimctl_access_commands, #{}},
{outgoing_pools, []},
{rdbms_server_type, generic},
{registration_timeout, 600},
Expand Down

0 comments on commit 4f53d01

Please sign in to comment.