Skip to content

Commit

Permalink
Merge pull request #3367 from esl/persistent-term-config
Browse files Browse the repository at this point in the history
Persistent term config
  • Loading branch information
NelsonVides committed Oct 28, 2021
2 parents 9786b66 + c718eb5 commit 1728c31
Show file tree
Hide file tree
Showing 109 changed files with 1,058 additions and 1,923 deletions.
54 changes: 20 additions & 34 deletions big_tests/tests/accounts_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ init_per_group(bad_cancelation, Config) ->
init_per_group(change_account_details, Config) ->
[{escalus_user_db, {module, escalus_ejabberd}} |Config];
init_per_group(change_account_details_store_plain, Config) ->
Config1 = mongoose_helper:backup_auth_config(Config),
mongoose_helper:set_store_password(plain),
AuthOpts = mongoose_helper:auth_opts_with_password_format(plain),
Config1 = mongoose_helper:backup_and_set_config_option(Config, auth_opts, AuthOpts),
[{escalus_user_db, {module, escalus_ejabberd}} |Config1];
init_per_group(registration_timeout, Config) ->
set_registration_timeout(Config);
Expand All @@ -102,8 +102,7 @@ init_per_group(users_number_estimate, Config) ->
AuthOpts = get_auth_opts(),
Key = rdbms_users_number_estimate,
NewAuthOpts = lists:keystore(Key, 1, AuthOpts, {Key, true}),
set_auth_opts(NewAuthOpts),
[{auth_opts, AuthOpts} | Config];
set_auth_opts(Config, NewAuthOpts);
init_per_group(_GroupName, Config) ->
Config.

Expand All @@ -112,7 +111,7 @@ end_per_group(change_account_details, Config) ->
[{escalus_user_db, xmpp} | Config];
end_per_group(change_account_details_store_plain, Config) ->
escalus_fresh:clean(),
mongoose_helper:restore_auth_config(Config),
mongoose_helper:restore_config(Config),
[{escalus_user_db, xmpp} | Config];
end_per_group(bad_cancelation, Config) ->
escalus:delete_users(Config, escalus:get_users([alice]));
Expand All @@ -121,18 +120,19 @@ end_per_group(registration_timeout, Config) ->
end_per_group(utilities, Config) ->
escalus:delete_users(Config, escalus:get_users([alice, bob]));
end_per_group(users_number_estimate, Config) ->
StoredAuthOpts = ?config(auth_opts, Config),
set_auth_opts(StoredAuthOpts);
mongoose_helper:restore_config(Config);
end_per_group(_GroupName, Config) ->
Config.

get_auth_opts() ->
rpc(mim(), ejabberd_config, get_local_option, [{auth_opts, host_type()}]).
rpc(mim(), mongoose_config, get_opt, [{auth_opts, host_type()}]).

set_auth_opts(AuthOpts) ->
set_auth_opts(Config, AuthOpts) ->
rpc(mim(), ejabberd_auth, stop, [host_type()]),
rpc(mim(), ejabberd_config, add_local_option, [{auth_opts, host_type()}, AuthOpts]),
rpc(mim(), ejabberd_auth, start, [host_type()]).
Config1 = mongoose_helper:backup_and_set_config_option(Config, {auth_opts, host_type()},
AuthOpts),
rpc(mim(), ejabberd_auth, start, [host_type()]),
Config1.

