Skip to content

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

Allow the `BrokerProperties` header for webhooks to support Azure Service Bus

Patryk Zawadzkie127e68c4f12
diff --git a/CHANGELOG.md b/CHANGELOG.md
index caa81dc778..87fc80b90b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ All notable, unreleased changes to this project will be documented in this file.
- DB performance improvements in attribute dataloaders - #15474 by @AjmalPonneth
- Calculate order promotions in draft orders - #15459 by @zedzior
- Prevent name overwriting of Product Variants when Updating Product Types - #15670 by @teddyondieki
+- Added support for the `BrokerProperties` custom header to webhooks to support Azure Service Bus - #15899 by @patrys
# 3.19.0
diff --git a/saleor/app/tests/test_installation_utils.py b/saleor/app/tests/test_installation_utils.py
index f84de6365d..ceb438e01f 100644
--- a/saleor/app/tests/test_installation_utils.py
+++ b/saleor/app/tests/test_installation_utils.py
@@ -595,7 +595,7 @@ def test_install_app_webhook_incorrect_custom_headers(
assert "webhooks" in error_dict
assert error_dict["webhooks"][0].message == (
'Invalid custom headers: "InvalidKey" '
- 'does not match allowed key pattern: "X-*" or "Authorization*".'
+ 'does not match allowed key pattern: "X-*", "Authorization*", or "BrokerProperties".'
)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 76a5040265..46a58638a0 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -20652,7 +20652,7 @@ input WebhookUpdateInput @doc(category: "Webhooks") {
query: String
"""
- Custom headers, which will be added to HTTP request. There is a limitation of 5 headers per webhook and 998 characters per header.Only "X-*" and "Authorization*" keys are allowed.
+ Custom headers, which will be added to HTTP request. There is a limitation of 5 headers per webhook and 998 characters per header.Only `X-*`, `Authorization*`, and `BrokerProperties` keys are allowed.
Added in Saleor 3.12.
diff --git a/saleor/graphql/webhook/mutations/webhook_update.py b/saleor/graphql/webhook/mutations/webhook_update.py
index 0873db85de..d993218466 100644
--- a/saleor/graphql/webhook/mutations/webhook_update.py
+++ b/saleor/graphql/webhook/mutations/webhook_update.py
@@ -68,7 +68,7 @@ class WebhookUpdateInput(BaseInputObjectType):
description=f"Custom headers, which will be added to HTTP request. "
f"There is a limitation of {HEADERS_NUMBER_LIMIT} headers per webhook "
f"and {HEADERS_LENGTH_LIMIT} characters per header."
- f'Only "X-*" and "Authorization*" keys are allowed.'
+ f"Only `X-*`, `Authorization*`, and `BrokerProperties` keys are allowed."
+ ADDED_IN_312
+ PREVIEW_FEATURE,
required=False,
diff --git a/saleor/graphql/webhook/tests/mutations/test_webhook_create.py b/saleor/graphql/webhook/tests/mutations/test_webhook_create.py
index 9f034a2aa7..5715fc053c 100644
--- a/saleor/graphql/webhook/tests/mutations/test_webhook_create.py
+++ b/saleor/graphql/webhook/tests/mutations/test_webhook_create.py
@@ -349,7 +349,7 @@ def test_webhook_create_invalid_custom_headers(app_api_client):
assert error["field"] == "customHeaders"
assert (
error["message"] == '"DisallowedKey" does not match allowed key pattern: '
- '"X-*" or "Authorization*".'
+ '"X-*", "Authorization*", or "BrokerProperties".'
)
assert error["code"] == WebhookErrorCode.INVALID_CUSTOM_HEADERS.name
diff --git a/saleor/graphql/webhook/tests/mutations/test_webhook_update.py b/saleor/graphql/webhook/tests/mutations/test_webhook_update.py
index 8e6efe7b9f..c676d8f6e5 100644
--- a/saleor/graphql/webhook/tests/mutations/test_webhook_update.py
+++ b/saleor/graphql/webhook/tests/mutations/test_webhook_update.py
@@ -301,7 +301,7 @@ def test_webhook_update_invalid_custom_headers(
assert error["field"] == "customHeaders"
assert (
error["message"] == '"DisallowedKey" does not match allowed key pattern: '
- '"X-*" or "Authorization*".'
+ '"X-*", "Authorization*", or "BrokerProperties".'
)
assert error["code"] == WebhookErrorCode.INVALID_CUSTOM_HEADERS.name
diff --git a/saleor/webhook/tests/test_webhook_validators.py b/saleor/webhook/tests/test_webhook_validators.py
index 1d941d2dd6..5fe59cc006 100644
--- a/saleor/webhook/tests/test_webhook_validators.py
+++ b/saleor/webhook/tests/test_webhook_validators.py
@@ -24,7 +24,7 @@ from ..validators import (
),
(
{"Key": "Value"},
- '"Key" does not match allowed key pattern: "X-*" or "Authorization*".',
+ '"Key" does not match allowed key pattern: "X-*", "Authorization*", or "BrokerProperties".',
),
(
{"X-Key": 123},
@@ -49,12 +49,12 @@ from ..validators import (
),
(
{"ABCX-Key": "Value"},
- '"ABCX-Key" does not match allowed key pattern: "X-*" or "Authorization*".',
+ '"ABCX-Key" does not match allowed key pattern: "X-*", "Authorization*", or "BrokerProperties".',
),
(
{"ABCAuthorization-Key": "Value"},
'"ABCAuthorization-Key" does not match allowed key pattern:'
- ' "X-*" or "Authorization*".',
+ ' "X-*", "Authorization*", or "BrokerProperties".',
),
],
)
diff --git a/saleor/webhook/validators.py b/saleor/webhook/validators.py
index d9ffbfcacd..bf222d8a9b 100644
--- a/saleor/webhook/validators.py
+++ b/saleor/webhook/validators.py
@@ -39,11 +39,13 @@ def custom_headers_validator(headers: dict[str, str]) -> dict[str, str]:
raise ValidationError(f'Value "{value}" contains invalid character.')
if not (
- key.lower().startswith("x-") or key.lower().startswith("authorization")
+ key.lower().startswith("x-")
+ or key.lower().startswith("authorization")
+ or key.lower() == "brokerproperties"
):
raise ValidationError(
f'"{key}" does not match allowed key pattern: '
- f'"X-*" or "Authorization*".'
+ f'"X-*", "Authorization*", or "BrokerProperties".'
)
return {k.lower(): v for k, v in headers.items()}