aboutsummaryrefslogtreecommitdiffstats
path: root/test/rfc7540_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/rfc7540_SUITE.erl')
-rw-r--r--test/rfc7540_SUITE.erl71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/rfc7540_SUITE.erl b/test/rfc7540_SUITE.erl
index f19ce34..780f850 100644
--- a/test/rfc7540_SUITE.erl
+++ b/test/rfc7540_SUITE.erl
@@ -70,6 +70,77 @@ do_authority_port(Transport0, DefaultPort, AuthorityHeaderPort) ->
AuthorityHeaderPort = Rest,
gun:close(ConnPid).
+prior_knowledge_preface_garbage(_) ->
+ doc("A PROTOCOL_ERROR connection error must result from the server sending "
+ "an invalid preface in the form of garbage when connecting "
+ "using the prior knowledge method. (RFC7540 3.4, RFC7540 3.5)"),
+ %% We use 'http' here because we are going to do the handshake manually.
+ {ok, OriginPid, Port} = init_origin(tcp, http, fun(_, Socket, Transport) ->
+ ok = Transport:send(Socket, <<0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15>>),
+ timer:sleep(100)
+ end),
+ {ok, ConnPid} = gun:open("localhost", Port, #{protocols => [http2]}),
+ {ok, http2} = gun:await_up(ConnPid),
+ handshake_completed = receive_from(OriginPid),
+ receive
+ {gun_down, ConnPid, http2, {error, {connection_error, protocol_error,
+ 'Invalid connection preface received. (RFC7540 3.5)'}}, []} ->
+ gun:close(ConnPid);
+ Msg ->
+ error({unexpected_msg, Msg})
+ after 1000 ->
+ error(timeout)
+ end.
+
+prior_knowledge_preface_http1(_) ->
+ doc("A PROTOCOL_ERROR connection error must result from the server sending "
+ "an invalid preface in the form of an HTTP/1.1 response when connecting "
+ "using the prior knowledge method. (RFC7540 3.4, RFC7540 3.5)"),
+ %% We use 'http' here because we are going to do the handshake manually.
+ {ok, OriginPid, Port} = init_origin(tcp, http, fun(_, Socket, Transport) ->
+ ok = Transport:send(Socket, <<
+ "HTTP/1.1 400 Bad Request\r\n"
+ "Connection: close\r\n"
+ "Content-Length: 0\r\n"
+ "Date: Thu, 27 Feb 2020 09:32:17 GMT\r\n"
+ "\r\n">>),
+ timer:sleep(100)
+ end),
+ {ok, ConnPid} = gun:open("localhost", Port, #{protocols => [http2]}),
+ {ok, http2} = gun:await_up(ConnPid),
+ handshake_completed = receive_from(OriginPid),
+ receive
+ {gun_down, ConnPid, http2, {error, {connection_error, protocol_error,
+ 'Invalid connection preface received. (RFC7540 3.5)'}}, []} ->
+ gun:close(ConnPid);
+ Msg ->
+ error({unexpected_msg, Msg})
+ after 1000 ->
+ error(timeout)
+ end.
+
+prior_knowledge_preface_other_frame(_) ->
+ doc("A PROTOCOL_ERROR connection error must result from the server sending "
+ "an invalid preface in the form of a non-SETTINGS frame when connecting "
+ "using the prior knowledge method. (RFC7540 3.4, RFC7540 3.5)"),
+ %% We use 'http' here because we are going to do the handshake manually.
+ {ok, OriginPid, Port} = init_origin(tcp, http, fun(_, Socket, Transport) ->
+ ok = Transport:send(Socket, cow_http2:window_update(1)),
+ timer:sleep(100)
+ end),
+ {ok, ConnPid} = gun:open("localhost", Port, #{protocols => [http2]}),
+ {ok, http2} = gun:await_up(ConnPid),
+ handshake_completed = receive_from(OriginPid),
+ receive
+ {gun_down, ConnPid, http2, {error, {connection_error, protocol_error,
+ 'Invalid connection preface received. (RFC7540 3.5)'}}, []} ->
+ gun:close(ConnPid);
+ Msg ->
+ error({unexpected_msg, Msg})
+ after 1000 ->
+ error(timeout)
+ end.
+
lingering_data_counts_toward_connection_window(_) ->
doc("DATA frames received after sending RST_STREAM must be counted "
"toward the connection flow-control window. (RFC7540 5.1)"),