From 871ed0f07b49a5bc2b12dc9afbdd6c9561ba76d6 Mon Sep 17 00:00:00 2001 From: smail Date: Thu, 1 Oct 2026 14:06:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B7=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=AE=A1=E6=9F=A5=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/deployment/test_certificate_renewal.py | 15 +++++++++++---- test/deployment/test_certificate_webroot.py | 8 ++++++-- test/deployment/test_frontend_review.py | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/test/deployment/test_certificate_renewal.py b/test/deployment/test_certificate_renewal.py index ee3f055..731ac40 100644 --- a/test/deployment/test_certificate_renewal.py +++ b/test/deployment/test_certificate_renewal.py @@ -17,12 +17,16 @@ SCRIPTS = BASE if (BASE / 'deploy_certificate.py').exists() else BASE.parents[1] sys.path.insert(0, str(SCRIPTS)) -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 +if os.name == 'posix': + 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 +else: + deploy = renew = cutover = None +@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix') class DomainConfigurationTests(unittest.TestCase): def test_domain_requires_explicit_configuration(self): 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') +@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix') class CutoverTests(unittest.TestCase): def test_atomic_config_preserves_mode_under_restrictive_umask(self): directory = Path(tempfile.mkdtemp(prefix='cutover-tests-', dir=Path.cwd())) @@ -60,6 +65,7 @@ class CutoverTests(unittest.TestCase): os.umask(previous) +@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix') class RenewalTests(unittest.TestCase): def execute(self, callback, provider='alidns'): with patch.object(renew.os, 'geteuid', return_value=0), \ @@ -164,6 +170,7 @@ class RenewalTests(unittest.TestCase): renew.main() +@unittest.skipUnless(os.name == 'posix', '证书部署脚本仅支持 Linux/Unix') class DeploymentTests(unittest.TestCase): @classmethod def setUpClass(cls): diff --git a/test/deployment/test_certificate_webroot.py b/test/deployment/test_certificate_webroot.py index b2a8289..7b833d3 100644 --- a/test/deployment/test_certificate_webroot.py +++ b/test/deployment/test_certificate_webroot.py @@ -13,10 +13,14 @@ 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)) -with patch.dict(os.environ, {'SMAIL_MAIL_DOMAIN': 'cdis.cn', 'SMAIL_WEB_DOMAIN': 'web.cdis.cn'}): - import renew_certificate as renew +if os.name == 'posix': + 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): def setUp(self): self.directory = Path(tempfile.mkdtemp(prefix='webroot-tests-', dir=Path.cwd())) diff --git a/test/deployment/test_frontend_review.py b/test/deployment/test_frontend_review.py index 0edf9eb..db9c264 100644 --- a/test/deployment/test_frontend_review.py +++ b/test/deployment/test_frontend_review.py @@ -1,6 +1,7 @@ """验证前端审查依赖的只读挂载范围,不启动本机应用。""" import importlib.util +import os from pathlib import Path import unittest from unittest.mock import patch @@ -12,6 +13,7 @@ review = importlib.util.module_from_spec(spec) spec.loader.exec_module(review) +@unittest.skipUnless(os.name == 'posix', '前端隔离审查脚本仅支持 Linux/Unix') class DependencyBindingsTest(unittest.TestCase): root = Path('/var/tmp/smail-review-current')