Skip to content

Commit

Permalink
[ct] prepare for IPv6 support
Browse files Browse the repository at this point in the history
Fully prepare client suite for full IPv6 support and add some minor
tweaks to the others to move them closer to IPv6 support.
  • Loading branch information
RoadRunnr committed May 6, 2024
1 parent 09a861e commit 349282c
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 152 deletions.
202 changes: 132 additions & 70 deletions test/eradius_client_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,65 +1,81 @@
%% Copyright (c) 2010-2017 by Travelping GmbH <[email protected]>

%% Permission is hereby granted, free of charge, to any person obtaining a
%% copy of this software and associated documentation files (the "Software"),
%% to deal in the Software without restriction, including without limitation
%% the rights to use, copy, modify, merge, publish, distribute, sublicense,
%% and/or sell copies of the Software, and to permit persons to whom the
%% Software is furnished to do so, subject to the following conditions:

%% The above copyright notice and this permission notice shall be included in
%% all copies or substantial portions of the Software.

%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
%% DEALINGS IN THE SOFTWARE.

%% Copyright (c) 2010-2017, Travelping GmbH <[email protected]>
%%
%% SPDX-License-Identifier: MIT
%%
-module(eradius_client_SUITE).
-compile(export_all).

-compile([export_all, nowarn_export_all]).

-behaviour(ct_suite).

-include("test/eradius_test.hrl").

%%%===================================================================
%%% Defines
%%%===================================================================

-define(HUT_SOCKET, eradius_client_socket).

-define(BAD_SERVER_IP, {eradius_test_handler:localhost(ip), 1820, "secret"}).
-define(BAD_SERVER_IP(Family),
{eradius_test_lib:localhost(Family, ip), 1820, "secret"}).
-define(BAD_SERVER_INITIAL_RETRIES, 3).
-define(BAD_SERVER_TUPLE_INITIAL, {{eradius_test_handler:localhost(tuple), 1820},
?BAD_SERVER_INITIAL_RETRIES,
?BAD_SERVER_INITIAL_RETRIES}).
-define(BAD_SERVER_TUPLE, {{eradius_test_handler:localhost(tuple), 1820},
?BAD_SERVER_INITIAL_RETRIES - 1,
?BAD_SERVER_INITIAL_RETRIES}).
-define(BAD_SERVER_IP_ETS_KEY, {eradius_test_handler:localhost(tuple), 1820}).
-define(BAD_SERVER_TUPLE_INITIAL(Family),
{{eradius_test_lib:localhost(Family, tuple), 1820},
?BAD_SERVER_INITIAL_RETRIES,
?BAD_SERVER_INITIAL_RETRIES}).
-define(BAD_SERVER_TUPLE(Family),
{{eradius_test_lib:localhost(Family, tuple), 1820},
?BAD_SERVER_INITIAL_RETRIES - 1,
?BAD_SERVER_INITIAL_RETRIES}).
-define(BAD_SERVER_IP_ETS_KEY(Family),
{eradius_test_lib:localhost(Family, tuple), 1820}).

-define(GOOD_SERVER_INITIAL_RETRIES, 3).
-define(GOOD_SERVER_TUPLE, {{eradius_test_handler:localhost(tuple), 1812},
?GOOD_SERVER_INITIAL_RETRIES,
?GOOD_SERVER_INITIAL_RETRIES}).
-define(GOOD_SERVER_2_TUPLE, {{{127, 0, 0, 2}, 1813},
?GOOD_SERVER_INITIAL_RETRIES,
?GOOD_SERVER_INITIAL_RETRIES}).

-define(RADIUS_SERVERS, [?GOOD_SERVER_TUPLE,
?BAD_SERVER_TUPLE_INITIAL,
?GOOD_SERVER_2_TUPLE]).
-define(GOOD_SERVER_TUPLE(Family),
{{eradius_test_lib:localhost(Family, tuple), 1812},
?GOOD_SERVER_INITIAL_RETRIES,
?GOOD_SERVER_INITIAL_RETRIES}).
-define(GOOD_SERVER_2_TUPLE(Family),
{{eradius_test_lib:badhost(Family), 1813},
?GOOD_SERVER_INITIAL_RETRIES,
?GOOD_SERVER_INITIAL_RETRIES}).

-define(RADIUS_SERVERS(Family),
[?GOOD_SERVER_TUPLE(Family),
?BAD_SERVER_TUPLE_INITIAL(Family),
?GOOD_SERVER_2_TUPLE(Family)]).

%%%===================================================================
%%% Setup
%%%===================================================================

