|
4 | 4 | import os |
5 | 5 |
|
6 | 6 | class TestSettingsSecurity(unittest.TestCase): |
7 | | - def test_development_mode_allows_default_key(self): |
8 | | - """Test that development mode allows the default insecure key (with warning).""" |
| 7 | + def test_default_key_is_secure(self): |
| 8 | + """Test that by default, a secure random key is generated.""" |
9 | 9 | # Ensure environment is clean |
10 | 10 | if "ADAM_API_KEY" in os.environ: |
11 | 11 | del os.environ["ADAM_API_KEY"] |
12 | 12 |
|
13 | | - settings = Settings(environment="development") |
14 | | - self.assertEqual(settings.adam_api_key, "default-insecure-key-change-me") |
15 | | - self.assertEqual(settings.environment, "development") |
| 13 | + settings_1 = Settings(environment="development") |
| 14 | + settings_2 = Settings(environment="development") |
16 | 15 |
|
17 | | - def test_production_mode_blocks_default_key(self): |
18 | | - """Test that production mode raises ValueError if default key is used.""" |
19 | | - # Ensure environment is clean |
20 | | - if "ADAM_API_KEY" in os.environ: |
21 | | - del os.environ["ADAM_API_KEY"] |
22 | | - |
23 | | - with self.assertRaises(ValueError) as cm: |
24 | | - Settings(environment="production") |
25 | | - |
26 | | - self.assertIn("CRITICAL SECURITY ERROR", str(cm.exception)) |
| 16 | + self.assertNotEqual(settings_1.adam_api_key, "default-insecure-key-change-me") |
| 17 | + self.assertTrue(len(settings_1.adam_api_key) > 32) |
| 18 | + # Should generate a new key each time if not provided |
| 19 | + self.assertNotEqual(settings_1.adam_api_key, settings_2.adam_api_key) |
27 | 20 |
|
28 | 21 | def test_production_mode_allows_secure_key(self): |
29 | 22 | """Test that production mode allows a custom secure key.""" |
|
0 commit comments