aboutsummaryrefslogtreecommitdiffstats
path: root/test/req_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-09-15 21:49:45 +0200
committerLoïc Hoguin <[email protected]>2019-09-15 21:49:45 +0200
commit8452df061711e42354a2cbb54678da3a5c412793 (patch)
tree40d8355bbf6541780ffd50aad4209b0d9568fcde /test/req_SUITE.erl
parentda5487b5a3dbbf5fa4e22d08268fb06647100d23 (diff)
downloadcowboy-8452df061711e42354a2cbb54678da3a5c412793.tar.gz
cowboy-8452df061711e42354a2cbb54678da3a5c412793.tar.bz2
cowboy-8452df061711e42354a2cbb54678da3a5c412793.zip
Split up urlencoded tests to speed up req_SUITE
Diffstat (limited to 'test/req_SUITE.erl')
-rw-r--r--test/req_SUITE.erl44
1 files changed, 26 insertions, 18 deletions
diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl
index 6fc2e12..c79dbf6 100644
--- a/test/req_SUITE.erl
+++ b/test/req_SUITE.erl
@@ -522,20 +522,18 @@ read_urlencoded_body(Config) ->
<<"[{<<\"abc\">>,true}]">> = do_body("POST", "/read_urlencoded_body", [], "abc", Config),
<<"[{<<\"a\">>,<<\"b\">>},{<<\"c\">>,<<\"d e\">>}]">>
= do_body("POST", "/read_urlencoded_body", [], "a=b&c=d+e", Config),
- %% Send a 10MB body, larger than the default length, to ensure a crash occurs.
- ok = do_read_urlencoded_body_too_large("/no-opts/read_urlencoded_body",
- string:chars($a, 10000000), Config),
- %% We read any length for at most 1 second.
- %%
- %% The body is sent twice, first with nofin, then wait 1.1 second, then again with fin.
- %% We expect the handler to crash because read_urlencoded_body expects the full body.
- ok = do_read_urlencoded_body_too_long("/crash/read_urlencoded_body/period", <<"abc">>, Config),
%% The timeout value is set too low on purpose to ensure a crash occurs.
ok = do_read_body_timeout("/opts/read_urlencoded_body/timeout", <<"abc">>, Config),
%% Ensure parse errors result in a 400 response.
{400, _} = do_body_error("POST", "/read_urlencoded_body", [], "%%%%%", Config),
ok.
+read_urlencoded_body_too_large(Config) ->
+ doc("application/x-www-form-urlencoded request body too large. "
+ "Send a 10MB body, larger than the default length, to ensure a crash occurs."),
+ do_read_urlencoded_body_too_large("/no-opts/read_urlencoded_body",
+ string:chars($a, 10000000), Config).
+
%% We expect a crash.
do_read_urlencoded_body_too_large(Path, Body, Config) ->
ConnPid = gun_open(Config),
@@ -546,6 +544,12 @@ do_read_urlencoded_body_too_large(Path, Body, Config) ->
{response, _, 413, _} = gun:await(ConnPid, Ref),
gun:close(ConnPid).
+read_urlencoded_body_too_long(Config) ->
+ doc("application/x-www-form-urlencoded request body sent too slow. "
+ "The body is sent twice with 2s wait in-between. It is read by the handler "
+ "for at most 1 second. A crash occurs because we don't have the full body."),
+ do_read_urlencoded_body_too_long("/crash/read_urlencoded_body/period", <<"abc">>, Config).
+
%% We expect a crash.
do_read_urlencoded_body_too_long(Path, Body, Config) ->
ConnPid = gun_open(Config),
@@ -578,20 +582,24 @@ read_and_match_urlencoded_body(Config) ->
{400, _} = do_body_error("POST", "/match/body_qs/a/c", [], "a=b", Config),
%% Ensure parse errors result in a 400 response.
{400, _} = do_body_error("POST", "/match/body_qs", [], "%%%%%", Config),
- %% Send a 10MB body, larger than the default length, to ensure a crash occurs.
- ok = do_read_urlencoded_body_too_large(
- "/no-opts/read_and_match_urlencoded_body",
- string:chars($a, 10000000), Config),
- %% We read any length for at most 1 second.
- %%
- %% The body is sent twice, first with nofin, then wait 1.1 second, then again with fin.
- %% We expect the handler to crash because read_and_match_urlencoded_body expects the full body.
- ok = do_read_urlencoded_body_too_long(
- "/crash/read_and_match_urlencoded_body/period", <<"abc">>, Config),
%% The timeout value is set too low on purpose to ensure a crash occurs.
ok = do_read_body_timeout("/opts/read_and_match_urlencoded_body/timeout", <<"abc">>, Config),
ok.
+read_and_match_urlencoded_body_too_large(Config) ->
+ doc("Read and match an application/x-www-form-urlencoded request body too large. "
+ "Send a 10MB body, larger than the default length, to ensure a crash occurs."),
+ do_read_urlencoded_body_too_large(
+ "/no-opts/read_and_match_urlencoded_body",
+ string:chars($a, 10000000), Config).
+
+read_and_match_urlencoded_body_too_long(Config) ->
+ doc("Read and match an application/x-www-form-urlencoded request body sent too slow. "
+ "The body is sent twice with 2s wait in-between. It is read by the handler "
+ "for at most 1 second. A crash occurs because we don't have the full body."),
+ do_read_urlencoded_body_too_long(
+ "/crash/read_and_match_urlencoded_body/period", <<"abc">>, Config).
+
multipart(Config) ->
doc("Multipart request body."),
do_multipart("/multipart", Config).