statuspage: Raise AnomalousWebhookPayloadError on other events.

Their documentation only describes these two event types.
This commit is contained in:
Alex Vandiver
2023-10-05 22:17:52 +00:00
committed by Tim Abbott
parent bda6a4b7e4
commit c4085d1b8a
2 changed files with 12 additions and 2 deletions

View File

@@ -43,3 +43,13 @@ class StatuspageHookTests(WebhookTestCase):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def test_statuspage_anomalous_payload(self) -> None:
result = self.client_post(
self.url,
{},
content_type="application/json",
)
self.assert_json_error(
result, "Unable to parse request: Did Statuspage generate this event?", 400
)

View File

@@ -2,7 +2,7 @@
from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
from zerver.lib.exceptions import AnomalousWebhookPayloadError
from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
from zerver.lib.validator import WildValue, check_string
@@ -69,7 +69,7 @@ def api_statuspage_webhook(
topic = get_component_topic(payload)
body = get_components_update_body(payload)
else:
raise UnsupportedWebhookEventTypeError("unknown-event")
raise AnomalousWebhookPayloadError
check_send_webhook_message(request, user_profile, topic, body, event)
return json_success(request)