aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r--test/http_SUITE.erl80
1 files changed, 77 insertions, 3 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index f8ba530..9928136 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -1,4 +1,4 @@
-%% Copyright (c) 2018-2024, Loïc Hoguin <[email protected]>
+%% Copyright (c) Loïc Hoguin <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -28,9 +28,16 @@
-import(cowboy_test, [raw_recv/3]).
-import(cowboy_test, [raw_expect_recv/2]).
-all() -> [{group, clear}].
+all() ->
+ [{group, clear_no_parallel}, {group, clear}].
-groups() -> [{clear, [parallel], ct_helper:all(?MODULE)}].
+groups() ->
+ [
+ %% cowboy:stop_listener can be slow when called many times
+ %% in parallel so we must run this test separately from the others.
+ {clear_no_parallel, [], [graceful_shutdown_listener]},
+ {clear, [parallel], ct_helper:all(?MODULE) -- [graceful_shutdown_listener]}
+ ].
init_per_group(Name, Config) ->
cowboy_test:init_http(Name, #{
@@ -199,6 +206,73 @@ do_chunked_body(ChunkSize0, Data, Acc) ->
do_chunked_body(ChunkSize, Rest,
[iolist_to_binary(cow_http_te:chunk(Chunk))|Acc]).
+disable_http1_tls(Config) ->
+ doc("Ensure that we can disable HTTP/1.1 over TLS (force HTTP/2)."),
+ TlsOpts = ct_helper:get_certs_from_ets(),
+ {ok, _} = cowboy:start_tls(?FUNCTION_NAME, TlsOpts ++ [{port, 0}], #{
+ env => #{dispatch => init_dispatch(Config)},
+ alpn_default_protocol => http2
+ }),
+ Port = ranch:get_port(?FUNCTION_NAME),
+ try
+ {ok, Socket} = ssl:connect("localhost", Port,
+ [binary, {active, false}|TlsOpts]),
+ %% ALPN was not negotiated but we're still over HTTP/2.
+ {error, protocol_not_negotiated} = ssl:negotiated_protocol(Socket),
+ %% Send a valid preface.
+ ok = ssl:send(Socket, [
+ "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n",
+ cow_http2:settings(#{})]),
+ %% Receive the server preface.
+ {ok, << Len:24 >>} = ssl:recv(Socket, 3, 1000),
+ {ok, << 4:8, 0:40, _:Len/binary >>} = ssl:recv(Socket, 6 + Len, 1000),
+ ok
+ after
+ cowboy:stop_listener(?FUNCTION_NAME)
+ end.
+
+disable_http2_prior_knowledge(Config) ->
+ doc("Ensure that we can disable prior knowledge HTTP/2 upgrade."),
+ {ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], #{
+ env => #{dispatch => init_dispatch(Config)},
+ protocols => [http]
+ }),
+ Port = ranch:get_port(?FUNCTION_NAME),
+ try
+ {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}]),
+ %% Send a valid preface.
+ ok = gen_tcp:send(Socket, [
+ "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n",
+ cow_http2:settings(#{})]),
+ {ok, <<"HTTP/1.1 501">>} = gen_tcp:recv(Socket, 12, 1000),
+ ok
+ after
+ cowboy:stop_listener(?FUNCTION_NAME)
+ end.
+
+disable_http2_upgrade(Config) ->
+ doc("Ensure that we can disable HTTP/1.1 upgrade to HTTP/2."),
+ {ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], #{
+ env => #{dispatch => init_dispatch(Config)},
+ protocols => [http]
+ }),
+ Port = ranch:get_port(?FUNCTION_NAME),
+ try
+ {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}]),
+ %% Send a valid preface.
+ ok = gen_tcp:send(Socket, [
+ "GET / HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Connection: Upgrade, HTTP2-Settings\r\n"
+ "Upgrade: h2c\r\n"
+ "HTTP2-Settings: ", base64:encode(cow_http2:settings_payload(#{})), "\r\n",
+ "\r\n"]),
+ {ok, <<"HTTP/1.1 200">>} = gen_tcp:recv(Socket, 12, 1000),
+ ok
+ after
+ cowboy:stop_listener(?FUNCTION_NAME)
+ end.
+
hibernate(Config) ->
doc("Ensure that we can enable hibernation for HTTP/1.1 connections."),
{ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], #{