| 1 |
%% Copyright (c) Loïc Hoguin <[email protected]> |
| 2 |
%% |
| 3 |
%% Permission to use, copy, modify, and/or distribute this software for any |
| 4 |
%% purpose with or without fee is hereby granted, provided that the above |
| 5 |
%% copyright notice and this permission notice appear in all copies. |
| 6 |
%% |
| 7 |
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 |
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 |
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 |
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 |
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 |
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 13 |
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 |
|
| 15 |
-module(ws_autobahn_SUITE). |
| 16 |
-compile(export_all). |
| 17 |
-compile(nowarn_export_all). |
| 18 |
|
| 19 |
-import(ct_helper, [config/2]). |
| 20 |
-import(ct_helper, [doc/1]). |
| 21 |
|
| 22 |
%% ct. |
| 23 |
|
| 24 |
all() -> |
| 25 |
[{group, autobahn}]. |
| 26 |
|
| 27 |
groups() -> |
| 28 |
[{autobahn, [], [autobahn_fuzzingclient]}]. |
| 29 |
|
| 30 |
init_per_group(Name, Config) -> |
| 31 |
%% Some systems have it named pip2. |
| 32 |
Out = os:cmd("pip show autobahntestsuite ; pip2 show autobahntestsuite"), |
| 33 |
case string:str(Out, "autobahntestsuite") of |
| 34 |
0 -> |
| 35 |
ct:print("Skipping the autobahn group because the " |
| 36 |
"Autobahn Test Suite is not installed.~nTo install it, " |
| 37 |
"please follow the instructions on this page:~n~n " |
| 38 |
"http://autobahn.ws/testsuite/installation.html"), |
| 39 |
{skip, "Autobahn Test Suite not installed."}; |
| 40 |
_ -> |
| 41 |
{ok, _} = cowboy:start_clear(Name, [{port, 33080}], #{ |
| 42 |
env => #{dispatch => init_dispatch()} |
| 43 |
}), |
| 44 |
Config |
| 45 |
end. |
| 46 |
|
| 47 |
end_per_group(Listener, _Config) -> |
| 48 |
cowboy:stop_listener(Listener). |
| 49 |
|
| 50 |
%% Dispatch configuration. |
| 51 |
|
| 52 |
init_dispatch() -> |
| 53 |
cowboy_router:compile([ |
| 54 |
{"host.docker.internal", [ |
| 55 |
{"/ws_echo", ws_echo, []} |
| 56 |
]} |
| 57 |
]). |
| 58 |
|
| 59 |
%% Tests. |
| 60 |
|
| 61 |
autobahn_fuzzingclient(Config) -> |
| 62 |
doc("Autobahn test suite for the Websocket protocol."), |
| 63 |
Self = self(), |
| 64 |
spawn_link(fun() -> do_start_port(Config, Self) end), |
| 65 |
receive autobahn_exit -> ok end, |
| 66 |
ct:log("<h2><a href=\"log_private/reports/servers/index.html\">Full report</a></h2>~n"), |
| 67 |
Report = config(priv_dir, Config) ++ "reports/servers/index.html", |
| 68 |
ct:print("Autobahn Test Suite report: file://~s~n", [Report]), |
| 69 |
{ok, HTML} = file:read_file(Report), |
| 70 |
case length(binary:matches(HTML, <<"case_failed">>)) > 2 of |
| 71 |
true -> error(failed); |
| 72 |
false -> ok |
| 73 |
end. |
| 74 |
|
| 75 |
do_start_port(Config, Pid) -> |
| 76 |
% Cmd = "wstest -m fuzzingclient -s " ++ config(data_dir, Config) ++ "client.json", |
| 77 |
Cmd = "sudo docker run --rm " |
| 78 |
"-v " ++ config(data_dir, Config) ++ "/client.json:/client.json " |
| 79 |
"-v " ++ config(priv_dir, Config) ++ "/reports:/reports " |
| 80 |
"--add-host=host.docker.internal:host-gateway " |
| 81 |
"--name fuzzingclient " |
| 82 |
"crossbario/autobahn-testsuite " |
| 83 |
"wstest -m fuzzingclient -s client.json", |
| 84 |
Port = open_port({spawn, Cmd}, |
| 85 |
[{line, 10000}, {cd, config(priv_dir, Config)}, binary, eof]), |
| 86 |
do_receive_infinity(Port, Pid). |
| 87 |
|
| 88 |
do_receive_infinity(Port, Pid) -> |
| 89 |
receive |
| 90 |
{Port, {data, {eol, Line}}} -> |
| 91 |
io:format(user, "~s~n", [Line]), |
| 92 |
do_receive_infinity(Port, Pid); |
| 93 |
{Port, eof} -> |
| 94 |
Pid ! autobahn_exit |
| 95 |
end. |