Skip to content

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

Fix cleaning manifest data during app instalation (#11327)

Iga Karbowiake5eb3d91fb16
diff --git a/saleor/app/manifest_validations.py b/saleor/app/manifest_validations.py
index 85c68775f9..820869fc9f 100644
--- a/saleor/app/manifest_validations.py
+++ b/saleor/app/manifest_validations.py
@@ -99,7 +99,8 @@ def clean_manifest_data(manifest_data):
validate_required_fields(manifest_data, errors)
try:
- _clean_app_url(manifest_data["tokenTargetUrl"])
+ if "tokenTargetUrl" in manifest_data:
+ _clean_app_url(manifest_data["tokenTargetUrl"])
except (ValidationError, AttributeError):
errors["tokenTargetUrl"].append(
ValidationError(
diff --git a/saleor/app/tests/test_installation_utils.py b/saleor/app/tests/test_installation_utils.py
index f99b822e03..b46e572a7f 100644
--- a/saleor/app/tests/test_installation_utils.py
+++ b/saleor/app/tests/test_installation_utils.py
@@ -407,3 +407,28 @@ def test_install_app_webhook_incorrect_query(
error_dict = excinfo.value.error_dict
assert "webhooks" in error_dict
assert error_dict["webhooks"][0].message == "Subscription query is not valid."
+
+
+def test_install_app_lack_of_token_target_url_in_manifest_data(
+ app_manifest, app_installation, monkeypatch, permission_manage_products
+):
+ # given
+ app_manifest.pop("tokenTargetUrl")
+
+ app_manifest["permissions"] = ["MANAGE_PRODUCTS"]
+ mocked_get_response = Mock()
+ mocked_get_response.json.return_value = app_manifest
+
+ monkeypatch.setattr(requests, "get", Mock(return_value=mocked_get_response))
+ mocked_post = Mock()
+ monkeypatch.setattr(requests, "post", mocked_post)
+
+ app_installation.permissions.set([permission_manage_products])
+
+ # when & then
+ with pytest.raises(ValidationError) as excinfo:
+ install_app(app_installation, activate=True)
+
+ error_dict = excinfo.value.error_dict
+ assert "tokenTargetUrl" in error_dict
+ assert error_dict["tokenTargetUrl"][0].message == "Field required."