-spec all() -> [ct_suite:ct_test_def(), ...].
all() -> [
send_request,
wanna_send,
reconf_address,
wanna_send,
reconf_ports_30,
wanna_send,
reconf_ports_10,
wanna_send,
send_request_failover,
check_upstream_servers
].
all() ->
[{group, ipv4},
{group, ipv4_mapped_ipv6},
{group, ipv6}].

common() ->
[send_request,
wanna_send,
reconf_address,
wanna_send,
reconf_ports_30,
wanna_send,
reconf_ports_10,
wanna_send,
send_request_failover,
check_upstream_servers
].

-spec groups() -> [ct_suite:ct_group_def(), ...].
groups() ->
SocketGroups = [{group, inet}, {group, socket}],
[{inet, [], common()},
{socket, [], common()},
{ipv4, [], SocketGroups},
{ipv4_mapped_ipv6, [], SocketGroups},
{ipv6, [], SocketGroups}].

init_per_suite(Config) ->
{ok, _} = application:ensure_all_started(eradius),
Expand All @@ -70,17 +86,48 @@ end_per_suite(_Config) ->
application:stop(eradius),
ok.

init_per_group(inet, Config) ->
[{inet_backend, inet} | Config];
init_per_group(socket, Config) ->
[{inet_backend, socket} | Config];
init_per_group(ipv6 = Group, Config) ->
{skip, "no IPv6 server support (yet)"};
%% case eradius_test_lib:has_ipv6_test_config() of
%% true ->
%% [{family, Group} | Config];
%% _ ->
%% {skip, "IPv6 test IPs not configured"}
%% end;
init_per_group(ipv4_mapped_ipv6 = Group, Config) ->
case eradius_test_lib:has_ipv6_test_config() of
true ->
[{family, Group} | Config];
_ ->
{skip, "IPv6 test IPs not configured"}
end;
init_per_group(ipv4 = Group, Config) ->
[{family, Group} | Config].

end_per_group(_Group, _Config) ->
application:stop(eradius),
ok.

start_handler(Config) ->
Backend = proplists:get_value(inet_backend, Config, inet),
Family = proplists:get_value(family, Config),
eradius_test_handler:start(Backend, Family).

