aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/autobahn_SUITE_data/test.py4
-rw-r--r--test/ws_SUITE.erl63
2 files changed, 62 insertions, 5 deletions
diff --git a/test/autobahn_SUITE_data/test.py b/test/autobahn_SUITE_data/test.py
index 422cb41..c528c64 100755
--- a/test/autobahn_SUITE_data/test.py
+++ b/test/autobahn_SUITE_data/test.py
@@ -29,7 +29,7 @@ def install_env(env):
subprocess.check_call(["curl", "-sS", VIRTUALENV_URL, "-o", VIRTUALENV_BIN])
subprocess.check_call(["python", VIRTUALENV_BIN, env])
activate_env(env)
- subprocess.check_call([PIP_BIN, "install", "Autobahn"])
+ subprocess.check_call([PIP_BIN, "install", "AutobahnTestSuite"])
def client_config():
"""
@@ -54,7 +54,7 @@ def run_test(env, config):
activate_env(env)
from twisted.python import log
from twisted.internet import reactor
- from autobahn.fuzzing import FuzzingClientFactory
+ from autobahntestsuite.fuzzing import FuzzingClientFactory
os.chdir(AB_TESTS_PRIV)
log.startLogging(sys.stdout)
fuzzer = FuzzingClientFactory(config)
diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl
index 136833f..0c5e2c8 100644
--- a/test/ws_SUITE.erl
+++ b/test/ws_SUITE.erl
@@ -19,7 +19,7 @@
-export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2]). %% ct.
-export([ws0/1, ws8/1, ws8_single_bytes/1, ws8_init_shutdown/1,
- ws13/1, ws_timeout_hibernate/1]). %% ws.
+ ws13/1, ws_timeout_hibernate/1, ws_text_fragments/1]). %% ws.
%% ct.
@@ -28,7 +28,7 @@ all() ->
groups() ->
BaseTests = [ws0, ws8, ws8_single_bytes, ws8_init_shutdown, ws13,
- ws_timeout_hibernate],
+ ws_timeout_hibernate, ws_text_fragments],
[{ws, [], BaseTests}].
init_per_suite(Config) ->
@@ -60,7 +60,8 @@ init_dispatch() ->
{[<<"localhost">>], [
{[<<"websocket">>], websocket_handler, []},
{[<<"ws_timeout_hibernate">>], ws_timeout_hibernate_handler, []},
- {[<<"ws_init_shutdown">>], websocket_handler_init_shutdown, []}
+ {[<<"ws_init_shutdown">>], websocket_handler_init_shutdown, []},
+ {[<<"ws_echo_handler">>], websocket_echo_handler, []}
]}
].
@@ -310,6 +311,62 @@ ws13(Config) ->
{error, closed} = gen_tcp:recv(Socket, 0, 6000),
ok.
+ws_text_fragments(Config) ->
+ {port, Port} = lists:keyfind(port, 1, Config),
+ {ok, Socket} = gen_tcp:connect("localhost", Port,
+ [binary, {active, false}, {packet, raw}]),
+ ok = gen_tcp:send(Socket, [
+ "GET /ws_echo_handler HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Connection: Upgrade\r\n"
+ "Upgrade: websocket\r\n"
+ "Sec-WebSocket-Origin: http://localhost\r\n"
+ "Sec-WebSocket-Version: 8\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"
+ "\r\n"]),
+ {ok, Handshake} = gen_tcp:recv(Socket, 0, 6000),
+ {ok, {http_response, {1, 1}, 101, "Switching Protocols"}, Rest}
+ = erlang:decode_packet(http, Handshake, []),
+ [Headers, <<>>] = websocket_headers(
+ erlang:decode_packet(httph, Rest, []), []),
+ {'Connection', "Upgrade"} = lists:keyfind('Connection', 1, Headers),
+ {'Upgrade', "websocket"} = lists:keyfind('Upgrade', 1, Headers),
+ {"sec-websocket-accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="}
+ = lists:keyfind("sec-websocket-accept", 1, Headers),
+
+ ok = gen_tcp:send(Socket, [
+ << 0:1, 0:3, 1:4, 1:1, 5:7 >>,
+ << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>,
+ << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>]),
+ ok = gen_tcp:send(Socket, [
+ << 1:1, 0:3, 0:4, 1:1, 5:7 >>,
+ << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>,
+ << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>]),
+ {ok, << 1:1, 0:3, 1:4, 0:1, 10:7, "HelloHello" >>}
+ = gen_tcp:recv(Socket, 0, 6000),
+
+ ok = gen_tcp:send(Socket, [
+ %% #1
+ << 0:1, 0:3, 1:4, 1:1, 5:7 >>,
+ << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>,
+ << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>,
+ %% #2
+ << 0:1, 0:3, 0:4, 1:1, 5:7 >>,
+ << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>,
+ << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>,
+ %% #3
+ << 1:1, 0:3, 0:4, 1:1, 5:7 >>,
+ << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>,
+ << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>]),
+ {ok, << 1:1, 0:3, 1:4, 0:1, 15:7, "HelloHelloHello" >>}
+ = gen_tcp:recv(Socket, 0, 6000),
+
+ ok = gen_tcp:send(Socket, << 1:1, 0:3, 8:4, 0:8 >>), %% close
+ {ok, << 1:1, 0:3, 8:4, 0:8 >>} = gen_tcp:recv(Socket, 0, 6000),
+ {error, closed} = gen_tcp:recv(Socket, 0, 6000),
+ ok.
+
+
websocket_headers({ok, http_eoh, Rest}, Acc) ->
[Acc, Rest];
websocket_headers({ok, {http_header, _I, Key, _R, Value}, Rest}, Acc) ->