diff --git a/zerver/webhooks/clubhouse/tests.py b/zerver/webhooks/clubhouse/tests.py index d7b44fa17a..2e978c274d 100644 --- a/zerver/webhooks/clubhouse/tests.py +++ b/zerver/webhooks/clubhouse/tests.py @@ -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) diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.py index 1c95fd972f..9d433eb73a 100644 --- a/zerver/webhooks/clubhouse/view.py +++ b/zerver/webhooks/clubhouse/view.py @@ -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)