From 21dc1cc546eb9c7a095937205085383d3efe88ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 9 Apr 2011 12:59:53 +0200 Subject: ct: Add raw tests to check that errors are properly handled. --- test/http_SUITE.erl | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'test/http_SUITE.erl') diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index e06a04c..c8d44ad 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -18,7 +18,8 @@ -export([all/0, groups/0, init_per_suite/1, end_per_suite/1, init_per_group/2, end_per_group/2]). %% ct. --export([http_200/1, http_404/1]). %% Common tests for http and https. +-export([raw/1]). %% http. +-export([http_200/1, http_404/1]). %% http and https. %% ct. @@ -27,7 +28,7 @@ all() -> groups() -> BaseTests = [http_200, http_404], - [{http, [], BaseTests}, + [{http, [], [raw] ++ BaseTests}, {https, [], BaseTests}]. init_per_suite(Config) -> @@ -81,7 +82,30 @@ init_http_dispatch() -> init_https_dispatch() -> init_http_dispatch(). -%% Common tests for http and https. +%% http. + +raw_req(Packet, Config) -> + {port, Port} = lists:keyfind(port, 1, Config), + {ok, Socket} = gen_tcp:connect("localhost", Port, + [binary, {active, false}, {packet, raw}]), + ok = gen_tcp:send(Socket, Packet), + {ok, << "HTTP/1.1 ", Str:24/bits, _Rest/bits >>} + = gen_tcp:recv(Socket, 0, 5000), + gen_tcp:close(Socket), + {Packet, list_to_integer(binary_to_list(Str))}. + +raw(Config) -> + Tests = [ + {"\r\n\r\n\r\n\r\n\r\nGET / HTTP/1.1\r\nHost: localhost\r\n\r\n", 200}, + {"Garbage\r\n\r\n", 400}, + {"GET / HTTP/1.1\r\nHost: dev-extend.eu\r\n\r\n", 400}, + {"GET http://localhost/ HTTP/1.1\r\n\r\n", 501}, + {"GET / HTTP/1.2\r\nHost: localhost\r\n\r\n", 505} + ], + [{Packet, StatusCode} = raw_req(Packet, Config) + || {Packet, StatusCode} <- Tests]. + +%% http and https. build_url(Path, Config) -> {scheme, Scheme} = lists:keyfind(scheme, 1, Config), -- cgit v1.2.3