mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	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>
		
			
				
	
	
		
			21 lines
		
	
	
		
			750 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			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, "")
 |