init_per_testcase(admin_notify, Config) ->
[{_, AdminSpec}] = escalus_users:get_users([admin]),
Expand All @@ -145,8 +145,8 @@ init_per_testcase(not_allowed_registration_cancelation, Config) ->
reload_mod_register_option(Config, access, {access, none}),
escalus:init_per_testcase(not_allowed_registration_cancelation, Config);
init_per_testcase(registration_failure_timeout, Config) ->
ok = deny_everyone_registration(),
escalus:init_per_testcase(registration_failure_timeout, Config);
Config1 = deny_everyone_registration(Config),
escalus:init_per_testcase(registration_failure_timeout, Config1);
init_per_testcase(CaseName, Config) when CaseName =:= list_selected_users;
CaseName =:= count_selected_users ->
case mongoose_helper:auth_modules() of
Expand Down Expand Up @@ -175,7 +175,7 @@ end_per_testcase(registration_timeout, Config) ->
escalus:delete_users(Config, escalus:get_users([alice, bob])),
escalus:end_per_testcase(registration_timeout, Config);
end_per_testcase(registration_failure_timeout, Config) ->
ok = allow_everyone_registration(),
mongoose_helper:restore_config_option(Config, {access, register, global}),
escalus:end_per_testcase(registration_failure_timeout, Config);
end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).
Expand Down Expand Up @@ -405,28 +405,14 @@ strong_pwd() ->
<<"Sup3r","c4li","fr4g1","l1571c","3xp1","4l1","d0c10u5">>.

set_registration_timeout(Config) ->
Record = {local_config, registration_timeout, ?REGISTRATION_TIMEOUT},
OldTimeout = rpc(mim(), ejabberd_config, get_local_option, [registration_timeout]),
true = rpc(mim(), ets, insert, [local_config, Record]),
[ {old_timeout, OldTimeout} | Config ].
mongoose_helper:backup_and_set_config_option(Config, registration_timeout,
?REGISTRATION_TIMEOUT).

restore_registration_timeout(Config) ->
{old_timeout, OldTimeout} = proplists:lookup(old_timeout, Config),
Record = {local_config, registration_timeout, OldTimeout},
true = rpc(mim(), ets, insert, [local_config, Record]),
proplists:delete(old_timeout, Config).

deny_everyone_registration() ->
ok = change_registration_settings_for_everyone(deny).

allow_everyone_registration() ->
ok = change_registration_settings_for_everyone(allow).

change_registration_settings_for_everyone(Rule)
when allow =:= Rule; deny =:= Rule ->
{atomic,ok} = rpc(mim(), ejabberd_config, add_global_option,
[{access, register, global}, [{Rule, all}]]),
ok.
mongoose_helper:restore_config_option(Config, registration_timeout).

deny_everyone_registration(Config) ->
mongoose_helper:backup_and_set_config_option(Config, {access, register, global}, [{deny, all}]).

has_registered_element(Stanza) ->
[#xmlel{name = <<"registered">>}] =:= exml_query:paths(Stanza,
Expand Down
18 changes: 5 additions & 13 deletions big_tests/tests/connect_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,18 @@ end_per_group(_, Config) ->
Config.

init_per_testcase(close_connection_if_service_type_is_hidden = CN, Config) ->
OptName = hide_service_name,
mongoose_helper:successful_rpc(ejabberd_config, add_local_option, [OptName, true]),
escalus:init_per_testcase(CN, Config);
Config1 = mongoose_helper:backup_and_set_config_option(Config, hide_service_name, true),
escalus:init_per_testcase(CN, Config1);
init_per_testcase(replaced_session_cannot_terminate = CN, Config) ->
S = escalus_users:get_server(Config, alice),
OptKey = {replaced_wait_timeout, S},
{atomic, _} = rpc(mim(), ejabberd_config, add_local_option, [OptKey, 1]),
escalus:init_per_testcase(CN, [{opt_to_del, OptKey} | Config]);
Config1 = mongoose_helper:backup_and_set_config_option(Config, OptKey, 1),
escalus:init_per_testcase(CN, Config1);
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,
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) ->
{_, OptKey} = lists:keyfind(opt_to_del, 1, Config),
{atomic, _} = rpc(mim(), ejabberd_config, del_local_option, [OptKey]),
escalus:end_per_testcase(CN, Config);
end_per_testcase(CaseName, Config) ->
mongoose_helper:restore_config(Config),
escalus:end_per_testcase(CaseName, Config).

