-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
7 changed files
with
268 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
|
@@ -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. | ||
|
@@ -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) -> | ||
|
@@ -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) -> | ||
|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.