Skip to content

Commit 400a4fe

Browse files
committed
test: pin the origin check on refresh and logout
Refresh and logout get the cross-site check whatever the SameSite setting, a refused request leaves the cookies alone, and neither route is held to the content-type gate. Refs #25
1 parent b55f8b3 commit 400a4fe

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎tests/test_adapter.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,29 @@ def test_a_body_less_form_post_does_not_reach_a_cookie_route(
642642
assert not api.calls_to("POST", path)
643643

644644

645+
@pytest.mark.parametrize("same_site", ["Lax", "Strict", "None"])
646+
@pytest.mark.parametrize(("method", "path"), [("POST", "/refresh"), ("DELETE", "/logout")])
647+
def test_refresh_and_logout_get_the_origin_check_and_keep_the_cookies(
648+
api: FakeApi, same_site: str, method: str, path: str
649+
) -> None:
650+
api.on("POST", "/refresh", respond(200, session()))
651+
api.on("DELETE", "/logout", respond(204, None))
652+
adapter = api.adapter(allowed_origins=[APP], same_site=same_site)
653+
for headers in (
654+
{"sec-fetch-site": "cross-site"},
655+
{"sec-fetch-site": "same-site", "origin": SIBLING},
656+
{"origin": SIBLING},
657+
):
658+
r = call(adapter, method, path, content_type=None, cookie=REFRESH, headers=headers)
659+
assert (r.status, r.body) == (403, {"error": "cross_site_request_blocked"}), headers
660+
assert not r.cookies, "a refused request must not clear the session"
661+
assert not api.calls_to(method, path)
662+
663+
# Exempt from the content-type gate: the client sends both with no body.
664+
r = call(adapter, method, path, content_type=None, cookie=REFRESH)
665+
assert r.status != 415, r.text
666+
667+
645668
def test_a_state_change_with_no_body_needs_json_or_the_transport_header(api: FakeApi) -> None:
646669
api.on("POST", "/recovery-codes", respond(200, {"ok": True}))
647670
api.on("GET", "/recovery-codes", respond(200, {"ok": True}))

0 commit comments

Comments
 (0)