init_per_testcase(send_request, Config) ->
application:stop(eradius),
eradius_test_handler:start(),
start_handler(Config),
Config;
init_per_testcase(send_request_failover, Config) ->
application:stop(eradius),
eradius_test_handler:start(),
start_handler(Config),
Config;
init_per_testcase(check_upstream_servers, Config) ->
application:stop(eradius),
eradius_test_handler:start(),
start_handler(Config),
Config;
init_per_testcase(_Test, Config) ->
Config.
Expand Down Expand Up @@ -157,6 +204,7 @@ check(#{sockets := OS, no_ports := _OP, idcounters := _OC, socket_id := {_, OA}}
test(PA == NA, "Adress not configured") and
case NA of
OA ->
ct:pal("NP: ~p, NC: ~p", [NP, NC]),
{_, Rest} = split(NP, array:to_list(OS)),
test(P == NP,"Ports not configured") and
test(maps:fold( fun(_Peer, {NextPortIdx, _NextReqId}, Akk) ->
Expand All @@ -173,11 +221,16 @@ check(#{sockets := OS, no_ports := _OP, idcounters := _OC, socket_id := {_, OA}}

%% TESTS

send_request(_Config) ->
?equal(accept, eradius_test_handler:send_request(eradius_test_handler:localhost(tuple))),
?equal(accept, eradius_test_handler:send_request(eradius_test_handler:localhost(ip))),
?equal(accept, eradius_test_handler:send_request(eradius_test_handler:localhost(string))),
?equal(accept, eradius_test_handler:send_request(eradius_test_handler:localhost(binary))),
send_request(Config) ->
Family = proplists:get_value(family, Config),
?equal(accept,
eradius_test_handler:send_request(eradius_test_lib:localhost(Family, tuple))),
?equal(accept,
eradius_test_handler:send_request(eradius_test_lib:localhost(Family, ip))),
?equal(accept,
eradius_test_handler:send_request(eradius_test_lib:localhost(Family, string))),
?equal(accept,
eradius_test_handler:send_request(eradius_test_lib:localhost(Family, binary))),
ok.

send(FUN, Ports, Address) ->
Expand All @@ -198,27 +251,36 @@ wanna_send(_Config) ->

%% socket shutdown is done asynchronous, the tests need to wait a bit for it to finish.
reconf_address(_Config) ->
FUN = fun() -> eradius_client_mngr:reconfigure(), timer:sleep(100) end,
application:set_env(eradius, client_ip, "7.13.23.42"),
FUN = fun() ->
eradius_client_mngr:reconfigure(#{ip => "7.13.23.42"}),
timer:sleep(100)
end,
send(FUN, null, "7.13.23.42").

reconf_ports_30(_Config) ->
FUN = fun() -> eradius_client_mngr:reconfigure(), timer:sleep(100) end,
application:set_env(eradius, client_ports, 30),
FUN = fun() ->
eradius_client_mngr:reconfigure(#{no_ports => 30}),
timer:sleep(100)
end,
send(FUN, 30, null).

reconf_ports_10(_Config) ->
FUN = fun() -> eradius_client_mngr:reconfigure(), timer:sleep(100) end,
application:set_env(eradius, client_ports, 10),
FUN = fun() ->
eradius_client_mngr:reconfigure(#{no_ports => 10}),
timer:sleep(100)
end,
send(FUN, 10, null).

send_request_failover(_Config) ->
?equal(accept, eradius_test_handler:send_request_failover(?BAD_SERVER_IP)),
send_request_failover(Config) ->
Family = proplists:get_value(family, Config),
?equal(accept, eradius_test_handler:send_request_failover(?BAD_SERVER_IP(Family))),
{ok, Timeout} = application:get_env(eradius, unreachable_timeout),
timer:sleep(Timeout * 1000),
?equal([?BAD_SERVER_TUPLE], eradius_client_mngr:servers(?BAD_SERVER_IP_ETS_KEY)),
?equal([?BAD_SERVER_TUPLE(Family)],
eradius_client_mngr:servers(?BAD_SERVER_IP_ETS_KEY(Family))),
ok.

check_upstream_servers(_Config) ->
?equal(?RADIUS_SERVERS, eradius_client_mngr:servers()),
check_upstream_servers(Config) ->
Family = proplists:get_value(family, Config),
?equal(lists:keysort(1, ?RADIUS_SERVERS(Family)), eradius_client_mngr:servers()),
ok.
14 changes: 7 additions & 7 deletions test/eradius_config_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ config_1(_Config) ->
Conf = [{session_nodes, ['node1@host1', 'node2@host2']},
{radius_callback, ?MODULE},
{servers, [
{root, {eradius_test_handler:localhost(ip), [1812, 1813]}}
{root, {eradius_test_lib:localhost(ip), [1812, 1813]}}
]},
{root, [
{ {"NAS1", [arg1, arg2]},
Expand All @@ -49,7 +49,7 @@ config_1(_Config) ->
[{{10, 18, 14, 3}, <<"secret2">>, [{nas_id, <<"name">>}]}]}
]}],
ok = apply_conf(Conf),
LocalHost = eradius_test_handler:localhost(tuple),
LocalHost = eradius_test_lib:localhost(tuple),
?match({ok, {?MODULE,[arg1,arg2]},
#nas_prop{
server_ip = LocalHost,
Expand Down Expand Up @@ -83,7 +83,7 @@ config_2(_Config) ->
]
},
{servers, [
{root, {eradius_test_handler:localhost(ip), [1812, 1813]}}
{root, {eradius_test_lib:localhost(ip), [1812, 1813]}}
]},
{root, [
{ {handler1, "NAS1", [arg1, arg2]},
Expand All @@ -93,7 +93,7 @@ config_2(_Config) ->
[ {"10.18.14.2", <<"secret2">>, [{group, "NodeGroup2"}]} ] }
]}],
ok = apply_conf(Conf),
LocalHost = eradius_test_handler:localhost(tuple),
LocalHost = eradius_test_lib:localhost(tuple),
?match({ok, {handler1,[arg1,arg2]},
#nas_prop{
server_ip = LocalHost,
Expand Down Expand Up @@ -146,7 +146,7 @@ test_validate_server(_Config) ->
ok.

config_nas_removing(_Config) ->
Conf = [{servers, [ {root, {eradius_test_handler:localhost(ip), [1812, 1813]}} ]},
Conf = [{servers, [ {root, {eradius_test_lib:localhost(ip), [1812, 1813]}} ]},
{root, [ ]}],
ok = apply_conf(Conf),
?match([], ets:tab2list(eradius_nas_tab)),
Expand All @@ -159,14 +159,14 @@ config_with_ranges(_Config) ->
]
},
{servers, [
{root, {eradius_test_handler:localhost(ip), [1812, 1813]}}
{root, {eradius_test_lib:localhost(ip), [1812, 1813]}}
]},
{root, [
{ {handler, "NAS", []},
[ {"10.18.14.2/30", <<"secret2">>, [{group, "NodeGroup"}]} ] }
]}],
ok = apply_conf(Conf),
LocalHost = eradius_test_handler:localhost(tuple),
LocalHost = eradius_test_lib:localhost(tuple),
?match({ok, {handler,[]},
#nas_prop{
server_ip = LocalHost,
Expand Down
24 changes: 12 additions & 12 deletions test/eradius_logtest.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@

start() ->
application:load(eradius),
ProxyConfig = [{default_route, {eradius_test_handler:localhost(tuple), 1813, ?SECRET}},
ProxyConfig = [{default_route, {eradius_test_lib:localhost(tuple), 1813, ?SECRET}},
{options, [{type, realm}, {strip, true}, {separator, "@"}]},
{routes, [{"test", {eradius_test_handler:localhost(tuple), 1815, ?SECRET3}}
{routes, [{"test", {eradius_test_lib:localhost(tuple), 1815, ?SECRET3}}
]}
],
Config = [{radius_callback, eradius_logtest},
{servers, [{root, {eradius_test_handler:localhost(ip), [1812, 1813]}},
{test, {eradius_test_handler:localhost(ip), [1815]}},
{proxy, {eradius_test_handler:localhost(ip), [11812, 11813]}}
{servers, [{root, {eradius_test_lib:localhost(ip), [1812, 1813]}},
{test, {eradius_test_lib:localhost(ip), [1815]}},
{proxy, {eradius_test_lib:localhost(ip), [11812, 11813]}}
]},
{session_nodes, [node()]},
{root, [
{ {eradius_logtest, "root", [] }, [{"127.0.0.1/24", ?SECRET, [{nas_id, <<"Test_Nas_Id">>}]}] }
]},
{test, [
{ {eradius_logtest, "test", [] }, [{eradius_test_handler:localhost(ip), ?SECRET3, [{nas_id, <<"Test_Nas_Id_test">>}]}] }
{ {eradius_logtest, "test", [] }, [{eradius_test_lib:localhost(ip), ?SECRET3, [{nas_id, <<"Test_Nas_Id_test">>}]}] }
]},
{proxy, [
{ {eradius_proxy, "proxy", ProxyConfig }, [{eradius_test_handler:localhost(ip), ?SECRET2, [{nas_id, <<"Test_Nas_proxy">>}]}] }
{ {eradius_proxy, "proxy", ProxyConfig }, [{eradius_test_lib:localhost(ip), ?SECRET2, [{nas_id, <<"Test_Nas_proxy">>}]}] }
]}
],
[application:set_env(eradius, Key, Value) || {Key, Value} <- Config],
Expand Down Expand Up @@ -97,20 +97,20 @@ test_client() ->
test_client(Command) ->
eradius_dict:load_tables([dictionary, dictionary_3gpp]),
Request = eradius_lib:set_attributes(#radius_request{cmd = Command, msg_hmac = true}, attrs("user")),
send_request(eradius_test_handler:localhost(tuple), 1813, ?SECRET, Request).
send_request(eradius_test_lib:localhost(tuple), 1813, ?SECRET, Request).

test_proxy() ->
test_proxy(request).

test_proxy(Command) ->
eradius_dict:load_tables([dictionary, dictionary_3gpp]),
send_request(eradius_test_handler:localhost(tuple), 11813, ?SECRET2, #radius_request{cmd = Command}),
send_request(eradius_test_lib:localhost(tuple), 11813, ?SECRET2, #radius_request{cmd = Command}),
Request = eradius_lib:set_attributes(#radius_request{cmd = Command, msg_hmac = true}, attrs("proxy_test")),
send_request(eradius_test_handler:localhost(tuple), 11813, ?SECRET2, Request),
send_request(eradius_test_lib:localhost(tuple), 11813, ?SECRET2, Request),
Request2 = eradius_lib:set_attributes(#radius_request{cmd = Command, msg_hmac = true}, attrs("user@test")),
send_request(eradius_test_handler:localhost(tuple), 11813, ?SECRET2, Request2),
send_request(eradius_test_lib:localhost(tuple), 11813, ?SECRET2, Request2),
Request3 = eradius_lib:set_attributes(#radius_request{cmd = Command, msg_hmac = true}, attrs("user@domain@test")),
send_request(eradius_test_handler:localhost(tuple), 11813, ?SECRET2, Request3).
send_request(eradius_test_lib:localhost(tuple), 11813, ?SECRET2, Request3).

send_request(Ip, Port, Secret, Request) ->
case eradius_client:send_request({Ip, Port, Secret}, Request) of
Expand Down
Loading

0 comments on commit 349282c

Please sign in to comment.