aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-04-09 12:59:53 +0200
committerLoïc Hoguin <[email protected]>2011-04-09 12:59:53 +0200
commit21dc1cc546eb9c7a095937205085383d3efe88ab (patch)
tree72e23d26c15795fe99c10a6c5416549a3f1534a3 /test
parent3a776b146e9a890eb2e1ce27ec59305c150dc156 (diff)
downloadcowboy-21dc1cc546eb9c7a095937205085383d3efe88ab.tar.gz
cowboy-21dc1cc546eb9c7a095937205085383d3efe88ab.tar.bz2
cowboy-21dc1cc546eb9c7a095937205085383d3efe88ab.zip
ct: Add raw tests to check that errors are properly handled.
Diffstat (limited to 'test')
-rw-r--r--test/http_SUITE.erl30
1 files changed, 27 insertions, 3 deletions
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),