Files
zulip/zerver/tests/test_server_settings.py
Zixuan James Li 059d0e7be8 settings: Make SHARED_SECRET mandatory.
This implements get_mandatory_secret that ensures SHARED_SECRET is
set when we hit zerver.decorator.authenticate_notify. To avoid getting
ZulipSettingsError when setting up the secrets, we set an environment
variable DISABLE_MANDATORY_SECRET_CHECK to skip the check and default
its value to an empty string.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-08-25 12:13:03 -07:00

21 lines
750 B
Python

import os
from unittest import mock
from zerver.lib.test_classes import ZulipTestCase
from zproject import config
class ConfigTest(ZulipTestCase):
def test_get_mandatory_secret_succeed(self) -> None:
secret = config.get_mandatory_secret("shared_secret")
self.assertGreater(len(secret), 0)
def test_get_mandatory_secret_failed(self) -> None:
with self.assertRaisesRegex(config.ZulipSettingsError, "nonexistent"):
config.get_mandatory_secret("nonexistent")
def test_disable_mandatory_secret_check(self) -> None:
with mock.patch.dict(os.environ, {"DISABLE_MANDATORY_SECRET_CHECK": "True"}):
secret = config.get_mandatory_secret("nonexistent")
self.assertEqual(secret, "")