Skip to content

Commit d2c4963

Browse files
committed
spec/cookie_spec: Add tests for tough cookies
1 parent 1206ba5 commit d2c4963

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec/cookie_spec.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,28 @@ describe("cookie module", function()
170170
assert.same("", s:lookup("example.com", "/", true, false))
171171
assert.same("foo=bar", s:lookup("example.com", "/", true, true))
172172
end)
173+
describe("tough cookies", function()
174+
it("enforces __Secure- prefix", function()
175+
local s = http_cookie.new_store()
176+
assert.falsy(s:store("example.com", "/", true, false, nil, http_cookie.parse_setcookie("__Secure-foo=bar; Secure")))
177+
assert.falsy(s:store("example.com", "/", true, false, nil, http_cookie.parse_setcookie("__Secure-foo=bar")))
178+
assert.falsy(s:store("example.com", "/", true, true, nil, http_cookie.parse_setcookie("__Secure-foo=bar;")))
179+
assert.truthy(s:store("example.com", "/", true, true, nil, http_cookie.parse_setcookie("__Secure-foo=bar; Secure")))
180+
end)
181+
it("enforces __Host- prefix", function()
182+
local s = http_cookie.new_store()
183+
-- Checks secure flag
184+
assert.falsy(s:store("example.com", "/", true, false, nil, http_cookie.parse_setcookie("__Host-foo=bar; Secure")))
185+
assert.falsy(s:store("example.com", "/", true, false, nil, http_cookie.parse_setcookie("__Host-foo=bar")))
186+
assert.falsy(s:store("example.com", "/", true, true, nil, http_cookie.parse_setcookie("__Host-foo=bar;")))
187+
-- Checks for host only flag
188+
assert.falsy(s:store("sub.example.com", "/", true, true, nil, http_cookie.parse_setcookie("__Host-foo=bar; Secure; Domain=example.com")))
189+
-- Checks that path is /
190+
assert.falsy(s:store("example.com", "/", true, true, nil, http_cookie.parse_setcookie("__Host-foo=bar; Secure; Path=/path")))
191+
-- Success case
192+
assert.truthy(s:store("example.com", "/", true, true, nil, http_cookie.parse_setcookie("__Host-foo=bar; Secure")))
193+
end)
194+
end)
173195
describe("cookie fixing mitigation", function()
174196
it("ignores already existing path", function()
175197
local s = http_cookie.new_store()

0 commit comments

Comments
 (0)