add.py (1129B)
1 import pytest 2 from tests.support.asserts import assert_error 3 4 5 @pytest.fixture(autouse=True) 6 def clean_up_cookies(session): 7 # Ensure that any test in the file does not navigate away once done with checking the cookies. 8 session.transport.send("DELETE", "session/%s/cookie" % session.session_id) 9 10 11 def add_cookie(session, cookie): 12 return session.transport.send( 13 "POST", 14 "session/{session_id}/cookie".format(**vars(session)), 15 {"cookie": cookie}, 16 ) 17 18 19 def test_invalid_samesite_none_and_not_secure(session, url): 20 session.url = url("/common/blank.html") 21 22 name = "foo" 23 value = "bar" 24 25 session.execute_script(f"document.cookie='{name}={value}'") 26 cookie = session.cookies(name) 27 28 # Set a cookie with exactly the same values as they are set with `document.cookie`. 29 result = add_cookie( 30 session, 31 { 32 "name": "foo2", 33 "value": cookie["value"], 34 "sameSite": cookie["sameSite"], 35 "secure": cookie["secure"], 36 "httpOnly": cookie["httpOnly"], 37 }, 38 ) 39 assert_error(result, "unable to set cookie")