移除部署域名和初始化账号默认值

This commit is contained in:
xuans committed 2026-10-01 13:52:13 +08:00
1 parent c44f639328
commit 843ca39ae7
8 files changed
+59 -17

No files matched your search

+23 -2
View File
@@ -17,11 +17,32 @@ SCRIPTS = BASE if (BASE / 'deploy_certificate.py').exists() else BASE.parents[1]
sys.path.insert(0, str(SCRIPTS))
import deploy_certificate as deploy
import renew_certificate as renew
with patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': 'cdis.cn', 'SMAIL_WEB_DOMAIN': 'web.cdis.cn'}):
import deploy_certificate as deploy
import renew_certificate as renew
import nginx_certificate_cutover as cutover
class DomainConfigurationTests(unittest.TestCase):
def test_domain_requires_explicit_configuration(self):
with patch.dict(os.environ, {}, clear=True), self.assertRaises(KeyError):
deploy.configured_domain('SMAIL_MAIL_DOMAIN')
def test_domain_rejects_invalid_input(self):
for value in ('', ' ', 'localhost', '../example.test', 'https://example.test',
'*.example.test', 'example.test:443', 'example..test',
'-mail.example.test', 'mail-.example.test',
'a' * 64 + '.test', '.'.join(['a' * 63] * 4)):
with self.subTest(value=value), \
patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': value}), \
self.assertRaises(ValueError):
deploy.configured_domain('SMAIL_MAIL_DOMAIN')
def test_domain_uses_user_configuration(self):
with patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': ' New.Example.Test '}):
self.assertEqual(deploy.configured_domain('SMAIL_MAIL_DOMAIN'), 'new.example.test')
class CutoverTests(unittest.TestCase):
def test_atomic_config_preserves_mode_under_restrictive_umask(self):
directory = Path(tempfile.mkdtemp(prefix='cutover-tests-', dir=Path.cwd()))
+2 -1
View File
@@ -13,7 +13,8 @@ from unittest.mock import patch
BASE = Path(__file__).resolve().parent
SCRIPTS = BASE if (BASE / 'renew_certificate.py').exists() else BASE.parents[1] / 'deploy/nginx'
sys.path.insert(0, str(SCRIPTS))
import renew_certificate as renew
with patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': 'cdis.cn', 'SMAIL_WEB_DOMAIN': 'web.cdis.cn'}):
import renew_certificate as renew
class WebrootTests(unittest.TestCase):
+5 -3
View File
@@ -18,9 +18,11 @@ class DomainAcceptanceTest(unittest.TestCase):
self.assertNotIn('return 308 https://__SMAIL_MAIL_DOMAIN__$request_uri;', NGINX)
def test_certificate_requests_root_and_wildcard(self):
self.assertIn("DOMAINS = ('cdis.cn', '*.cdis.cn')", CERTIFICATE)
self.assertIn("CERTIFICATE_SNI = 'web.cdis.cn'", CERTIFICATE)
self.assertIn("'web.cdis.cn'", CERTIFICATE)
self.assertIn("DOMAINS = (MAIL_DOMAIN, '*.' + MAIL_DOMAIN)", CERTIFICATE)
self.assertIn("configured_domain('SMAIL_MAIL_DOMAIN')", CERTIFICATE)
self.assertIn("configured_domain('SMAIL_WEB_DOMAIN')", CERTIFICATE)
self.assertNotIn('cdis.cn', CERTIFICATE)
self.assertIn("any(domain.startswith('*.') for domain in DOMAINS)", RENEWAL)
self.assertIn('DOMAINS = deploy.DOMAINS', RENEWAL)