mcp-sandbox-authority-boundary-profile / scripts /test_evidence_bindings.py
Michael Saleme
fix: reconcile v0.2.0 evidence release controls
347662e unverified
Raw History Blame
2.17 kB
#!/usr/bin/env python3
"""Positive and negative controls for the released evidence-binding verifier."""
from __future__ import annotations
import json
import shutil
import subprocess
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
VERIFY = ROOT / "scripts" / "verify_evidence_bindings.py"
def fixture_copy(parent: Path) -> Path:
fixture = parent / "fixture"
shutil.copytree(ROOT, fixture, ignore=shutil.ignore_patterns(".git", "artifacts"))
return fixture
def receipt_path(fixture: Path, value: str) -> None:
index_path = fixture / "evidence" / "evidence-index-v0.2.0.json"
index = json.loads(index_path.read_text())
next(receipt for receipt in index["receipts"] if receipt["case_id"] == "RS-01")["path"] = value
index_path.write_text(json.dumps(index, indent=2) + "\n")
def rejected(label: str, mutate) -> None:
with tempfile.TemporaryDirectory() as temporary:
fixture = fixture_copy(Path(temporary))
mutate(fixture)
result = subprocess.run(["python3", str(VERIFY), str(fixture)], capture_output=True, text=True)
assert result.returncode != 0, f"{label} unexpectedly passed"
assert "invalid evidence binding:" in result.stderr, result.stderr
with tempfile.TemporaryDirectory() as temporary:
fixture = fixture_copy(Path(temporary))
subprocess.run(["python3", str(VERIFY), str(fixture)], check=True)
rejected(
"payload-byte corruption",
lambda fixture: (fixture / "evidence" / "payloads" / "RS-01.json").write_text(
(fixture / "evidence" / "payloads" / "RS-01.json").read_text() + "\n"
),
)
rejected("malformed payload", lambda fixture: (fixture / "evidence" / "payloads" / "RS-01.json").write_text("{\n"))
for label, value in (
("path traversal", "../README.md"),
("absolute path", "/tmp/outside.json"),
("missing local payload", "evidence/payloads/does-not-exist.json"),
("external URL-like path", "https://example.invalid/evidence.json"),
):
rejected(label, lambda fixture, value=value: receipt_path(fixture, value))
print("valid: clean fixture accepted; corruption and locality controls rejected")