mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 00:23:49 +00:00
webhooks/clubhouse: Ignore requests with empty request body.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from mock import MagicMock, patch
|
||||
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
@@ -193,3 +194,10 @@ class ClubhouseWebhookTest(WebhookTestCase):
|
||||
expected_message = u"The type of the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was changed from **feature** to **bug**."
|
||||
self.send_and_test_stream_message('story_update_change_type', "Add cool feature!",
|
||||
expected_message)
|
||||
|
||||
@patch('zerver.lib.webhooks.common.check_send_webhook_message')
|
||||
def test_empty_post_request_body_ignore(self, check_send_webhook_message_mock: MagicMock) -> None:
|
||||
payload = json.dumps(None)
|
||||
result = self.client_post(self.url, payload, content_type="application/json")
|
||||
self.assertFalse(check_send_webhook_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
|
||||
@@ -444,6 +444,13 @@ def api_clubhouse_webhook(
|
||||
payload: Dict[str, Any]=REQ(argument_type='body')
|
||||
) -> HttpResponse:
|
||||
|
||||
# Clubhouse has a tendency to send empty POST requests to
|
||||
# third-party endpoints. It is unclear as to which event type
|
||||
# such requests correspond to. So, it is best to ignore such
|
||||
# requests for now.
|
||||
if payload is None:
|
||||
return json_success()
|
||||
|
||||
body_func = get_body_function_based_on_type(payload)
|
||||
topic_func = get_topic_function_based_on_type(payload)
|
||||
topic = topic_func(payload)
|
||||
|
||||
Reference in New Issue
Block a user