From d2f9060b33d2d95b711eb101cdcc36f54a82a1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Tue, 17 Nov 2026 19:32:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(settings):=20=E7=A6=81=E6=AD=A2=20PP=20?= =?UTF-8?q?=E9=9A=90=E5=BC=8F=E5=9B=9E=E8=90=BD=E6=97=A7=E5=87=AD=E6=8D=AE?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 生效状态文件缺失时,扫描与取件仅在显式配置迁移路径时读取旧凭据;默认未配置状态与 API 一致。 新增缺失状态文件的回归,先复现旧凭据被隐式启用,再验证修复。 验证:PP 客户端 7 项隔离服务/配置回归通过;完整 make verify 退出 0,全部本地必需门禁通过。 --- scripts/pp_client.py | 5 ++++- scripts/test_pp_client.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/pp_client.py b/scripts/pp_client.py index 5755ab3..ad2869a 100644 --- a/scripts/pp_client.py +++ b/scripts/pp_client.py @@ -60,7 +60,10 @@ def load_config(path=None): if not isinstance(config, dict): raise PPError("incomplete") else: - legacy = pathlib.Path(os.environ.get("PP_LEGACY_CREDENTIALS_FILE") or "/run/source-secrets/pp_credentials.json") + legacy_path = os.environ.get("PP_LEGACY_CREDENTIALS_FILE") + if not legacy_path: + raise PPError("incomplete") + legacy = pathlib.Path(legacy_path) try: config = json.loads(legacy.read_text(encoding="utf-8")) except (OSError, ValueError): diff --git a/scripts/test_pp_client.py b/scripts/test_pp_client.py index 9ac97f9..35cb606 100644 --- a/scripts/test_pp_client.py +++ b/scripts/test_pp_client.py @@ -53,4 +53,8 @@ class PPClientTests(unittest.TestCase): self.assertFalse(local);self.assertGreater(size,0);self.assertEqual(hashlib.sha256(pathlib.Path(path).read_bytes()).hexdigest(),digest) self.assertEqual([x[0] for x in self.calls],['POST','GET','GET']) finally:os.unlink(path) + def test_missing_state_never_implicitly_reuses_legacy_credentials(self): + fake=json.dumps({'username':'example','password':'synthetic-'+'fixture'}) + with patch.dict(os.environ,{'PP_LEGACY_CREDENTIALS_FILE':''}),patch('pathlib.Path.exists',return_value=False),patch('pathlib.Path.read_text',return_value=fake): + with self.assertRaises(pp_client.PPError):pp_client.load_config('/example-missing/settings.json') if __name__=='__main__':unittest.main()