Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

decorator: Move tornado notify `data` parameter to `REQ` framework.

Lauryn Menard8a0070ace7dc
diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py
index 645e69dd10f..427054f6a5b 100644
--- a/zerver/tests/test_event_system.py
+++ b/zerver/tests/test_event_system.py
@@ -227,6 +227,14 @@ class EventsEndpointTest(ZulipTestCase):
result = self.client_post_request("/notify_tornado", req)
self.assert_json_success(result)
+ post_data = dict(secret=settings.SHARED_SECRET)
+ req = HostRequestMock(post_data, tornado_handler=dummy_handler)
+ req.META["REMOTE_ADDR"] = "127.0.0.1"
+ with self.assertRaises(RequestVariableMissingError) as context:
+ result = self.client_post_request("/notify_tornado", req)
+ self.assertEqual(str(context.exception), "Missing 'data' argument")
+ self.assertEqual(context.exception.http_status_code, 400)
+
class GetEventsTest(ZulipTestCase):
def tornado_call(
diff --git a/zerver/tornado/views.py b/zerver/tornado/views.py
index 731893f6919..9ff22d236cd 100644
--- a/zerver/tornado/views.py
+++ b/zerver/tornado/views.py
@@ -1,7 +1,6 @@
import time
-from typing import Callable, Optional, Sequence, TypeVar
+from typing import Any, Callable, Mapping, Optional, Sequence, TypeVar
-import orjson
from asgiref.sync import async_to_sync
from django.http import HttpRequest, HttpResponse
from django.utils.translation import gettext as _
@@ -13,6 +12,7 @@ from zerver.lib.request import REQ, RequestNotes, has_request_variables
from zerver.lib.response import AsynchronousResponse, json_success
from zerver.lib.validator import (
check_bool,
+ check_dict,
check_int,
check_list,
check_string,
@@ -34,8 +34,11 @@ def in_tornado_thread(f: Callable[P, T]) -> Callable[P, T]:
@internal_notify_view(True)
-def notify(request: HttpRequest) -> HttpResponse:
- in_tornado_thread(process_notification)(orjson.loads(request.POST["data"]))
+@has_request_variables
+def notify(
+ request: HttpRequest, data: Mapping[str, Any] = REQ(json_validator=check_dict([]))
+) -> HttpResponse:
+ in_tornado_thread(process_notification)(data)
return json_success(request)