aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-04-12 18:46:52 +0300
committerLoïc Hoguin <[email protected]>2015-04-12 18:46:52 +0300
commit7445aa96d346a330787f3820544922a9ed22375b (patch)
treec10a63db6dc13b4da49921b6402be6b39f18416d
parent064f77ac3f11c4bf8d54a73a9d32ce7329d5caaf (diff)
downloadgun-7445aa96d346a330787f3820544922a9ed22375b.tar.gz
gun-7445aa96d346a330787f3820544922a9ed22375b.tar.bz2
gun-7445aa96d346a330787f3820544922a9ed22375b.zip
More and improved SPDY tests
-rw-r--r--test/spdy_SUITE.erl61
-rw-r--r--test/spdy_server.erl5
2 files changed, 51 insertions, 15 deletions
diff --git a/test/spdy_SUITE.erl b/test/spdy_SUITE.erl
index 86167c5..b9bebfc 100644
--- a/test/spdy_SUITE.erl
+++ b/test/spdy_SUITE.erl
@@ -17,16 +17,39 @@
-import(ct_helper, [doc/1]).
+%% ct.
+
all() -> [{group, spdy31}].
groups() -> [{spdy31, [parallel], ct_helper:all(?MODULE)}].
+%% Helper functions.
+
+wait() ->
+ receive after 500 -> ok end.
+
+do_req_resp(ConnPid, ServerPid, ServerStreamID) ->
+ StreamRef = gun:get(ConnPid, "/"),
+ spdy_server:send(ServerPid, [
+ {syn_reply, ServerStreamID, false, <<"200">>, <<"HTTP/1.1">>, []},
+ {data, ServerStreamID, true, <<"Hello world!">>}
+ ]),
+ receive {gun_response, _, StreamRef, _, _, _} ->
+ ok
+ after 5000 ->
+ exit(timeout)
+ end,
+ ok.
+
+%% SPDY/3.1 test suite.
+
goaway_on_close(_) ->
doc("Send a GOAWAY when the client closes the connection (spdy-protocol-draft3-1 2.1)"),
{ok, ServerPid, Port} = spdy_server:start_link(),
{ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
{ok, spdy} = gun:await_up(ConnPid),
gun:close(ConnPid),
+ wait(),
[{goaway, 0, ok}] = spdy_server:stop(ServerPid).
goaway_on_shutdown(_) ->
@@ -35,20 +58,9 @@ goaway_on_shutdown(_) ->
{ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
{ok, spdy} = gun:await_up(ConnPid),
gun:shutdown(ConnPid),
+ wait(),
[{goaway, 0, ok}] = spdy_server:stop(ServerPid).
-do_req_resp(ConnPid, ServerPid, ServerStreamID) ->
- StreamRef = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [
- {syn_reply, ServerStreamID, false, <<"200">>, <<"HTTP/1.1">>, []},
- {data, ServerStreamID, true, <<"Hello world!">>}
- ]),
- receive {gun_response, _, StreamRef, _, _, _} ->
- ok
- after 5000 ->
- exit(timeout)
- end,
- ok.
streamid_is_odd(_) ->
doc("Client-initiated Stream-ID must be an odd number. (spdy-protocol-draft3-1 2.3.2)"),
@@ -64,9 +76,12 @@ reject_streamid_0(_) ->
{ok, ServerPid, Port} = spdy_server:start_link(),
{ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
{ok, spdy} = gun:await_up(ConnPid),
- StreamRef = gun:get(ConnPid, "/"),
- spdy_server:send(ServerPid, [{syn_reply, 0, true, <<"200">>, <<"HTTP/1.1">>, []}]),
- receive after 500 -> ok end,
+ _ = gun:get(ConnPid, "/"),
+ spdy_server:send(ServerPid, [
+ {syn_stream, 0, 1, true, true, 0, <<"GET">>, <<"https">>, ["localhost:", integer_to_binary(Port)], "/a", <<"HTTP/1.1">>, []},
+ {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []}
+ ]),
+ wait(),
[_, {goaway, 1, protocol_error}] = spdy_server:stop(ServerPid).
streamid_increases_monotonically(_) ->
@@ -78,3 +93,19 @@ streamid_increases_monotonically(_) ->
[do_req_resp(ConnPid, ServerPid, N) || N <- Expected],
Rec = spdy_server:stop(ServerPid),
Expected = [StreamID || {syn_stream, StreamID, _, _, _, _, _, _, _, _, _, _} <- Rec].
+
+syn_stream_decreasing_streamid(_) ->
+ doc("Reject a decreasing Stream-ID with a PROTOCOL_ERROR session error. (spdy-protocol-draft3-1 2.3.2)"),
+ {ok, ServerPid, Port} = spdy_server:start_link(),
+ {ok, ConnPid} = gun:open("localhost", Port, #{transport=>ssl}),
+ {ok, spdy} = gun:await_up(ConnPid),
+ _ = gun:get(ConnPid, "/"),
+ Host = ["localhost:", integer_to_binary(Port)],
+ spdy_server:send(ServerPid, [
+ {syn_stream, 2, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/a", <<"HTTP/1.1">>, []},
+ {syn_stream, 6, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/b", <<"HTTP/1.1">>, []},
+ {syn_stream, 4, 1, true, true, 0, <<"GET">>, <<"https">>, Host, "/c", <<"HTTP/1.1">>, []},
+ {syn_reply, 1, true, <<"200">>, <<"HTTP/1.1">>, []}
+ ]),
+ wait(),
+ [_, {goaway, 1, protocol_error}] = spdy_server:stop(ServerPid).
diff --git a/test/spdy_server.erl b/test/spdy_server.erl
index 0b3ec6d..10ef067 100644
--- a/test/spdy_server.erl
+++ b/test/spdy_server.erl
@@ -105,6 +105,11 @@ code_change(_OldVsn, State, _Extra) ->
do_send([], _, _) ->
ok;
+do_send([{syn_stream, StreamID, AssocToStreamID, IsFin, IsUnidirectional, Priority,
+ Method, Scheme, Host, Path, Version, Headers}|Tail], Socket, Zdef) ->
+ ssl:send(Socket, cow_spdy:syn_stream(Zdef, StreamID, AssocToStreamID, IsFin, IsUnidirectional, Priority,
+ Method, Scheme, Host, Path, Version, Headers)),
+ do_send(Tail, Socket, Zdef);
do_send([{syn_reply, StreamID, IsFin, Status, Version, Headers}|Tail], Socket, Zdef) ->
ssl:send(Socket, cow_spdy:syn_reply(Zdef, StreamID, IsFin, Status, Version, Headers)),
do_send(Tail, Socket, Zdef);