Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Apply changes after review

Maciej Korycinskib6a5e35edc6c
diff --git a/saleor/core/exceptions.py b/saleor/core/exceptions.py
index b960c5e161..8829435c3a 100644
--- a/saleor/core/exceptions.py
+++ b/saleor/core/exceptions.py
@@ -1,5 +1,3 @@
-from jwt.exceptions import PyJWTError
-
from ..checkout.error_codes import CheckoutErrorCode
@@ -41,7 +39,3 @@ class PermissionDenied(Exception):
if message is None:
message = default_message
super().__init__(message)
-
-
-class ExpiredUserSignatureError(PyJWTError):
- pass
diff --git a/saleor/core/jwt.py b/saleor/core/jwt.py
index e2d191912f..ef03296f2a 100644
--- a/saleor/core/jwt.py
+++ b/saleor/core/jwt.py
@@ -8,7 +8,6 @@ from django.core.handlers.wsgi import WSGIRequest
from jwt import InvalidTokenError
from ..account.models import User
-from .exceptions import ExpiredUserSignatureError
JWT_ALGORITHM = "HS256"
JWT_AUTH_HEADER = "HTTP_AUTHORIZATION"
@@ -101,7 +100,7 @@ def get_user_from_payload(payload: Dict[str, Any]) -> Optional[User]:
"Invalid token. Create new one by using tokenCreate mutation."
)
if user.jwt_token_key != user_jwt_token:
- raise ExpiredUserSignatureError(
+ raise InvalidTokenError(
"User requested to expire this token. Create new one by using tokenCreate "
"mutation."
)
diff --git a/saleor/core/tests/test_auth_backend.py b/saleor/core/tests/test_auth_backend.py
index 8bf0e00aa5..bb4320bee6 100644
--- a/saleor/core/tests/test_auth_backend.py
+++ b/saleor/core/tests/test_auth_backend.py
@@ -4,7 +4,6 @@ from freezegun import freeze_time
from jwt import ExpiredSignatureError, InvalidSignatureError, InvalidTokenError
from ..auth_backend import JSONWebTokenBackend
-from ..exceptions import ExpiredUserSignatureError
from ..jwt import (
JWT_ACCESS_TYPE,
JWT_ALGORITHM,
@@ -86,7 +85,7 @@ def test_user_deactivated_token(rf, staff_user):
staff_user.save()
request = rf.request(HTTP_AUTHORIZATION=f"JWT {access_token}")
backend = JSONWebTokenBackend()
- with pytest.raises(ExpiredUserSignatureError):
+ with pytest.raises(InvalidTokenError):
backend.authenticate(request)
diff --git a/saleor/graphql/account/tests/mutations/test_tokens_deactivate_all.py b/saleor/graphql/account/tests/mutations/test_tokens_deactivate_all.py
index 22606ed916..e18522c36b 100644
--- a/saleor/graphql/account/tests/mutations/test_tokens_deactivate_all.py
+++ b/saleor/graphql/account/tests/mutations/test_tokens_deactivate_all.py
@@ -48,7 +48,6 @@ def test_deactivate_all_user_tokens_access_token(user_api_client, customer_user)
user_api_client.token = token
response = user_api_client.post_graphql(MUTATION_DEACTIVATE_ALL_USER_TOKENS)
content = get_graphql_content(response)
-
errors = content["data"]["tokensDeactivateAll"]["accountErrors"]
assert not errors
@@ -57,7 +56,7 @@ def test_deactivate_all_user_tokens_access_token(user_api_client, customer_user)
content = json.loads(response.content.decode("utf8"))
assert len(content["errors"]) == 1
assert content["errors"][0]["extensions"]["exception"]["code"] == (
- "ExpiredUserSignatureError"
+ "InvalidTokenError"
)
assert content["data"]["me"] is None