Skip to content

Commit

Permalink
Update tests with the new s2s maps
Browse files Browse the repository at this point in the history
Expect the new defaults for global options o be always present
  • Loading branch information
chrzaszcz committed Jan 26, 2022
1 parent dd2e8c4 commit 26cf20d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
26 changes: 15 additions & 11 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1431,27 +1431,32 @@ access_merge_host_and_global(_Config) ->
%% tests: s2s

s2s_dns_timeout(_Config) ->
?cfg(s2s_dns_options, [{timeout, 5}], #{<<"s2s">> => #{<<"dns">> => #{<<"timeout">> => 5}}}),
?cfg([s2s_dns, timeout], 10, #{}), % default
?cfg([s2s_dns, timeout], 5, #{<<"s2s">> => #{<<"dns">> => #{<<"timeout">> => 5}}}),
?err(#{<<"s2s">> => #{<<"dns">> => #{<<"timeout">> => 0}}}).

s2s_dns_retries(_Config) ->
?cfg(s2s_dns_options, [{retries, 1}], #{<<"s2s">> => #{<<"dns">> => #{<<"retries">> => 1}}}),
?cfg([s2s_dns, retries], 2, #{}), % default
?cfg([s2s_dns, retries], 1, #{<<"s2s">> => #{<<"dns">> => #{<<"retries">> => 1}}}),
?err(#{<<"s2s">> => #{<<"dns">> => #{<<"retries">> => 0}}}).

s2s_outgoing_port(_Config) ->
?cfg(outgoing_s2s_port, 5270, #{<<"s2s">> => #{<<"outgoing">> => #{<<"port">> => 5270}}}),
?cfg([s2s_outgoing, port], 5269, #{}), % default
?cfg([s2s_outgoing, port], 5270, #{<<"s2s">> => #{<<"outgoing">> => #{<<"port">> => 5270}}}),
?err(#{<<"s2s">> => #{<<"outgoing">> => #{<<"port">> => <<"http">>}}}).

s2s_outgoing_ip_versions(_Config) ->
?cfg(outgoing_s2s_families, [ipv6, ipv4],
?cfg([s2s_outgoing, ip_versions], [4, 6], #{}), % default
?cfg([s2s_outgoing, ip_versions], [6, 4],
#{<<"s2s">> => #{<<"outgoing">> => #{<<"ip_versions">> => [6, 4]}}}),
?err(#{<<"s2s">> => #{<<"outgoing">> => #{<<"ip_versions">> => []}}}),
?err(#{<<"s2s">> => #{<<"outgoing">> => #{<<"ip_versions">> => [<<"http">>]}}}).

s2s_outgoing_timeout(_Config) ->
?cfg(outgoing_s2s_timeout, 5,
#{<<"s2s">> => #{<<"outgoing">> => #{<<"connection_timeout">> => 5}}}),
?cfg(outgoing_s2s_timeout, infinity,
?cfg([s2s_outgoing, connection_timeout], 10000, #{}), % default
?cfg([s2s_outgoing, connection_timeout], 5000,
#{<<"s2s">> => #{<<"outgoing">> => #{<<"connection_timeout">> => 5000}}}),
?cfg([s2s_outgoing, connection_timeout], infinity,
#{<<"s2s">> => #{<<"outgoing">> => #{<<"connection_timeout">> => <<"infinity">>}}}),
?err(#{<<"s2s">> => #{<<"outgoing">> => #{<<"connection_timeout">> => 0}}}).

Expand Down Expand Up @@ -1487,9 +1492,10 @@ s2s_address(_Config) ->
Addr = #{<<"host">> => <<"host1">>,
<<"ip_address">> => <<"192.168.1.2">>,
<<"port">> => 5321},
?cfg(s2s_address, #{<<"host1">> => {"192.168.1.2", 5321}},
?cfg(s2s_address, #{}, #{}),% default
?cfg(s2s_address, #{<<"host1">> => #{ip_address => "192.168.1.2", port => 5321}},
#{<<"s2s">> => #{<<"address">> => [Addr]}}),
?cfg(s2s_address, #{<<"host1">> => "192.168.1.2"},
?cfg(s2s_address, #{<<"host1">> => #{ip_address => "192.168.1.2"}},
#{<<"s2s">> => #{<<"address">> => [maps:without([<<"port">>], Addr)]}}),
?err(#{<<"s2s">> => #{<<"address">> => [maps:without([<<"host">>], Addr)]}}),
?err(#{<<"s2s">> => #{<<"address">> => [maps:without([<<"ip_address">>], Addr)]}}),
Expand Down Expand Up @@ -3218,8 +3224,6 @@ compare_nodes([{auth_method, _}], V1, V2) when is_atom(V1) ->
?eq([V1], V2);
compare_nodes([{s2s_addr, _}], {_, _, _, _} = IP1, IP2) ->
?eq(inet:ntoa(IP1), IP2);
compare_nodes([s2s_dns_options], V1, V2) ->
compare_unordered_lists(V1, V2);
compare_nodes([{modules, _}, mod_extdisco], V1, V2) ->
compare_ordered_lists(V1, V2, fun compare_unordered_lists/2);
compare_nodes([{modules, _}, _Module], V1, V2) ->
Expand Down
4 changes: 2 additions & 2 deletions test/config_parser_SUITE_data/s2s_only.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
default_policy = "allow"
ciphers = "TLSv1.2:TLSv1.3"
outgoing.port = 5299
outgoing.connection_timeout = 10000
outgoing.ip_versions = [4, 6]
outgoing.connection_timeout = 4_000
outgoing.ip_versions = [6, 4]
dns.timeout = 30
dns.retries = 1
shared = "shared secret"
Expand Down
38 changes: 30 additions & 8 deletions test/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ options("host_types") ->
{registration_timeout, 600},
{routing_modules, mongoose_router:default_routing_modules()},
{sm_backend, {mnesia, []}},
{s2s_address, #{}},
{s2s_dns, default_s2s_dns()},
{s2s_outgoing, default_s2s_outgoing()},
{{auth, <<"another host type">>}, auth_with_methods(#{})},
{{auth, <<"localhost">>},
auth_with_methods(#{rdbms => #{users_number_estimate => false}})},
Expand Down Expand Up @@ -79,6 +82,9 @@ options("miscellaneous") ->
{periodic_report, 10800000},
report,
{tracking_id, "UA-123456789"}]}]},
{s2s_address, #{}},
{s2s_dns, default_s2s_dns()},
{s2s_outgoing, default_s2s_outgoing()},
{sm_backend, {mnesia, []}},
{{auth, <<"anonymous.localhost">>}, custom_auth()},
{{auth, <<"localhost">>}, custom_auth()},
Expand All @@ -101,6 +107,9 @@ options("modules") ->
{rdbms_server_type, generic},
{registration_timeout, 600},
{routing_modules, mongoose_router:default_routing_modules()},
{s2s_address, #{}},
{s2s_dns, default_s2s_dns()},
{s2s_outgoing, default_s2s_outgoing()},
{sm_backend, {mnesia, []}},
{{auth, <<"dummy_host">>}, default_auth()},
{{auth, <<"localhost">>}, default_auth()},
Expand Down Expand Up @@ -229,11 +238,13 @@ options("mongooseim-pgsql") ->
{server_name_indication, disable},
{verify, verify_peer}]}]}}]},
{redis, <<"localhost">>, global_distrib, [{workers, 10}], []}]},
{outgoing_s2s_port, 5299},
{rdbms_server_type, generic},
{registration_timeout, infinity},
{routing_modules, mongoose_router:default_routing_modules()},
{s2s_address, #{<<"fed1">> => #{ip_address => "127.0.0.1"}}},
{s2s_certfile, "tools/ssl/mongooseim/server.pem"},
{s2s_dns, default_s2s_dns()},
{s2s_outgoing, (default_s2s_outgoing())#{port => 5299}},
{s2s_use_starttls, optional},
{services,
[{service_admin_extra,
Expand Down Expand Up @@ -265,7 +276,6 @@ options("mongooseim-pgsql") ->
{{replaced_wait_timeout, <<"anonymous.localhost">>}, 2000},
{{replaced_wait_timeout, <<"localhost">>}, 2000},
{{replaced_wait_timeout, <<"localhost.bis">>}, 2000},
{s2s_address, #{<<"fed1">> => "127.0.0.1"}},
{{s2s_default_policy, <<"anonymous.localhost">>}, allow},
{{s2s_default_policy, <<"localhost">>}, allow},
{{s2s_default_policy, <<"localhost.bis">>}, allow},
Expand Down Expand Up @@ -345,6 +355,9 @@ options("outgoing_pools") ->
{rdbms_server_type, generic},
{registration_timeout, 600},
{routing_modules, mongoose_router:default_routing_modules()},
{s2s_address, #{}},
{s2s_dns, default_s2s_dns()},
{s2s_outgoing, default_s2s_outgoing()},
{sm_backend, {mnesia, []}},
{{auth, <<"anonymous.localhost">>}, default_auth()},
{{auth, <<"localhost">>}, default_auth()},
Expand All @@ -365,15 +378,11 @@ options("s2s_only") ->
{listen, []},
{loglevel, warning},
{mongooseimctl_access_commands, []},
{outgoing_s2s_families, [ipv4, ipv6]},
{outgoing_s2s_port, 5299},
{outgoing_s2s_timeout, 10000},
{rdbms_server_type, generic},
{registration_timeout, 600},
{routing_modules, mongoose_router:default_routing_modules()},
{s2s_certfile, "tools/ssl/mongooseim/server.pem"},
{s2s_ciphers, "TLSv1.2:TLSv1.3"},
{s2s_dns_options, [{retries, 1}, {timeout, 30}]},
{s2s_use_starttls, optional},
{sm_backend, {mnesia, []}},
{{auth, <<"dummy_host">>}, default_auth()},
Expand All @@ -382,8 +391,12 @@ options("s2s_only") ->
{{modules, <<"localhost">>}, #{}},
{{replaced_wait_timeout, <<"dummy_host">>}, 2000},
{{replaced_wait_timeout, <<"localhost">>}, 2000},
{s2s_address, #{<<"fed1">> => "127.0.0.1",
<<"fed2">> => {"127.0.0.1", 8765}}},
{s2s_address, #{<<"fed1">> => #{ip_address => "127.0.0.1"},
<<"fed2">> => #{ip_address => "127.0.0.1", port => 8765}}},
{s2s_dns, #{retries => 1, timeout => 30}},
{s2s_outgoing, #{connection_timeout => 4000,
ip_versions => [6, 4],
port => 5299}},
{{s2s_default_policy, <<"dummy_host">>}, allow},
{{s2s_default_policy, <<"localhost">>}, allow},
{{s2s_max_retry_delay, <<"dummy_host">>}, 30},
Expand Down Expand Up @@ -705,6 +718,15 @@ default_auth() ->
sasl_external => [standard],
sasl_mechanisms => cyrsasl:default_modules()}.

default_s2s_dns() ->
#{retries => 2,
timeout => 10}.

default_s2s_outgoing() ->
#{connection_timeout => 10000,
ip_versions => [4, 6],
port => 5269}.

pgsql_access() ->
#{c2s => [#{acl => blocked, value => deny},
#{acl => all, value => allow}],
Expand Down
3 changes: 3 additions & 0 deletions test/mongoose_config_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ minimal_config_opts() ->
{rdbms_server_type, generic},
{registration_timeout, 600},
{routing_modules, mongoose_router:default_routing_modules()},
{s2s_address, #{}},
{s2s_dns, config_parser_helper:default_s2s_dns()},
{s2s_outgoing, config_parser_helper:default_s2s_outgoing()},
{sm_backend, {mnesia, []}},
{{auth, <<"localhost">>}, config_parser_helper:default_auth()},
{{modules, <<"localhost">>}, #{}},
Expand Down

0 comments on commit 26cf20d

Please sign in to comment.