mirror of https://github.com/zulip/zulip.git
webhooks: Make MissingHTTPEventHeaderError a WebhookError.
Specifically, an AnomalousWebhookPayloadError.
This commit is contained in:
parent
558a47af82
commit
bda6a4b7e4
|
@ -15,7 +15,12 @@ from zerver.actions.message_send import (
|
||||||
check_send_stream_message_by_id,
|
check_send_stream_message_by_id,
|
||||||
send_rate_limited_pm_notification_to_bot_owner,
|
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.request import RequestNotes
|
||||||
from zerver.lib.send_email import FromAddress
|
from zerver.lib.send_email import FromAddress
|
||||||
from zerver.lib.timestamp import timestamp_to_datetime
|
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
|
code = ErrorCode.MISSING_HTTP_EVENT_HEADER
|
||||||
data_fields = ["header"]
|
data_fields = ["header"]
|
||||||
|
|
||||||
|
|
|
@ -185,11 +185,13 @@ class MissingEventHeaderTestCase(WebhookTestCase):
|
||||||
# an actual webhook, instead of just making a mock
|
# an actual webhook, instead of just making a mock
|
||||||
def test_missing_event_header(self) -> None:
|
def test_missing_event_header(self) -> None:
|
||||||
self.subscribe(self.test_user, self.STREAM_NAME)
|
self.subscribe(self.test_user, self.STREAM_NAME)
|
||||||
result = self.client_post(
|
with self.assertLogs("zulip.zerver.webhooks.anomalous", level="INFO") as webhook_logs:
|
||||||
self.url,
|
result = self.client_post(
|
||||||
self.get_body("ticket_state_changed"),
|
self.url,
|
||||||
content_type="application/x-www-form-urlencoded",
|
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'")
|
self.assert_json_error(result, "Missing the HTTP event header 'X-Groove-Event'")
|
||||||
|
|
||||||
realm = get_realm("zulip")
|
realm = get_realm("zulip")
|
||||||
|
|
Loading…
Reference in New Issue