From 6599fc9a0ce1721271cc070f6d54a677d466c583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 16 Apr 2020 14:44:23 +0200 Subject: Add tests for cookie_ignore_informational option --- test/handlers/cookie_informational_h.erl | 10 ++++++++ test/rfc6265bis_SUITE.erl | 41 +++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/handlers/cookie_informational_h.erl (limited to 'test') diff --git a/test/handlers/cookie_informational_h.erl b/test/handlers/cookie_informational_h.erl new file mode 100644 index 0000000..71e1b4a --- /dev/null +++ b/test/handlers/cookie_informational_h.erl @@ -0,0 +1,10 @@ +%% Feel free to use, reuse and abuse the code in this file. + +-module(cookie_informational_h). + +-export([init/2]). + +init(Req0, State) -> + cowboy_req:inform(103, #{<<"set-cookie">> => [<<"informational=1">>]}, Req0), + Req = cowboy_req:reply(204, #{<<"set-cookie">> => [<<"final=1">>]}, Req0), + {ok, Req, State}. diff --git a/test/rfc6265bis_SUITE.erl b/test/rfc6265bis_SUITE.erl index 0672fec..ecaf45f 100644 --- a/test/rfc6265bis_SUITE.erl +++ b/test/rfc6265bis_SUITE.erl @@ -79,9 +79,10 @@ init_routes() -> [ {"/cookie-set/[...]", cookie_set_h, []}, {"/cookies/resources/echo-cookie.html", cookie_echo_h, []}, {"/cookies/resources/set-cookie.html", cookie_set_h, []}, - {<<"/cookies/resources/echo.py">>, cookie_echo_h, []}, - {<<"/cookies/resources/set.py">>, cookie_set_h, []}, - {<<"/ws">>, ws_cookie_h, []} + {"/cookies/resources/echo.py", cookie_echo_h, []}, + {"/cookies/resources/set.py", cookie_set_h, []}, + {"/informational", cookie_informational_h, []}, + {"/ws", ws_cookie_h, []} ]} ]. @@ -141,6 +142,40 @@ do_request_test_file(Config) -> %% Tests. +dont_ignore_informational_set_cookie(Config) -> + doc("User agents may accept set-cookie headers " + "sent in informational responses. (RFC6265bis 3)"), + [{<<"informational">>, <<"1">>}, {<<"final">>, <<"1">>}] + = do_informational_set_cookie(Config, false). + +ignore_informational_set_cookie(Config) -> + doc("User agents may ignore set-cookie headers " + "sent in informational responses. (RFC6265bis 3)"), + [{<<"final">>, <<"1">>}] + = do_informational_set_cookie(Config, true). + +do_informational_set_cookie(Config, Boolean) -> + Protocol = config(protocol, Config), + {ok, ConnPid} = gun:open("localhost", config(port, Config), #{ + transport => config(transport, Config), + protocols => [Protocol], + cookie_store => gun_cookies_list:init(), + cookie_ignore_informational => Boolean + }), + {ok, Protocol} = gun:await_up(ConnPid), + StreamRef1 = gun:get(ConnPid, "/informational"), + {inform, 103, Headers1} = gun:await(ConnPid, StreamRef1), + ct:log("Headers1:~n~p", [Headers1]), + {response, fin, 204, Headers2} = gun:await(ConnPid, StreamRef1), + ct:log("Headers2:~n~p", [Headers2]), + StreamRef2 = gun:get(ConnPid, "/cookie-echo"), + {response, nofin, 200, _} = gun:await(ConnPid, StreamRef2), + {ok, Body2} = gun:await_body(ConnPid, StreamRef2), + ct:log("Body2:~n~p", [Body2]), + Res = cow_cookie:parse_cookie(Body2), + gun:close(ConnPid), + Res. + -define(HOST, "web-platform.test"). %% WPT: domain/domain-attribute-host-with-and-without-leading-period -- cgit v1.2.3