Skip to content

Commit

Permalink
Adapt vcard_simple_SUITE for dynamic domains
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Aug 20, 2021
1 parent 493644d commit 0246e1b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
16 changes: 8 additions & 8 deletions big_tests/tests/vcard_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ init_per_group(Group, Config) when Group == rw; Group == params_limited_infinity
Config
end;
init_per_group(ldap_only, Config) ->
VCardConfig = ?config(mod_vcard, Config),
VCardConfig = ?config(mod_vcard_opts, Config),
case proplists:get_value(backend, VCardConfig) of
ldap ->
Config1 = restart_and_prepare_vcard(ldap_only, Config),
Expand Down Expand Up @@ -1013,7 +1013,7 @@ prepare_vcards(Config) ->
Config.

get_backend(Config) ->
case lists:keyfind(backend, 1, ?config(mod_vcard, Config)) of
case lists:keyfind(backend, 1, ?config(mod_vcard_opts, Config)) of
{backend, Backend} ->
Backend;
_ ->
Expand Down Expand Up @@ -1154,7 +1154,7 @@ prepare_vcard_module(Config) ->
%% Keep the old config, so we can undo our changes, once finished testing
Config1 = dynamic_modules:save_modules_for_host_types(host_types(), Config),
%% Get a list of options, we can use as a prototype to start new modules
[{mod_vcard, get_vcard_config(Config)} | Config1].
[{mod_vcard_opts, get_vcard_config(Config)} | Config1].

restore_vcard_module(Config) ->
dynamic_modules:restore_modules(Config).
Expand All @@ -1175,22 +1175,22 @@ stop_vcard_mod(_Config) ->
dynamic_modules:stop(SecHostType, mod_vcard).

params_all(Config) ->
add_backend_param([], ?config(mod_vcard, Config)).
add_backend_param([], ?config(mod_vcard_opts, Config)).

params_limited(Config) ->
add_backend_param([{matches, 1},
{host, subhost_pattern("directory.@HOST@")}],
?config(mod_vcard, Config)).
?config(mod_vcard_opts, Config)).

params_limited_infinity(Config) ->
add_backend_param([{matches, infinity},
{host, subhost_pattern("directory.@HOST@")}],
?config(mod_vcard, Config)).
?config(mod_vcard_opts, Config)).

params_no(Config) ->
add_backend_param([{search, false},
{host, subhost_pattern("vjud.@HOST@")}],
?config(mod_vcard, Config)).
?config(mod_vcard_opts, Config)).

params_ldap_only(Config) ->
Reported = [{<<"Full Name">>, <<"FN">>},
Expand All @@ -1208,7 +1208,7 @@ params_ldap_only(Config) ->
add_backend_param([{ldap_search_operator, 'or'},
{ldap_binary_search_fields, [<<"PHOTO">>]},
{ldap_search_reported, Reported}],
?config(mod_vcard, Config)).
?config(mod_vcard_opts, Config)).

add_backend_param(Opts, CurrentVCardConfig) ->
F = fun({Key, _} = Item, Cfg) ->
Expand Down
75 changes: 42 additions & 33 deletions big_tests/tests/vcard_simple_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,13 @@ suite() ->
%%--------------------------------------------------------------------

init_per_suite(Config) ->
NewConfig0 = escalus:init_per_suite(Config),
NewConfig = case is_vcard_ldap() of
true ->
configure_ldap_vcards(NewConfig0);
_ ->
NewConfig0
end,
escalus:create_users(NewConfig, escalus:get_users([alice, bob])).
Config1 = prepare_vcard_module(escalus:init_per_suite(Config)),
configure_mod_vcard(Config1),
escalus:create_users(Config1, escalus:get_users([alice, bob])).

end_per_suite(Config) ->
NewConfig = escalus:delete_users(Config, escalus:get_users([alice, bob])),
case is_vcard_ldap() of
true ->
restore_ldap_vcards_config(Config);
_ ->
ok
end,
restore_vcard_module(NewConfig),
escalus:end_per_suite(NewConfig).

init_per_group(_GN, Config) ->
Expand Down Expand Up @@ -451,22 +441,41 @@ get_FN(Config) ->
<<"Old Name">>
end.

configure_ldap_vcards(Config) ->
Domain = ct:get_config({hosts, mim, domain}),
CurrentConfigs = rpc(mim(), gen_mod, loaded_modules_with_opts, [Domain]),
{mod_vcard, CurrentVcardConfig} = lists:keyfind(mod_vcard, 1, CurrentConfigs),
dynamic_modules:stop(Domain, mod_vcard),
Cfg = [{backend,ldap}, {host, subhost_pattern("vjud.@HOST@")},
{ldap_uids, [{<<"uid">>}]}, %% equivalent to {<<"uid">>, <<"%u">>}
{ldap_filter,"(objectClass=inetOrgPerson)"},
{ldap_base,"ou=Users,dc=esl,dc=com"},
{ldap_search_fields, [{"Full Name","cn"},{"User","uid"}]},
{ldap_vcard_map,[{"FN","%s",["cn"]}]}],
dynamic_modules:start(Domain, mod_vcard, Cfg),
[{mod_vcard, CurrentVcardConfig} | Config].

restore_ldap_vcards_config(Config) ->
OriginalConfig = ?config(mod_vcard, Config),
Domain = ct:get_config({hosts, mim, domain}),
dynamic_modules:stop(Domain, mod_vcard),
dynamic_modules:start(Domain, mod_vcard, OriginalConfig).
configure_mod_vcard(Config) ->
HostType = ct:get_config({hosts, mim, host_type}),
case is_vcard_ldap() of
true ->
ensure_started(HostType, ldap_opts());
_ ->
ensure_started(HostType, ?config(mod_vcard_opts, Config))
end.

ldap_opts() ->
[{backend,ldap}, {host, subhost_pattern("vjud.@HOST@")},
{ldap_uids, [{<<"uid">>}]}, %% equivalent to {<<"uid">>, <<"%u">>}
{ldap_filter,"(objectClass=inetOrgPerson)"},
{ldap_base,"ou=Users,dc=esl,dc=com"},
{ldap_search_fields, [{"Full Name","cn"},{"User","uid"}]},
{ldap_vcard_map,[{"FN","%s",["cn"]}]}].

ensure_started(HostType, Opts) ->
dynamic_modules:stop(HostType, mod_vcard),
dynamic_modules:start(HostType, mod_vcard, Opts).

get_vcard_config(Config) ->
CfgHost = ct:get_config({hosts, mim, configured_host_type}),
rpc(mim(), gen_mod, get_loaded_module_opts, [CfgHost, mod_vcard]).

prepare_vcard_module(Config) ->
%% Keep the old config, so we can undo our changes, once finished testing
Config1 = dynamic_modules:save_modules_for_host_types(host_types(), Config),
%% Get a list of options, we can use as a prototype to start new modules
[{mod_vcard_opts, get_vcard_config(Config)} | Config1].

host_types() ->
HostType = ct:get_config({hosts, mim, host_type}),
SecHostType = ct:get_config({hosts, mim, secondary_host_type}),
lists:usort([HostType, SecHostType]).

restore_vcard_module(Config) ->
dynamic_modules:restore_modules(Config).

0 comments on commit 0246e1b

Please sign in to comment.