Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
support: Return json error if the POST request is invalid.
Vishnu KS18ad35013f92
diff --git a/analytics/tests/test_views.py b/analytics/tests/test_views.pyindex 5ef05fc8342..170c454edc1 100644--- a/analytics/tests/test_views.py+++ b/analytics/tests/test_views.py@@ -698,8 +698,8 @@ class TestSupportEndpoint(ZulipTestCase):self.assert_in_success_response(["Lear & Co. scrubbed"], result)with mock.patch("analytics.views.do_scrub_realm") as m:- with self.assertRaises(AssertionError):- result = self.client_post("/activity/support", {"realm_id": f"{lear_realm.id}"})+ result = self.client_post("/activity/support", {"realm_id": f"{lear_realm.id}"})+ self.assert_json_error(result, "Invalid parameters")m.assert_not_called()class TestGetChartDataHelpers(ZulipTestCase):diff --git a/analytics/views.py b/analytics/views.pyindex 93aefd2acba..c8df5a6d9ef 100644--- a/analytics/views.py+++ b/analytics/views.py@@ -53,7 +53,7 @@ from zerver.lib.actions import (from zerver.lib.exceptions import JsonableErrorfrom zerver.lib.realm_icon import realm_icon_urlfrom zerver.lib.request import REQ, has_request_variables-from zerver.lib.response import json_success+from zerver.lib.response import json_error, json_successfrom zerver.lib.subdomains import get_subdomain_from_hostnamefrom zerver.lib.timestamp import convert_to_UTC, timestamp_to_datetimefrom zerver.lib.validator import to_non_negative_int@@ -1125,7 +1125,8 @@ def support(request: HttpRequest) -> HttpResponse:keys = set(request.POST.keys())if "csrfmiddlewaretoken" in keys:keys.remove("csrfmiddlewaretoken")- assert(len(keys) == 2)+ if len(keys) != 2:+ return json_error(_("Invalid parameters"))realm_id = request.POST.get("realm_id")realm = Realm.objects.get(id=realm_id)