Browse Source

fix(tests): load adversarial PEM markers from fixture file

Keep BEGIN PRIVATE KEY bytes out of packaged unit-test sources so
review-compact content secret scan stays green.

Co-authored-by: Cursor <cursoragent@cursor.com>
root 3 tháng trước cách đây
mục cha
commit
d5cbc67190

+ 2 - 2
tests/unit/package_review_compact_contract.py

@@ -187,7 +187,7 @@ def assert_no_full_git_bundle(members: list[str], *, testcase) -> None:
     )
 
 
-def _adversarial_private_key_bytes() -> bytes:
+def adversarial_private_key_bytes() -> bytes:
     """Load PEM-like fixture bytes without embedding secret markers in this module.
 
     The payload file basename ``id_ed25519`` is path-excluded from packaging; keeping
@@ -213,7 +213,7 @@ def adversarial_fixture_relatives() -> dict[str, bytes]:
         "anlogic_cd/installer/setup.exe": b"MZADV-INSTALLER",
         "reference/original/local_archives/Anlogic.lic": b"ADV-LICENSE-KEY\n",
         "config/.env": b"SECRET=should-never-pack\n",
-        "secrets/id_ed25519": _adversarial_private_key_bytes(),
+        "secrets/id_ed25519": adversarial_private_key_bytes(),
         "node_modules/left-pad/index.js": b"module.exports=function(){}\n",
         ".venv/bin/python": b"#!/adversarial-venv\n",
         "venv/lib/site.py": b"# adversarial venv\n",

+ 3 - 2
tests/unit/test_package_adversarial_compact.py

@@ -27,6 +27,7 @@ from package_review_compact_contract import (  # noqa: E402
     DEFAULT_REVIEW_COMPACT_INCLUDE_GIT_BUNDLE,
     REVIEW_COMPACT_PROFILE,
     adversarial_fixture_relatives,
+    adversarial_private_key_bytes,
     assert_no_full_git_bundle,
     handoff_profiles,
     intended_review_compact_exclusion_reason,
@@ -295,7 +296,7 @@ class TipFailClosedAdversarialTests(unittest.TestCase):
 
     def test_private_key_pem_content_fails_closed(self) -> None:
         handoff = load_handoff()
-        marker = b"-----BEGIN PRIVATE KEY-----\nsecret\n-----END PRIVATE KEY-----\n"
+        marker = adversarial_private_key_bytes()
         with self.assertRaises(handoff.PackagingError):
             handoff.scan_secret_markers(marker, b"", "docs/leaked.pem")
 
@@ -353,7 +354,7 @@ class TipFailClosedAdversarialTests(unittest.TestCase):
 
     def test_nested_archive_secret_fails_closed_on_audit(self) -> None:
         handoff = load_handoff()
-        marker = b"-----BEGIN PRIVATE KEY-----\nsecret\n-----END PRIVATE KEY-----\n"
+        marker = adversarial_private_key_bytes()
         with tempfile.TemporaryDirectory() as tmp:
             source = Path(tmp) / "source"
             buf_path = source / "docs" / "nested-secret.bin"