修正跨平台部署审查用例
Some checks are pending
Security Checks / security (push) Waiting to run

This commit is contained in:
smail 2026-10-01 14:06:17 +08:00
parent c2b8cd0eed
commit 871ed0f07b
3 changed files with 19 additions and 6 deletions

View File

@ -17,12 +17,16 @@ SCRIPTS = BASE if (BASE / 'deploy_certificate.py').exists() else BASE.parents[1]
sys.path.insert(0, str(SCRIPTS)) sys.path.insert(0, str(SCRIPTS))
with patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': 'cdis.cn', 'SMAIL_WEB_DOMAIN': 'web.cdis.cn'}): if os.name == 'posix':
import deploy_certificate as deploy with patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': 'cdis.cn', 'SMAIL_WEB_DOMAIN': 'web.cdis.cn'}):
import renew_certificate as renew import deploy_certificate as deploy
import nginx_certificate_cutover as cutover import renew_certificate as renew
import nginx_certificate_cutover as cutover
else:
deploy = renew = cutover = None
@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix')
class DomainConfigurationTests(unittest.TestCase): class DomainConfigurationTests(unittest.TestCase):
def test_domain_requires_explicit_configuration(self): def test_domain_requires_explicit_configuration(self):
with patch.dict(os.environ, {}, clear=True), self.assertRaises(KeyError): with patch.dict(os.environ, {}, clear=True), self.assertRaises(KeyError):
@ -43,6 +47,7 @@ class DomainConfigurationTests(unittest.TestCase):
self.assertEqual(deploy.configured_domain('SMAIL_MAIL_DOMAIN'), 'new.example.test') self.assertEqual(deploy.configured_domain('SMAIL_MAIL_DOMAIN'), 'new.example.test')
@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix')
class CutoverTests(unittest.TestCase): class CutoverTests(unittest.TestCase):
def test_atomic_config_preserves_mode_under_restrictive_umask(self): def test_atomic_config_preserves_mode_under_restrictive_umask(self):
directory = Path(tempfile.mkdtemp(prefix='cutover-tests-', dir=Path.cwd())) directory = Path(tempfile.mkdtemp(prefix='cutover-tests-', dir=Path.cwd()))
@ -60,6 +65,7 @@ class CutoverTests(unittest.TestCase):
os.umask(previous) os.umask(previous)
@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix')
class RenewalTests(unittest.TestCase): class RenewalTests(unittest.TestCase):
def execute(self, callback, provider='alidns'): def execute(self, callback, provider='alidns'):
with patch.object(renew.os, 'geteuid', return_value=0), \ with patch.object(renew.os, 'geteuid', return_value=0), \
@ -164,6 +170,7 @@ class RenewalTests(unittest.TestCase):
renew.main() renew.main()
@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix')
class DeploymentTests(unittest.TestCase): class DeploymentTests(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):

View File

@ -13,10 +13,14 @@ from unittest.mock import patch
BASE = Path(__file__).resolve().parent BASE = Path(__file__).resolve().parent
SCRIPTS = BASE if (BASE / 'renew_certificate.py').exists() else BASE.parents[1] / 'deploy/nginx' SCRIPTS = BASE if (BASE / 'renew_certificate.py').exists() else BASE.parents[1] / 'deploy/nginx'
sys.path.insert(0, str(SCRIPTS)) sys.path.insert(0, str(SCRIPTS))
with patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': 'cdis.cn', 'SMAIL_WEB_DOMAIN': 'web.cdis.cn'}): if os.name == 'posix':
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
else:
renew = None
@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix')
class WebrootTests(unittest.TestCase): class WebrootTests(unittest.TestCase):
def setUp(self): def setUp(self):
self.directory = Path(tempfile.mkdtemp(prefix='webroot-tests-', dir=Path.cwd())) self.directory = Path(tempfile.mkdtemp(prefix='webroot-tests-', dir=Path.cwd()))

View File

@ -1,6 +1,7 @@
"""验证前端审查依赖的只读挂载范围,不启动本机应用。""" """验证前端审查依赖的只读挂载范围,不启动本机应用。"""
import importlib.util import importlib.util
import os
from pathlib import Path from pathlib import Path
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
@ -12,6 +13,7 @@ review = importlib.util.module_from_spec(spec)
spec.loader.exec_module(review) spec.loader.exec_module(review)
@unittest.skipUnless(os.name == 'posix', '前端隔离审查脚本仅支持 Linux/Unix')
class DependencyBindingsTest(unittest.TestCase): class DependencyBindingsTest(unittest.TestCase):
root = Path('/var/tmp/smail-review-current') root = Path('/var/tmp/smail-review-current')