From 03dac1486d72d9d84a3cb99d2040c78b25853257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 5 Oct 2019 11:23:57 +0200 Subject: Add cowboy_req:filter_cookies/2 --- test/handlers/echo_h.erl | 4 ++++ test/req_SUITE.erl | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'test') diff --git a/test/handlers/echo_h.erl b/test/handlers/echo_h.erl index 7d0e75b..1b672d1 100644 --- a/test/handlers/echo_h.erl +++ b/test/handlers/echo_h.erl @@ -92,6 +92,10 @@ echo(<<"match">>, Req, Opts) -> Match end, {ok, cowboy_req:reply(200, #{}, value_to_iodata(Value), Req), Opts}; +echo(<<"filter_then_parse_cookies">>, Req0, Opts) -> + Req = cowboy_req:filter_cookies([cake, color], Req0), + Value = cowboy_req:parse_cookies(Req), + {ok, cowboy_req:reply(200, #{}, value_to_iodata(Value), Req), Opts}; echo(What, Req, Opts) -> Key = binary_to_atom(What, latin1), Value = case cowboy_req:path(Req) of diff --git a/test/req_SUITE.erl b/test/req_SUITE.erl index 2cc8de4..76abba9 100644 --- a/test/req_SUITE.erl +++ b/test/req_SUITE.erl @@ -286,6 +286,27 @@ parse_cookies(Config) -> [{<<"cookie">>, "goodname=strawberry\tmilkshake"}], Config), ok. +filter_then_parse_cookies(Config) -> + doc("Filter cookies then parse them."), + <<"[]">> = do_get_body("/filter_then_parse_cookies", Config), + <<"[{<<\"cake\">>,<<\"strawberry\">>}]">> + = do_get_body("/filter_then_parse_cookies", [{<<"cookie">>, "cake=strawberry"}], Config), + <<"[{<<\"cake\">>,<<\"strawberry\">>},{<<\"color\">>,<<\"blue\">>}]">> + = do_get_body("/filter_then_parse_cookies", [{<<"cookie">>, "cake=strawberry; color=blue"}], Config), + <<"[{<<\"cake\">>,<<\"strawberry\">>},{<<\"color\">>,<<\"blue\">>}]">> + = do_get_body("/filter_then_parse_cookies", + [{<<"cookie">>, "cake=strawberry"}, {<<"cookie">>, "color=blue"}], Config), + <<"[]">> + = do_get_body("/filter_then_parse_cookies", + [{<<"cookie">>, "bad name=strawberry"}], Config), + <<"[{<<\"cake\">>,<<\"strawberry\">>}]">> + = do_get_body("/filter_then_parse_cookies", + [{<<"cookie">>, "bad name=strawberry; cake=strawberry"}], Config), + <<"[]">> + = do_get_body("/filter_then_parse_cookies", + [{<<"cookie">>, "Blocked by http://www.example.com/upgrade-to-remove"}], Config), + ok. + parse_header(Config) -> doc("Parsed request header with/without default."), <<"[{{<<\"text\">>,<<\"html\">>,[]},1000,[]}]">> -- cgit v1.2.3