Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

webhooks: Make MissingHTTPEventHeaderError a WebhookError.

Alex Vandiverbda6a4b7e461
diff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.py
index 94ec68892fd..a1c22a848e0 100644
--- a/zerver/lib/webhooks/common.py
+++ b/zerver/lib/webhooks/common.py
@@ -15,7 +15,12 @@ from zerver.actions.message_send import (
check_send_stream_message_by_id,
send_rate_limited_pm_notification_to_bot_owner,
)
-from zerver.lib.exceptions import ErrorCode, JsonableError, StreamDoesNotExistError
+from zerver.lib.exceptions import (
+ AnomalousWebhookPayloadError,
+ ErrorCode,
+ JsonableError,
+ StreamDoesNotExistError,
+)
from zerver.lib.request import RequestNotes
from zerver.lib.send_email import FromAddress
from zerver.lib.timestamp import timestamp_to_datetime
@@ -61,7 +66,7 @@ def notify_bot_owner_about_invalid_json(
)
-class MissingHTTPEventHeaderError(JsonableError):
+class MissingHTTPEventHeaderError(AnomalousWebhookPayloadError):
code = ErrorCode.MISSING_HTTP_EVENT_HEADER
data_fields = ["header"]
diff --git a/zerver/tests/test_webhooks_common.py b/zerver/tests/test_webhooks_common.py
index 4acc14f649b..b4966788a71 100644
--- a/zerver/tests/test_webhooks_common.py
+++ b/zerver/tests/test_webhooks_common.py
@@ -185,11 +185,13 @@ class MissingEventHeaderTestCase(WebhookTestCase):
# an actual webhook, instead of just making a mock
def test_missing_event_header(self) -> None:
self.subscribe(self.test_user, self.STREAM_NAME)
- result = self.client_post(
- self.url,
- self.get_body("ticket_state_changed"),
- content_type="application/x-www-form-urlencoded",
- )
+ with self.assertLogs("zulip.zerver.webhooks.anomalous", level="INFO") as webhook_logs:
+ result = self.client_post(
+ self.url,
+ self.get_body("ticket_state_changed"),
+ content_type="application/x-www-form-urlencoded",
+ )
+ self.assertTrue("Missing the HTTP event header 'X-Groove-Event'" in webhook_logs.output[0])
self.assert_json_error(result, "Missing the HTTP event header 'X-Groove-Event'")
realm = get_realm("zulip")