fix(settings): 禁止 PP 隐式回落旧凭据配置
build / build (push) Successful in 1m58s

生效状态文件缺失时,扫描与取件仅在显式配置迁移路径时读取旧凭据;默认未配置状态与 API 一致。
新增缺失状态文件的回归,先复现旧凭据被隐式启用,再验证修复。

验证:PP 客户端 7 项隔离服务/配置回归通过;完整 make verify 退出 0,全部本地必需门禁通过。
This commit is contained in:
姚章浩
2026-11-17 19:32:17 +08:00
parent 3825859da6
commit d2f9060b33
2 changed files with 8 additions and 1 deletions
+4 -1
View File
@@ -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):
+4
View File
@@ -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()