Skip to content

Commit ee61e94

Browse files
Allows None to be set for the sameSite attribute (#9771)
* Allows None to be set for the sameSite attribute * Fixes formatting Co-authored-by: David Burns <david.burns@theautomatedtester.co.uk>
1 parent 0101ad4 commit ee61e94

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ def add_cookie(self, cookie_dict) -> None:
11171117
11181118
"""
11191119
if 'sameSite' in cookie_dict:
1120-
assert cookie_dict['sameSite'] in ['Strict', 'Lax']
1120+
assert cookie_dict['sameSite'] in ['Strict', 'Lax', 'None']
11211121
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
11221122
else:
11231123
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})

py/test/selenium/webdriver/common/cookie_tests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def same_site_cookie_lax(webserver):
5757
return same_site_cookie_lax
5858

5959

60+
@pytest.fixture
61+
def same_site_cookie_none(webserver):
62+
same_site_cookie_none = {
63+
'name': 'foo',
64+
'value': 'bar',
65+
'path': '/',
66+
'domain': webserver.host,
67+
'sameSite': 'None',
68+
'secure': True}
69+
return same_site_cookie_none
70+
71+
6072
@pytest.fixture(autouse=True)
6173
def pages(request, driver, pages):
6274
pages.load('simpleTest.html')
@@ -88,6 +100,15 @@ def testAddCookieSameSiteLax(same_site_cookie_lax, driver):
88100
assert 'sameSite' in returned and returned['sameSite'] == 'Lax'
89101

90102

103+
@pytest.mark.xfail_firefox(reason='sameSite cookie attribute not implemented')
104+
@pytest.mark.xfail_remote(reason='sameSite cookie attribute not implemented')
105+
@pytest.mark.xfail_safari
106+
def testAddCookieSameSiteNone(same_site_cookie_none, driver):
107+
driver.add_cookie(same_site_cookie_none)
108+
# Note that insecure sites (http:) can't set cookies with the Secure directive.
109+
# driver.get_cookie would return None
110+
111+
91112
@pytest.mark.xfail_ie
92113
@pytest.mark.xfail_safari
93114
def testAddingACookieThatExpiredInThePast(cookie, driver):

0 commit comments

Comments
 (0)