aboutsummaryrefslogtreecommitdiffstats
path: root/test/rfc7540_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-04-29 20:32:36 +0200
committerLoïc Hoguin <[email protected]>2018-04-29 20:32:36 +0200
commit17349fafc2b64cf424e7bae4e33d3e6bd9deec6e (patch)
treefff1410d9e890cca0636cca56c65ed509aae5d0f /test/rfc7540_SUITE.erl
parent84b4128d068cddc37bbb45e755044183f3e9cd97 (diff)
downloadcowboy-17349fafc2b64cf424e7bae4e33d3e6bd9deec6e.tar.gz
cowboy-17349fafc2b64cf424e7bae4e33d3e6bd9deec6e.tar.bz2
cowboy-17349fafc2b64cf424e7bae4e33d3e6bd9deec6e.zip
Add tests for rejecting streams depending on themselves
Diffstat (limited to 'test/rfc7540_SUITE.erl')
-rw-r--r--test/rfc7540_SUITE.erl44
1 files changed, 43 insertions, 1 deletions
diff --git a/test/rfc7540_SUITE.erl b/test/rfc7540_SUITE.erl
index 3d8bac4..adc84b5 100644
--- a/test/rfc7540_SUITE.erl
+++ b/test/rfc7540_SUITE.erl
@@ -2335,7 +2335,49 @@ reject_streamid_lower(Config) ->
% timely fashion. Failure to do so could lead to a deadlock when
% critical frames, such as WINDOW_UPDATE, are not read and acted upon.
-%% @todo Stream priorities. (RFC7540 5.3 5.3.x)
+%% (RFC7540 5.3.1)
+% Inside the dependency tree, a dependent stream SHOULD only be
+% allocated resources if either all of the streams that it depends on
+% (the chain of parent streams up to 0x0) are closed or it is not
+% possible to make progress on them.
+
+%% We reject all invalid HEADERS with a connection error because
+%% we do not want to waste resources decoding them.
+reject_self_dependent_stream_headers(Config) ->
+ doc("HEADERS frames opening a stream that depends on itself "
+ "must be rejected with a PROTOCOL_ERROR connection error. (RFC7540 5.3.1)"),
+ {ok, Socket} = do_handshake(Config),
+ %% Send a HEADERS frame with priority set to depend on itself.
+ ok = gen_tcp:send(Socket, << 5:24, 1:8,
+ 0:2, 1:1, 0:4, 1:1, 0:1, 1:31, 0:1, 1:31, 0:8 >>),
+ %% Receive a PROTOCOL_ERROR connection error.
+ {ok, << _:24, 7:8, _:72, 1:32 >>} = gen_tcp:recv(Socket, 17, 6000),
+ ok.
+
+%% We reject all invalid HEADERS with a connection error because
+%% we do not want to waste resources decoding them.
+reject_self_dependent_stream_headers_with_padding(Config) ->
+ doc("HEADERS frames opening a stream that depends on itself "
+ "must be rejected with a PROTOCOL_ERROR connection error. (RFC7540 5.3.1)"),
+ {ok, Socket} = do_handshake(Config),
+ %% Send a HEADERS frame with priority set to depend on itself.
+ ok = gen_tcp:send(Socket, << 6:24, 1:8,
+ 0:2, 1:1, 0:1, 1:1, 0:2, 1:1, 0:1, 1:31, 0:8, 0:1, 1:31, 0:8 >>),
+ %% Receive a PROTOCOL_ERROR connection error.
+ {ok, << _:24, 7:8, _:72, 1:32 >>} = gen_tcp:recv(Socket, 17, 6000),
+ ok.
+
+reject_self_dependent_stream_priority(Config) ->
+ doc("PRIORITY frames making a stream depend on itself "
+ "must be rejected with a PROTOCOL_ERROR stream error. (RFC7540 5.3.1)"),
+ {ok, Socket} = do_handshake(Config),
+ %% Send a PRIORITY frame making a stream depend on itself.
+ ok = gen_tcp:send(Socket, cow_http2:priority(1, shared, 1, 123)),
+ %% Receive a PROTOCOL_ERROR stream error.
+ {ok, << _:24, 3:8, _:8, 1:32, 1:32 >>} = gen_tcp:recv(Socket, 13, 6000),
+ ok.
+
+%% @todo Stream priorities. (RFC7540 5.3.2 5.3.3 5.3.4 5.3.5)
%% (RFC7540 5.4.1)
% An endpoint that encounters a connection error SHOULD first send a