From 7b3f4755ffe14f4cf8218348cdb0607366743c55 Mon Sep 17 00:00:00 2001 From: Pragati Agrawal Date: Sun, 21 Jun 2020 14:20:01 +0530 Subject: [PATCH] streams: Fix bug that allows 0 value for message_retention_days. --- zerver/tests/test_subs.py | 4 ++++ zerver/views/streams.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 3b5c001742..7b98bb4fdf 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -938,6 +938,10 @@ class StreamAdminTest(ZulipTestCase): {'message_retention_days': ujson.dumps(-1)}) self.assert_json_error(result, "Bad value for 'message_retention_days': -1") + result = self.client_patch(f'/json/streams/{stream.id}', + {'message_retention_days': ujson.dumps(0)}) + self.assert_json_error(result, "Bad value for 'message_retention_days': 0") + def test_change_stream_message_retention_days_requires_realm_owner(self) -> None: user_profile = self.example_user('iago') self.login_user(user_profile) diff --git a/zerver/views/streams.py b/zerver/views/streams.py index 8671cedfc9..608dab1424 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -134,7 +134,7 @@ def parse_message_retention_days(value: Union[int, str]) -> Optional[int]: return -1 if value == "realm_default": return None - if isinstance(value, str) or value < 0: + if isinstance(value, str) or value <= 0: raise RequestVariableConversionError('message_retention_days', value) assert isinstance(value, int) return value