Browse Source

Move tests from old http suite to rfc7230 suite

Loïc Hoguin 7 years ago
parent
commit
f6539a9a68
3 changed files with 32 additions and 19 deletions
  1. 0 10
      test/handlers/input_crash_h.erl
  2. 0 2
      test/http_SUITE.erl
  3. 32 7
      test/rfc7230_SUITE.erl

+ 0 - 10
test/handlers/input_crash_h.erl

@@ -1,10 +0,0 @@
-%% This module crashes on request input data
-%% depending on the given option.
-
--module(input_crash_h).
-
--export([init/2]).
-
-init(Req, content_length) ->
-	ct_helper_error_h:ignore(erlang, binary_to_integer, 1),
-	cowboy_req:parse_header(<<"content-length">>, Req).

+ 0 - 2
test/http_SUITE.erl

@@ -105,7 +105,6 @@ init_dispatch(Config) ->
 				[{body, <<"A flameless dance does not equal a cycle">>}]},
 				[{body, <<"A flameless dance does not equal a cycle">>}]},
 			{"/handler_errors", http_errors, []},
 			{"/handler_errors", http_errors, []},
 			{"/echo/body", http_echo_body, []},
 			{"/echo/body", http_echo_body, []},
-			{"/crash/content-length", input_crash_h, content_length},
 			{"/param_all", rest_param_all, []},
 			{"/param_all", rest_param_all, []},
 			{"/bad_accept", rest_simple_resource, []},
 			{"/bad_accept", rest_simple_resource, []},
 			{"/bad_content_type", rest_patch_resource, []},
 			{"/bad_content_type", rest_patch_resource, []},
@@ -181,7 +180,6 @@ The document has moved
 		{400, "GET / HTTP/1.1\r\nHost: ninenines.eu\r\n\r\n"},
 		{400, "GET / HTTP/1.1\r\nHost: ninenines.eu\r\n\r\n"},
 		{400, "GET http://proxy/ HTTP/1.1\r\n\r\n"},
 		{400, "GET http://proxy/ HTTP/1.1\r\n\r\n"},
 		{400, "GET / HTTP/1.1\r\nHost: localhost:bad_port\r\n\r\n"},
 		{400, "GET / HTTP/1.1\r\nHost: localhost:bad_port\r\n\r\n"},
-		{400, ["POST /crash/content-length HTTP/1.1\r\nHost: localhost\r\nContent-Length: 5000,5000\r\n\r\n", Huge]},
 		{400, ResponsePacket},
 		{400, ResponsePacket},
 		{408, "GET / HTTP/1.1\r\n"},
 		{408, "GET / HTTP/1.1\r\n"},
 		{408, "GET / HTTP/1.1\r\nHost: localhost"},
 		{408, "GET / HTTP/1.1\r\nHost: localhost"},

+ 32 - 7
test/rfc7230_SUITE.erl

@@ -764,8 +764,19 @@ limit_header_value(Config) ->
 %@todo
 %@todo
 %The normal procedure for parsing headers is to read each header
 %The normal procedure for parsing headers is to read each header
 %field into a hash table by field name until the empty line. (RFC7230 3)
 %field into a hash table by field name until the empty line. (RFC7230 3)
-%
-%reject_duplicate_content_length_header(Config) ->
+
+reject_duplicate_content_length_header(Config) ->
+	doc("Requests with duplicate content-length headers must be rejected "
+		"with a 400 status code and the closing of the connection. (RFC7230 3.3.2)"),
+	#{code := 400, client := Client} = do_raw(Config, [
+		"POST / HTTP/1.1\r\n"
+		"Host: localhost\r\n"
+		"Content-length: 12\r\n"
+		"Content-length: 12\r\n"
+		"\r\n"
+		"Hello world!"]),
+	{error, closed} = raw_recv(Client, 0, 1000).
+
 %reject_duplicate_host_header(Config) ->
 %reject_duplicate_host_header(Config) ->
 %Requests with duplicate content-length or host headers must be rejected
 %Requests with duplicate content-length or host headers must be rejected
 %with a 400 status code and the closing of the connection. (RFC7230 3.3.2)
 %with a 400 status code and the closing of the connection. (RFC7230 3.3.2)
@@ -854,11 +865,25 @@ limit_header_value(Config) ->
 %```
 %```
 %Content-Length = 1*DIGIT
 %Content-Length = 1*DIGIT
 %```
 %```
-%
-%reject_invalid_content_length(Config) ->
-%A request with an invalid content-length header must be rejected
-%with a 400 status code and the closing of the connection. (RFC7230 3.3.3)
-%
+
+reject_invalid_content_length(Config) ->
+	doc("A request with an invalid content-length header must be rejected "
+		"with a 400 status code and the closing of the connection. (RFC7230 3.3.3)"),
+	#{code := 400, client := Client1} = do_raw(Config, [
+		"POST / HTTP/1.1\r\n"
+		"Host: localhost\r\n"
+		"Content-length: 12,12\r\n"
+		"\r\n"
+		"Hello world!"]),
+	{error, closed} = raw_recv(Client1, 0, 1000),
+	#{code := 400, client := Client2} = do_raw(Config, [
+		"POST / HTTP/1.1\r\n"
+		"Host: localhost\r\n"
+		"Content-length: NaN\r\n"
+		"\r\n"
+		"Hello world!"]),
+	{error, closed} = raw_recv(Client2, 0, 1000).
+
 %@todo
 %@todo
 %The content-length header ranges from 0 to infinity. Requests
 %The content-length header ranges from 0 to infinity. Requests
 %with a message body too large must be rejected with a 413 status
 %with a message body too large must be rejected with a 413 status