Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
update_storage: Validate storage type correctly.
Anders Kaseorgc584462b32fe
diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.pyindex 69786402460..eba98544489 100644--- a/zerver/tests/test_service_bot_system.py+++ b/zerver/tests/test_service_bot_system.py@@ -299,7 +299,7 @@ class TestServiceBotStateHandler(ZulipTestCase):'storage': ujson.dumps({'foo': [1, 2, 3]}),}result = self.client_put('/json/bot_storage', params)- self.assert_json_error(result, "Value type is <class 'list'>, but should be str.")+ self.assert_json_error(result, "storage contains a value that is not a string")# Remove some entries.keys_to_remove = ['key 1', 'key 2']diff --git a/zerver/views/storage.py b/zerver/views/storage.pyindex 3772345cc0b..1a8e959531a 100644--- a/zerver/views/storage.py+++ b/zerver/views/storage.py@@ -16,11 +16,13 @@ from zerver.models import UserProfile@has_request_variables-def update_storage(request: HttpRequest, user_profile: UserProfile,- storage: Dict[str, str]=REQ(validator=check_dict([]))) -> HttpResponse:+def update_storage(+ request: HttpRequest, user_profile: UserProfile,+ storage: Dict[str, str]=REQ(validator=check_dict([], value_validator=check_string)),+) -> HttpResponse:try:set_bot_storage(user_profile, list(storage.items()))- except StateError as e:+ except StateError as e: # nocoveragereturn json_error(str(e))return json_success()