Skip to content

Commit 1223944

Browse files
committed
fixes test
1 parent 4aa3dd5 commit 1223944

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

supertokens_python/recipe/session/cookie_and_header.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def _set_access_token_in_response(
426426
# resulting in an infinite refresh loop. To fix this, users are asked to specify "older_cookie_domain" in
427427
# the config.
428428

429+
429430
# This function checks for multiple cookies with the same name and clears the cookies for the older domain.
430431
def clear_session_cookies_from_older_cookie_domain(
431432
request: BaseRequest, config: SessionConfig, user_context: Dict[str, Any]
@@ -463,9 +464,11 @@ def clear_session_cookies_from_older_cookie_domain(
463464
get_cookie_name_from_token_type(token_type),
464465
"",
465466
0,
466-
"refresh_token_path"
467-
if token_type == "refresh"
468-
else "access_token_path",
467+
(
468+
"refresh_token_path"
469+
if token_type == "refresh"
470+
else "access_token_path"
471+
),
469472
request,
470473
domain=config.older_cookie_domain,
471474
)
@@ -498,7 +501,7 @@ def _parse_cookie_string_from_request_header_allow_duplicates(
498501
for cookie_pair in cookie_pairs:
499502
name_value = cookie_pair.split("=")
500503
if len(name_value) != 2:
501-
raise Exception("Invalid cookie string in request header")
504+
continue
502505
name, value = unquote(name_value[0].strip()), unquote(name_value[1].strip())
503506
if name in cookies:
504507
cookies[name].append(value)

tests/Django/test_django.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ async def test_login_refresh(self):
177177

178178
request.COOKIES["sRefreshToken"] = cookies["sRefreshToken"]["value"]
179179
request.META["HTTP_ANTI_CSRF"] = response.headers["anti-csrf"]
180+
request.META["HTTP_COOKIE"] = (
181+
"sRefreshToken=" + cookies["sRefreshToken"]["value"]
182+
)
180183
temp = my_middleware(request)
181184
if not isawaitable(temp):
182185
raise Exception("Should never come here")
@@ -247,6 +250,7 @@ async def test_login_logout(self):
247250

248251
request.COOKIES["sAccessToken"] = cookies["sAccessToken"]["value"]
249252
request.META["HTTP_ANTI_CSRF"] = response.headers["anti-csrf"]
253+
request.META["HTTP_COOKIE"] = "sAccessToken=" + cookies["sAccessToken"]["value"]
250254
temp = my_middleware(request)
251255
if not isawaitable(temp):
252256
raise Exception("Should never come here")
@@ -301,13 +305,12 @@ async def test_login_handle(self):
301305

302306
request.COOKIES["sAccessToken"] = cookies["sAccessToken"]["value"]
303307
request.META["HTTP_ANTI_CSRF"] = response.headers["anti-csrf"]
308+
request.META["HTTP_COOKIE"] = "sAccessToken=" + cookies["sAccessToken"]["value"]
304309
temp = my_middleware(request)
305310
if not isawaitable(temp):
306311
raise Exception("Should never come here")
307312
response = await temp
308-
assert "s" in json.loads(
309-
response.content
310-
) # FIXME: Getting Unauthorized in body. Why?
313+
assert "s" in json.loads(response.content)
311314
handle_cookies = get_cookies(response)
312315

313316
assert not handle_cookies

0 commit comments

Comments
 (0)