Browse Source

Move some more tests out of the old HTTP test suite

Loïc Hoguin 6 years ago
parent
commit
dc52ebe440
3 changed files with 29 additions and 31 deletions
  1. 0 31
      test/old_http_SUITE.erl
  2. 19 0
      test/rfc7230_SUITE.erl
  3. 10 0
      test/rfc7231_SUITE.erl

+ 0 - 31
test/old_http_SUITE.erl

@@ -119,32 +119,9 @@ do_get(Path, Config) ->
 
 %% Tests.
 
-check_raw_status(Config) ->
-	Huge = [$0 || _ <- lists:seq(1, 5000)],
-	HugeCookie = lists:flatten(["whatever_man_biiiiiiiiiiiig_cookie_me_want_77="
-		"Wed Apr 06 2011 10:38:52 GMT-0500 (CDT)" || _ <- lists:seq(1, 40)]),
-	Tests = [
-		{200, ["GET / HTTP/1.0\r\nHost: localhost\r\n"
-			"Set-Cookie: ", HugeCookie, "\r\n\r\n"]},
-		{200, "\r\n\r\n\r\n\r\n\r\nGET / HTTP/1.1\r\nHost: localhost\r\n\r\n"},
-		{400, "\n"},
-		{400, "Garbage\r\n\r\n"},
-		{400, "\r\n\r\n\r\n\r\n\r\n\r\n"},
-		{400, "GET  HTTP/1.1\r\nHost: localhost\r\n\r\n"},
-		{400, "GET / HTTP/1.1\r\nHost: ninenines.eu\r\n\r\n"},
-		{400, "GET / HTTP/1.1\r\nHost: localhost:bad_port\r\n\r\n"},
-		{closed, Huge}
-	],
-	_ = [{Status, Packet} = begin
-		Ret = do_raw(Packet, Config),
-		{Ret, Packet}
-	end || {Status, Packet} <- Tests],
-	ok.
-
 check_status(Config) ->
 	Tests = [
 		{200, "/simple"},
-		{404, "/not/found"},
 		{500, "/handler_errors?case=init_before_reply"}
 	],
 	_ = [{Status, URL} = begin
@@ -158,14 +135,6 @@ error_init_after_reply(Config) ->
 	{response, nofin, 200, _} = gun:await(ConnPid, Ref),
 	ok.
 
-headers_dupe(Config) ->
-	ConnPid = gun_open(Config),
-	Ref = gun:get(ConnPid, "/headers/dupe"),
-	{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
-	%% Ensure that only one connection header was received.
-	[<<"close">>] = [V || {Name, V} <- Headers, Name =:= <<"connection">>],
-	gun_down(ConnPid).
-
 keepalive_nl(Config) ->
 	ConnPid = gun_open(Config),
 	Refs = [begin

+ 19 - 0
test/rfc7230_SUITE.erl

@@ -640,6 +640,15 @@ invalid_request_target(Config) ->
 		"\r\n"),
 	{error, closed} = raw_recv(Client, 0, 1000).
 
+missing_request_target(Config) ->
+	doc("The lack of request target must be rejected with a 400 status code "
+		"and the closing of the connection."),
+	#{code := 400, client := Client} = do_raw(Config,
+		"GET  HTTP/1.1\r\n"
+		"Host: localhost\r\n"
+		"\r\n"),
+	{error, closed} = raw_recv(Client, 0, 1000).
+
 %% Between request-target and version.
 
 reject_tab_between_request_target_and_version(Config) ->
@@ -1641,6 +1650,16 @@ empty_host(Config0) ->
 %%
 %% This is covered in req_SUITE in the tests for cowboy_req:uri/1,2.
 
+reject_non_authoritative_host(Config) ->
+	doc("A request with a host header for which the origin server is "
+		"not authoritative must be rejected with a 400 status code. "
+		"(RFC7230 5.5, RFC7230 9.1)"),
+	#{code := 400} = do_raw(Config, [
+		"GET / HTTP/1.1\r\n"
+		"Host: ninenines.eu\r\n"
+		"\r\n"]),
+	ok.
+
 %@todo
 %Resources with identical URI except for the scheme component
 %must be treated as different. (RFC7230 2.7.2)

+ 10 - 0
test/rfc7231_SUITE.erl

@@ -611,6 +611,16 @@ status_code_404(Config) ->
 	{response, _, 404, _} = gun:await(ConnPid, Ref),
 	ok.
 
+status_code_404_not_found(Config) ->
+	doc("The 404 Not Found status code is sent when the target "
+		"resource does not exist. (RFC7231 6.5.4)"),
+	ConnPid = gun_open(Config),
+	Ref = gun:get(ConnPid, "/not/found", [
+		{<<"accept-encoding">>, <<"gzip">>}
+	]),
+	{response, _, 404, _} = gun:await(ConnPid, Ref),
+	ok.
+
 status_code_405(Config) ->
 	doc("The 405 Method Not Allowed status code can be sent. (RFC7231 6.5.5)"),
 	ConnPid = gun_open(Config),