0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Rewrite the tests for header name/value limits

Putting them in the correct test suite, with the proper
documentation etc.
This commit is contained in:
Loïc Hoguin 2017-01-03 18:07:39 +01:00
parent f59c29dff0
commit 42c95b1584
No known key found for this signature in database
GPG key ID: 71366FF21851DF03
2 changed files with 27 additions and 28 deletions

View file

@ -307,20 +307,6 @@ echo_body(Config) ->
end || Size <- lists:seq(MTU - 500, MTU)], end || Size <- lists:seq(MTU - 500, MTU)],
ok. ok.
%% Check if sending request whose header name is bigger than 64 bytes causes 431
echo_body_max_header_name_length(Config) ->
ConnPid = gun_open(Config),
Ref = gun:post(ConnPid, "/echo/body", [{binary:copy(<<$a>>, 32768), <<"bad">>}], << "echo=name" >>),
{response, fin, 431, _} = gun:await(ConnPid, Ref),
ok.
%% Check if sending request whose header name is bigger than 64 bytes causes 431
echo_body_max_header_value_length(Config) ->
ConnPid = gun_open(Config),
Ref = gun:post(ConnPid, "/echo/body", [{<<"bad">>, binary:copy(<<$a>>, 32768)}], << "echo=name" >>),
{response, fin, 431, _} = gun:await(ConnPid, Ref),
ok.
%% Check if sending request whose size is bigger than 1000000 bytes causes 413 %% Check if sending request whose size is bigger than 1000000 bytes causes 413
echo_body_max_length(Config) -> echo_body_max_length(Config) ->
ConnPid = gun_open(Config), ConnPid = gun_open(Config),

View file

@ -726,20 +726,33 @@ reject_invalid_whitespace_after_version(Config) ->
%Messages that contain whitespace between the header name and %Messages that contain whitespace between the header name and
%colon must be rejected with a 400 status code and the closing %colon must be rejected with a 400 status code and the closing
%of the connection. (RFC7230 3.2.4) %of the connection. (RFC7230 3.2.4)
%
%limit_header_name(Config) -> limit_header_name(Config) ->
%The header name must be subject to a configurable limit. A doc("The header name must be subject to a configurable limit. A "
%good default is 50 characters, well above the longest registered "good default is 50 characters, well above the longest registered "
%header. Such a request must be rejected with a 431 status code "header. Such a request must be rejected with a 431 status code "
%and the closing of the connection. (RFC7230 3.2.5, RFC6585 5, IANA Message Headers registry) "and the closing of the connection. "
% "(RFC7230 3.2.5, RFC6585 5, IANA Message Headers registry)"),
%limit_header_value(Config) -> #{code := 431, client := Client} = do_raw(Config, [
%The header value and the optional whitespace around it must be "GET / HTTP/1.1\r\n"
%subject to a configurable limit. There is no recommendations "Host: localhost\r\n",
%for the default. 4096 characters is known to work well. Such binary:copy(<<$a>>, 32768), ": bad\r\n"
%a request must be rejected with a 431 status code and the closing "\r\n"]),
%of the connection. (RFC7230 3.2.5, RFC6585 5) {error, closed} = raw_recv(Client, 0, 1000).
%
limit_header_value(Config) ->
doc("The header value and the optional whitespace around it must be "
"subject to a configurable limit. There is no recommendations "
"for the default. 4096 characters is known to work well. Such "
"a request must be rejected with a 431 status code and the closing "
"of the connection. (RFC7230 3.2.5, RFC6585 5)"),
#{code := 431, client := Client} = do_raw(Config, [
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"bad: ", binary:copy(<<$a>>, 32768), "\r\n"
"\r\n"]),
{error, closed} = raw_recv(Client, 0, 1000).
%drop_whitespace_before_header_value(Config) -> %drop_whitespace_before_header_value(Config) ->
%drop_whitespace_after_header_value(Config) -> %drop_whitespace_after_header_value(Config) ->
%Optional whitespace before and after the header value is not %Optional whitespace before and after the header value is not