webhooks: Make MissingHTTPEventHeaderError a WebhookError.

Specifically, an AnomalousWebhookPayloadError.
This commit is contained in:
Alex Vandiver 2023-10-12 13:54:34 +00:00 committed by Tim Abbott
parent 558a47af82
commit bda6a4b7e4
2 changed files with 14 additions and 7 deletions

View File

@ -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"]

View File

@ -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")