Skip to content

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

Allow to fetch anonymous checkout.user as an anymous user

Maciej Korycinskidfd40338d7dd
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.py
index a8eb93a899..daf829b4df 100644
--- a/saleor/graphql/checkout/tests/test_checkout.py
+++ b/saleor/graphql/checkout/tests/test_checkout.py
@@ -3363,11 +3363,36 @@ QUERY_CHECKOUT_USER_ID = """
"""
-def test_anonymous_client_cant_fetch_checkout_user(api_client, checkout):
+def test_anonymous_client_can_fetch_anonymoues_checkout_user(api_client, checkout):
+ # given
query = QUERY_CHECKOUT_USER_ID
variables = {"token": str(checkout.token)}
+
+ # when
response = api_client.post_graphql(query, variables)
- assert_no_permission(response)
+
+ # then
+
+ content = get_graphql_content(response)
+ assert not content["data"]["checkout"]["user"]
+
+
+def test_anonymous_client_cant_fetch_checkout_with_attached_user(
+ api_client, checkout, customer_user
+):
+ # given
+ checkout.user = customer_user
+ checkout.save()
+
+ query = QUERY_CHECKOUT_USER_ID
+ variables = {"token": str(checkout.token)}
+
+ # when
+ response = api_client.post_graphql(query, variables)
+
+ # then
+ content = get_graphql_content(response)
+ assert not content["data"]["checkout"]
def test_authorized_access_to_checkout_user_as_customer(
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index 63e1d10764..b6ba85f80f 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -302,6 +302,8 @@ class Checkout(ModelObjectType):
@staticmethod
def resolve_user(root: models.Checkout, info):
+ if not root.user_id:
+ return None
requestor = get_user_or_app_from_context(info.context)
check_requestor_access(requestor, root.user, AccountPermissions.MANAGE_USERS)
return root.user