%%--------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/dynamic_modules.erl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ start_running(Config) ->
stop_running(Mod, Config) ->
ModL = atom_to_list(Mod),
HostType = domain_helper:host_type(mim),
Modules = rpc(mim(), ejabberd_config, get_local_option, [{modules, HostType}]),
Modules = rpc(mim(), mongoose_config, get_opt, [{modules, HostType}]),
Filtered = lists:filter(fun({Module, _}) ->
ModuleL = atom_to_list(Module),
case lists:sublist(ModuleL, 1, length(ModL)) of
Expand Down
8 changes: 4 additions & 4 deletions big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ init_per_testcase(CN, Config) when CN =:= retrieve_inbox_muc;
Config0;

init_per_testcase(retrieve_vcard = CN, Config) ->
case vcard_update:is_vcard_ldap() of
case vcard_helper:is_vcard_ldap() of
true ->
{skip, skipped_for_simplicity_for_now}; % TODO: Fix the case for LDAP as well
_ ->
escalus:init_per_testcase(CN, Config)
end;
init_per_testcase(remove_vcard = CN, Config) ->
case vcard_update:is_vcard_ldap() of
case vcard_helper:is_vcard_ldap() of
true ->
{skip, skipped_for_simplicity_for_now}; % TODO: Fix the case for LDAP as well
_ ->
Expand Down Expand Up @@ -842,7 +842,7 @@ retrieve_mam_pm_and_muc_light_dont_interfere(Config) ->

[mam_helper:wait_for_archive_size(User, 2) || User <- [Alice, Bob]],

false = mongoose_helper:successful_rpc(mod_mam_meta, get_mam_module_opt,
false = mongoose_helper:successful_rpc(gen_mod, get_module_opt,
[host_type(), mod_mam, archive_groupchats, undefined]),

AliceDir = retrieve_all_personal_data(Alice, Config),
Expand Down Expand Up @@ -890,7 +890,7 @@ retrieve_mam_pm_and_muc_light_interfere(Config) ->
[mam_helper:wait_for_archive_size(User, 5) || User <- [Alice, Bob]],
mam_helper:wait_for_archive_size(Kate, 3),

true = mongoose_helper:successful_rpc(mod_mam_meta, get_mam_module_opt,
true = mongoose_helper:successful_rpc(gen_mod, get_module_opt,
[host_type(), mod_mam, archive_groupchats, undefined]),

AliceDir = retrieve_all_personal_data(Alice, Config),
Expand Down
101 changes: 52 additions & 49 deletions big_tests/tests/login_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -113,70 +113,82 @@ suite() ->
%%--------------------------------------------------------------------

init_per_suite(Config) ->
Config0 = mongoose_helper:backup_auth_config(Config),
Config1 = mongoose_helper:backup_sasl_mechanisms_config(Config0),
mongoose_helper:set_store_password(scram),
escalus:init_per_suite(Config1).
escalus:init_per_suite(Config).

end_per_suite(Config) ->
escalus_fresh:clean(),
mongoose_helper:restore_auth_config(Config),
mongoose_helper:restore_sasl_mechanisms_config(Config),
escalus:end_per_suite(Config).

init_per_group(login_digest, ConfigIn) ->
Config = mongoose_helper:backup_sasl_mechanisms_config(ConfigIn),
mongoose_helper:set_store_password(plain),
init_per_group(login_digest = GroupName, ConfigIn) ->
Config = backup_and_set_options(GroupName, ConfigIn),
case mongoose_helper:supports_sasl_module(cyrsasl_digest) of
false ->
mongoose_helper:set_store_password(scram),
mongoose_helper:restore_config(Config),
{skip, "digest password type not supported"};
true ->
Config1 = configure_digest(Config),
escalus:create_users(Config1, escalus:get_users([alice, bob]))
escalus:create_users(Config, escalus:get_users([alice, bob]))
end;
init_per_group(GroupName, Config) when
GroupName == login_scram; GroupName == login_scram_store_plain ->
init_per_group(GroupName, ConfigIn)
when GroupName == login_scram;
GroupName == login_scram_store_plain ->
Config = backup_and_set_options(GroupName, ConfigIn),
case are_sasl_scram_modules_supported() of
false ->
mongoose_helper:restore_config(Config),
{skip, "scram password type not supported"};
true ->
config_password_format(GroupName),
Config2 = escalus:create_users(Config, escalus:get_users([alice, bob, neustradamus])),
assert_password_format(GroupName, Config2)
end;
init_per_group(login_scram_tls, Config) ->
init_per_group(login_scram_tls = GroupName, ConfigIn) ->
Config = backup_and_set_options(GroupName, ConfigIn),
case are_sasl_scram_modules_supported() of
false ->
mongoose_helper:restore_config(Config),
{skip, "scram password type not supported"};
true ->
Config1 = config_ejabberd_node_tls(Config),
config_password_format(login_scram_tls),
Config2 = create_tls_users(Config1),
assert_password_format(scram, Config2)
end;
init_per_group(login_specific_scram, Config) ->
init_per_group(login_specific_scram = GroupName, ConfigIn) ->
Config = backup_and_set_options(GroupName, ConfigIn),
case are_sasl_scram_modules_supported() of
false ->
mongoose_helper:restore_config(Config),
{skip, "scram password type not supported"};
true ->
escalus:create_users(Config, escalus:get_users([alice, bob, neustradamus]))
end;
init_per_group(_GroupName, Config) ->
init_per_group(GroupName, ConfigIn) ->
Config = backup_and_set_options(GroupName, ConfigIn),
escalus:create_users(Config, escalus:get_users([alice, bob])).

backup_and_set_options(GroupName, Config) ->
Options = config_options(GroupName),
mongoose_helper:backup_and_set_config(Config, Options).

config_options(login_digest) ->
#{{auth_opts, host_type()} => mongoose_helper:auth_opts_with_password_format(plain),
{sasl_mechanisms, host_type()} => [cyrsasl_digest]};
config_options(login_scram_store_plain) ->
#{{auth_opts, host_type()} => mongoose_helper:auth_opts_with_password_format(plain)};
config_options(_GroupName) ->
#{{auth_opts, host_type()} => mongoose_helper:auth_opts_with_password_format(scram)}.

end_per_group(login_digest, Config) ->
mongoose_helper:set_store_password(scram),
mongoose_helper:restore_sasl_mechanisms_config(Config),
mongoose_helper:restore_config(Config),
escalus:delete_users(Config, escalus:get_users([alice, bob]));
end_per_group(GroupName, Config) when
GroupName == login_scram; GroupName == login_specific_scram ->
mongoose_helper:set_store_password(scram),
mongoose_helper:restore_config(Config),
escalus:delete_users(Config, escalus:get_users([alice, bob, neustradamus]));
end_per_group(login_scram_tls, Config) ->
mongoose_helper:restore_config(Config),
restore_c2s(Config),
delete_tls_users(Config);
end_per_group(_GroupName, Config) ->
mongoose_helper:restore_config(Config),
escalus:delete_users(Config, escalus:get_users([alice, bob])).

init_per_testcase(CaseName, Config) when
Expand All @@ -189,7 +201,7 @@ init_per_testcase(CaseName, Config) when
end;
init_per_testcase(message_zlib_limit, Config) ->
Listeners = [Listener
|| {Listener, _, _} <- rpc(mim(), ejabberd_config, get_local_option, [listen])],
|| {Listener, _, _} <- rpc(mim(), mongoose_config, get_opt, [listen])],
[{_U, Props}] = escalus_users:get_users([hacker]),
Port = proplists:get_value(port, Props),
case lists:keymember(Port, 1, Listeners) of
Expand Down Expand Up @@ -346,17 +358,17 @@ log_non_existent(Config) ->
{error, {connection_step_failed, _, R}} = escalus_client:start(Config, UserSpec, <<"res">>),
R.

blocked_user(_Config) ->
blocked_user(Config) ->
[{_, Spec}] = escalus_users:get_users([alice]),
set_acl_for_blocking(Spec),
Config1 = set_acl_for_blocking(Config, Spec),
try
{ok, _Alice, _Spec2, _Features} = escalus_connection:start(Spec),
ct:fail("Alice authenticated but shouldn't")
catch
error:{assertion_failed, assert, is_iq_result, Stanza, _Bin} ->
<<"cancel">> = exml_query:path(Stanza, [{element, <<"error">>}, {attr, <<"type">>}])
after
unset_acl_for_blocking()
unset_acl_for_blocking(Config1)
end,
ok.

Expand Down Expand Up @@ -398,11 +410,6 @@ config_ejabberd_node_tls(Config) ->
mongoose_helper:restart_listener_with_opts(mim(), C2SListener, NewOpts),
[{c2s_listener, C2SListener} | Config].

configure_digest(Config) ->
mongoose_helper:set_sasl_mechanisms(sasl_mechanisms, [cyrsasl_digest]),
mongoose_helper:set_store_password(plain),
Config.

create_tls_users(Config) ->
Config1 = escalus:create_users(Config, escalus:get_users([alice, neustradamus])),
Users = proplists:get_value(escalus_users, Config1, []),
Expand All @@ -417,11 +424,6 @@ create_tls_users(Config) ->
delete_tls_users(Config) ->
escalus:delete_users(Config, escalus:get_users([alice, neustradamus])).

config_password_format(GN) when GN == login_scram; GN == login_scram_tls ->
mongoose_helper:set_store_password(scram);
config_password_format(_) ->
mongoose_helper:set_store_password(plain).

assert_password_format(GroupName, Config) ->
Users = proplists:get_value(escalus_users, Config),
[verify_format(GroupName, User) || User <- Users],
Expand Down Expand Up @@ -452,35 +454,36 @@ do_verify_format(login_scram, _Password, SPassword) ->
do_verify_format(_, Password, SPassword) ->
Password = SPassword.

set_acl_for_blocking(Spec) ->
set_acl_for_blocking(Config, Spec) ->
User = proplists:get_value(username, Spec),
LUser = jid:nodeprep(User),
rpc(mim(), ejabberd_config, add_global_option, [{acl, blocked, host_type()}, [{user, LUser}]]).
mongoose_helper:backup_and_set_config_option(Config, {acl, blocked, host_type()},
[{user, LUser}]).

unset_acl_for_blocking() ->
%% There is no del_global_option
rpc(mim(), mnesia, dirty_delete, [config, {acl, blocked, host_type()}]).
unset_acl_for_blocking(Config) ->
mongoose_helper:restore_config_option(Config, {acl, blocked, host_type()}).

configure_and_log_scram(Config, Sha, Mech) ->
mongoose_helper:set_store_password({scram, [Sha]}),
assert_password_format({scram, Sha}, Config),
set_scram_sha(Config, Sha),
log_one([{escalus_auth_method, Mech} | Config]).

configure_and_log_scram_plus(Config, Sha, Mech) ->
mongoose_helper:set_store_password({scram, [Sha]}),
assert_password_format({scram, Sha}, Config),
set_scram_sha(Config, Sha),
log_one_scram_plus([{escalus_auth_method, Mech} | Config]).

configure_and_fail_log_scram(Config, Sha, Mech) ->
mongoose_helper:set_store_password({scram, [Sha]}),
assert_password_format({scram, Sha}, Config),
set_scram_sha(Config, Sha),
{expected_challenge, _, _} = fail_log_one([{escalus_auth_method, Mech} | Config]).

configure_scram_plus_and_fail_log_scram(Config, Sha, Mech) ->
mongoose_helper:set_store_password({scram, [Sha]}),
assert_password_format({scram, Sha}, Config),
set_scram_sha(Config, Sha),
{expected_challenge, _, _} = fail_log_one_scram_plus([{escalus_auth_method, Mech} | Config]).

set_scram_sha(Config, Sha) ->
NewAuthOpts = mongoose_helper:auth_opts_with_password_format({scram, [Sha]}),
mongoose_helper:change_config_option(Config, {auth_opts, host_type()}, NewAuthOpts),
assert_password_format({scram, Sha}, Config).

fail_log_one(Config) ->
[{alice, UserSpec}] = escalus_users:get_users([alice]),
{error, {connection_step_failed, _, R}} = escalus_client:start(Config, UserSpec, <<"res">>),
Expand Down

0 comments on commit 1728c31

Please sign in to comment.