Skip to content

Commit

Permalink
Update big tests with the new listener config format
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Jan 12, 2022
1 parent 183a787 commit 2e93602
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 41 deletions.
34 changes: 15 additions & 19 deletions big_tests/tests/connect_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ suite() ->
init_per_suite(Config) ->
Config0 = escalus:init_per_suite([{escalus_user_db, {module, escalus_ejabberd, []}} | Config]),
C2SPort = ct:get_config({hosts, mim, c2s_port}),
[{_, ejabberd_c2s, _} = C2SListener] = mongoose_helper:get_listener_opts(mim(), C2SPort),
[C2SListener] = mongoose_helper:get_listeners(mim(), #{port => C2SPort, module => ejabberd_c2s}),
Config1 = [{c2s_listener, C2SListener} | Config0],
assert_cert_file_exists(),
escalus:create_users(Config1, escalus:get_users([?SECURE_USER, alice])).
Expand All @@ -148,32 +148,33 @@ end_per_suite(Config) ->
escalus:end_per_suite(Config).

init_per_group(c2s_noproc, Config) ->
config_ejabberd_node_c2s(Config, [starttls]),
configure_c2s_listener(Config, #{tls => [starttls | common_tls_opts(Config)]}),
Config;
init_per_group(session_replacement, Config) ->
config_ejabberd_node_c2s(Config, [starttls]),
configure_c2s_listener(Config, #{tls => [starttls | common_tls_opts(Config)]}),
logger_ct_backend:start(),
Config;
init_per_group(starttls, Config) ->
config_ejabberd_node_c2s(Config, [starttls_required]),
configure_c2s_listener(Config, #{tls => [starttls_required | common_tls_opts(Config)]}),
Config;
init_per_group(tls, Config) ->
config_ejabberd_node_c2s(Config, [tls]),
configure_c2s_listener(Config, #{tls => [tls | common_tls_opts(Config)]}),
Users = proplists:get_value(escalus_users, Config, []),
JoeSpec = lists:keydelete(starttls, 1, proplists:get_value(?SECURE_USER, Users)),
JoeSpec2 = {?SECURE_USER, lists:keystore(ssl, 1, JoeSpec, {ssl, true})},
NewUsers = lists:keystore(?SECURE_USER, 1, Users, JoeSpec2),
Config2 = lists:keystore(escalus_users, 1, Config, {escalus_users, NewUsers}),
[{c2s_port, ct:get_config({hosts, mim, c2s_port})} | Config2];
init_per_group(feature_order, Config) ->
config_ejabberd_node_c2s(Config, [starttls_required, {zlib, 10000}]),
configure_c2s_listener(Config, #{zlib => 100000,
tls => [starttls_required | common_tls_opts(Config)]}),
Config;
init_per_group(just_tls,Config)->
[{tls_module, just_tls} | Config];
init_per_group(fast_tls,Config)->
[{tls_module, fast_tls} | Config];
init_per_group(proxy_protocol, Config) ->
config_ejabberd_node_c2s(Config, [{proxy_protocol, true}]),
configure_c2s_listener(Config, #{proxy_protocol => true}),
Config;
init_per_group(_, Config) ->
Config.
Expand Down Expand Up @@ -751,28 +752,23 @@ openssl_client_can_use_cipher(Cipher, Port) ->
0 == string:str(Output, ":error:") andalso 0 == string:str(Output, "errno=0").

restore_c2s_listener(Config) ->
{_, _, Opts} = C2SListener = ?config(c2s_listener, Config),
mongoose_helper:restart_listener_with_opts(mim(), C2SListener, Opts).
C2SListener = ?config(c2s_listener, Config),
mongoose_helper:restart_listener(mim(), C2SListener).

assert_cert_file_exists() ->
ejabberd_node_utils:file_exists(?CERT_FILE) orelse
ct:fail("cert file ~s not exists", [?CERT_FILE]).

config_ejabberd_node_c2s(Config, ExtraC2SOpts) ->
Opts = ExtraC2SOpts ++ common_c2s_opts(Config),
configure_c2s_listener(Config, ExtraC2SOpts) ->
C2SListener = ?config(c2s_listener, Config),
mongoose_helper:restart_listener_with_opts(mim(), C2SListener, Opts).
NewC2SListener = maps:merge(C2SListener, ExtraC2SOpts),
mongoose_helper:restart_listener(mim(), NewC2SListener).

common_c2s_opts(Config) ->
common_tls_opts(Config) ->
TLSModule = ?config(tls_module, Config),
[{tls_module, TLSModule},
{certfile, ?CERT_FILE},
%starttls,
%{zlib, 10000},
{access, c2s},
{shaper, c2s_shaper},
{max_stanza_size, 65536},
{dhfile, "priv/ssl/fake_dh_server.pem"}].
{dhfile, ?DH_FILE}].

set_secure_connection_protocol(UserSpec, Version) ->
[{ssl_opts, [{versions, [Version]}]} | UserSpec].
Expand Down
24 changes: 8 additions & 16 deletions big_tests/tests/login_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
-module(login_SUITE).
-compile([export_all, nowarn_export_all]).

-include_lib("escalus/include/escalus.hrl").
-include_lib("escalus/include/escalus_xmlns.hrl").

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

-include_lib("exml/include/exml.hrl").

-import(distributed_helper, [mim/0,
Expand All @@ -35,9 +29,6 @@
%% Suite configuration
%%--------------------------------------------------------------------

-define(REGISTRATION_TIMEOUT, 2). %% seconds
-define(CERT_FILE, "priv/ssl/fake_server.pem").

all() ->
[
{group, login},
Expand Down Expand Up @@ -147,7 +138,7 @@ init_per_group(login_scram_tls = GroupName, ConfigIn) ->
mongoose_helper:restore_config(Config),
{skip, "scram password type not supported"};
true ->
Config1 = config_ejabberd_node_tls(Config),
Config1 = configure_c2s_listener(Config),
Config2 = create_tls_users(Config1),
assert_password_format(scram, Config2)
end;
Expand Down Expand Up @@ -401,12 +392,13 @@ message_zlib_limit(Config) ->
%% Helpers
%%--------------------------------------------------------------------

config_ejabberd_node_tls(Config) ->
configure_c2s_listener(Config) ->
C2SPort = ct:get_config({hosts, mim, c2s_port}),
[{_, ejabberd_c2s, Opts} = C2SListener] = mongoose_helper:get_listener_opts(mim(), C2SPort),
[C2SListener = #{tls := TLSOpts}] =
mongoose_helper:get_listeners(mim(), #{port => C2SPort, module => ejabberd_c2s}),
%% replace starttls with tls
NewOpts = [tls | Opts -- [starttls]],
mongoose_helper:restart_listener_with_opts(mim(), C2SListener, NewOpts),
NewTLSOpts = [tls | TLSOpts -- [starttls]],
mongoose_helper:restart_listener(mim(), C2SListener#{tls := NewTLSOpts}),
[{c2s_listener, C2SListener} | Config].

create_tls_users(Config) ->
Expand Down Expand Up @@ -500,5 +492,5 @@ are_sasl_scram_modules_supported() ->
[true, true, true, true, true] == IsSupported.

restore_c2s(Config) ->
{_, _, Opts} = C2SListener = proplists:get_value(c2s_listener, Config),
mongoose_helper:restart_listener_with_opts(mim(), C2SListener, Opts).
C2SListener = proplists:get_value(c2s_listener, Config),
mongoose_helper:restart_listener(mim(), C2SListener).
11 changes: 5 additions & 6 deletions big_tests/tests/service_domain_db_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
patch_custom/4]).

-import(domain_rest_helper,
[start_listener/0,
start_listener/1,
stop_listener/0]).
[start_listener/1,
stop_listener/1]).

-import(domain_helper, [domain/0]).

Expand Down Expand Up @@ -218,7 +217,7 @@ init_per_group(db, Config) ->
false -> {skip, require_rdbms}
end;
init_per_group(rest_with_auth, Config) ->
start_listener(),
start_listener(#{}),
[{auth_creds, valid}|Config];
init_per_group(rest_without_auth, Config) ->
start_listener(#{skip_auth => true}),
Expand All @@ -232,9 +231,9 @@ init_per_group(GroupName, Config) ->
Config1.

end_per_group(rest_with_auth, _Config) ->
stop_listener();
stop_listener(#{});
end_per_group(rest_without_auth, _Config) ->
stop_listener();
stop_listener(#{skip_auth => true});
end_per_group(_GroupName, Config) ->
case ?config(service_setup, Config) of
per_group -> teardown_service();
Expand Down

0 comments on commit 2e93602

Please sign in to comment.