aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-10-31 22:41:59 +0100
committerLoïc Hoguin <[email protected]>2018-10-31 22:41:59 +0100
commitb3bfcf068c20573ae06df42530f1a6d4dc6842c7 (patch)
treeecd450c038789864a6c725b0ff365a650f683ea3 /test
parent09bf1199aa3e33a73970ee4ce38714be087b0df0 (diff)
downloadcowboy-b3bfcf068c20573ae06df42530f1a6d4dc6842c7.tar.gz
cowboy-b3bfcf068c20573ae06df42530f1a6d4dc6842c7.tar.bz2
cowboy-b3bfcf068c20573ae06df42530f1a6d4dc6842c7.zip
Add a cowboy_rest test for malformed if-*-match headers
Diffstat (limited to 'test')
-rw-r--r--test/handlers/rest_hello_h.erl16
-rw-r--r--test/rest_handler_SUITE.erl21
2 files changed, 37 insertions, 0 deletions
diff --git a/test/handlers/rest_hello_h.erl b/test/handlers/rest_hello_h.erl
new file mode 100644
index 0000000..a40d6ac
--- /dev/null
+++ b/test/handlers/rest_hello_h.erl
@@ -0,0 +1,16 @@
+%% This module sends a hello world response via a REST handler.
+
+-module(rest_hello_h).
+
+-export([init/2]).
+-export([content_types_provided/2]).
+-export([get_text_plain/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+content_types_provided(Req, State) ->
+ {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
diff --git a/test/rest_handler_SUITE.erl b/test/rest_handler_SUITE.erl
index 1d9619c..a9884b5 100644
--- a/test/rest_handler_SUITE.erl
+++ b/test/rest_handler_SUITE.erl
@@ -38,6 +38,7 @@ end_per_group(Name, _) ->
init_dispatch(_) ->
cowboy_router:compile([{'_', [
+ {"/", rest_hello_h, []},
{"/provide_callback_missing", provide_callback_missing_h, []},
{"/switch_handler", switch_handler_h, run},
{"/switch_handler_opts", switch_handler_h, hibernate}
@@ -53,6 +54,26 @@ do_decode(Headers, Body) ->
%% Tests.
+error_on_malformed_if_match(Config) ->
+ doc("A malformed If-Match header must result in a 400 response."),
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, "/", [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"if-match">>, <<"bad">>}
+ ]),
+ {response, _, 400, _} = gun:await(ConnPid, Ref),
+ ok.
+
+error_on_malformed_if_none_match(Config) ->
+ doc("A malformed If-None-Match header must result in a 400 response."),
+ ConnPid = gun_open(Config),
+ Ref = gun:get(ConnPid, "/", [
+ {<<"accept-encoding">>, <<"gzip">>},
+ {<<"if-none-match">>, <<"bad">>}
+ ]),
+ {response, _, 400, _} = gun:await(ConnPid, Ref),
+ ok.
+
provide_callback_missing(Config) ->
doc("A 500 response must be sent when the ProvideCallback can't be called."),
ConnPid = gun_open(Config),