Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Advisory fix merx-280.
zedzior36699c6f5c99
diff --git a/saleor/graphql/account/mutations/authentication/refresh_token.py b/saleor/graphql/account/mutations/authentication/refresh_token.pyindex cf4fb63484..b461fffc36 100644--- a/saleor/graphql/account/mutations/authentication/refresh_token.py+++ b/saleor/graphql/account/mutations/authentication/refresh_token.py@@ -58,14 +58,13 @@ class RefreshToken(BaseMutation):cls, info: ResolveInfo, refresh_token: Optional[str] = None) -> Optional[str]:request = info.context- refresh_token = refresh_token or request.COOKIES.get(- JWT_REFRESH_TOKEN_COOKIE_NAME, None- )+ if refresh_token is None:+ refresh_token = request.COOKIES.get(JWT_REFRESH_TOKEN_COOKIE_NAME, None)return refresh_token@classmethoddef clean_refresh_token(cls, refresh_token):- if not refresh_token:+ if refresh_token is None:raise ValidationError({"refresh_token": ValidationError(diff --git a/saleor/graphql/account/tests/mutations/authentication/test_token_refresh.py b/saleor/graphql/account/tests/mutations/authentication/test_token_refresh.pyindex e969dbcbf4..f0baffa79d 100644--- a/saleor/graphql/account/tests/mutations/authentication/test_token_refresh.py+++ b/saleor/graphql/account/tests/mutations/authentication/test_token_refresh.py@@ -1,5 +1,6 @@from datetime import datetime+import pytestfrom django.urls import reversefrom freezegun import freeze_time@@ -269,3 +270,25 @@ def test_refresh_token_when_user_deactivated_token(api_client, customer_user):assert not data["token"]assert len(errors) == 1assert errors[0]["code"] == AccountErrorCode.JWT_INVALID_TOKEN.name++[email protected]("token", ["incorrect-token", ""])+def test_refresh_token_incorrect_token_provided(api_client, customer_user, token):+ # given+ csrf_token = _get_new_csrf_token()+ refresh_token = create_refresh_token(customer_user, {"csrfToken": csrf_token})+ api_client.cookies[JWT_REFRESH_TOKEN_COOKIE_NAME] = refresh_token+ api_client.cookies[JWT_REFRESH_TOKEN_COOKIE_NAME]["httponly"] = True++ variables = {"token": token, "csrf_token": csrf_token}++ # when+ response = api_client.post_graphql(MUTATION_TOKEN_REFRESH, variables)+ content = get_graphql_content(response)++ # then+ data = content["data"]["tokenRefresh"]+ errors = data["errors"]+ assert not data.get("token")+ assert len(errors) == 1+ assert errors[0]["code"] == AccountErrorCode.JWT_DECODE_ERROR.name