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", ) self.assert_json_error( result, "Missing the HTTP event header 'X-Groove-Event'") realm = get_realm("zulip") webhook_bot = get_user("*****@*****.**", realm) webhook_bot.last_reminder = None notification_bot = self.notification_bot(realm) msg = self.get_last_message() expected_message = MISSING_EVENT_HEADER_MESSAGE.format( bot_name=webhook_bot.full_name, request_path="/api/v1/external/groove", header_name="X-Groove-Event", integration_name="Groove", support_email=FromAddress.SUPPORT, ).rstrip() if msg.sender.id != notification_bot.id: # nocoverage # This block seems to fire occasionally; debug output: print(msg) print(msg.content) self.assertEqual(msg.sender.id, notification_bot.id) self.assertEqual(msg.content, expected_message)
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") self.assert_json_error( result, "Missing the HTTP event header 'X_GROOVE_EVENT'") webhook_bot = get_user('*****@*****.**', get_realm('zulip')) webhook_bot.last_reminder = None notification_bot = self.notification_bot() msg = self.get_last_message() expected_message = MISSING_EVENT_HEADER_MESSAGE.format( bot_name=webhook_bot.full_name, request_path='/api/v1/external/groove', header_name='X_GROOVE_EVENT', integration_name='Groove', support_email=FromAddress.SUPPORT).rstrip() self.assertEqual(msg.sender.email, notification_bot.email) self.assertEqual(msg.content, expected_message)
def test_webhook_http_header_header_does_not_exist(self) -> None: webhook_bot = get_user('*****@*****.**', get_realm('zulip')) webhook_bot.last_reminder = None notification_bot = self.notification_bot() request = HostRequestMock() request.user = webhook_bot request.path = 'some/random/path' exception_msg = "Missing the HTTP event header 'X_CUSTOM_HEADER'" with self.assertRaisesRegex(MissingHTTPEventHeader, exception_msg): validate_extract_webhook_http_header(request, 'X_CUSTOM_HEADER', 'test_webhook') msg = self.get_last_message() expected_message = MISSING_EVENT_HEADER_MESSAGE.format( bot_name=webhook_bot.full_name, request_path=request.path, header_name='X_CUSTOM_HEADER', integration_name='test_webhook', support_email=FromAddress.SUPPORT).rstrip() self.assertEqual(msg.sender.email, notification_bot.email) self.assertEqual(msg.content, expected_message)
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") self.assert_json_error(result, "Missing the HTTP event header 'X_GROOVE_EVENT'") webhook_bot = get_user('*****@*****.**', get_realm('zulip')) webhook_bot.last_reminder = None notification_bot = self.notification_bot() msg = self.get_last_message() expected_message = MISSING_EVENT_HEADER_MESSAGE.format( bot_name=webhook_bot.full_name, request_path='/api/v1/external/groove', header_name='X_GROOVE_EVENT', integration_name='Groove', support_email=FromAddress.SUPPORT ).rstrip() if msg.sender.email != notification_bot.email: # nocoverage # This block seems to fire occasionally; debug output: print(msg) print(msg.content) self.assertEqual(msg.sender.email, notification_bot.email) self.assertEqual(msg.content, expected_message)
def test_webhook_http_header_header_does_not_exist(self) -> None: webhook_bot = get_user('*****@*****.**', get_realm('zulip')) webhook_bot.last_reminder = None notification_bot = self.notification_bot() request = HostRequestMock() request.user = webhook_bot request.path = 'some/random/path' exception_msg = "Missing the HTTP event header 'X_CUSTOM_HEADER'" with self.assertRaisesRegex(MissingHTTPEventHeader, exception_msg): validate_extract_webhook_http_header(request, 'X_CUSTOM_HEADER', 'test_webhook') msg = self.get_last_message() expected_message = MISSING_EVENT_HEADER_MESSAGE.format( bot_name=webhook_bot.full_name, request_path=request.path, header_name='X_CUSTOM_HEADER', integration_name='test_webhook', support_email=FromAddress.SUPPORT ).rstrip() self.assertEqual(msg.sender.email, notification_bot.email) self.assertEqual(msg.content, expected_message)
def test_webhook_http_header_header_does_not_exist(self) -> None: realm = get_realm("zulip") webhook_bot = get_user("*****@*****.**", realm) webhook_bot.last_reminder = None notification_bot = self.notification_bot(realm) request = HostRequestMock() request.user = webhook_bot request.path = "some/random/path" exception_msg = "Missing the HTTP event header 'X-Custom-Header'" with self.assertRaisesRegex(MissingHTTPEventHeader, exception_msg): validate_extract_webhook_http_header(request, "X-Custom-Header", "test_webhook") msg = self.get_last_message() expected_message = MISSING_EVENT_HEADER_MESSAGE.format( bot_name=webhook_bot.full_name, request_path=request.path, header_name="X-Custom-Header", integration_name="test_webhook", support_email=FromAddress.SUPPORT, ).rstrip() self.assertEqual(msg.sender.id, notification_bot.id) self.assertEqual(msg.content, expected_message)