test_isr_security.py file-level

at sha256:a · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:8 docs: queue board-identity follow-ups so they survive the session Capt… · aaronrene · Sep 5, 2026
1 """Security tests for ISR opaque session ids and role gates (§ISR.11)."""
2
3 from __future__ import annotations
4
5 import inspect
6
7 from tests.fixtures.isr import load_isr_entry, seed_isr_repo
8 from tools.honesty.ledger import append_entry
9 from tools.honesty.status import (
10 EXIT_MISSING_INDEPENDENT_SECOND_REVIEW,
11 HonestyStatusOptions,
12 run_honesty_status,
13 )
14 from tools.honesty.types import LedgerAppendOptions
15 from tools.independent_second_reviewer import (
16 build_independent_second_reviewer_gate,
17 independent_second_reviewer_gate_payload,
18 )
19
20
21 def test_url_like_session_ids_opaque(repo_root) -> None:
22 config = seed_isr_repo(repo_root)
23 body = load_isr_entry("isr-pass.json")
24 body["actor_session_id"] = "https://evil.example/$(curl)"
25 body["producer_session_id"] = "file:///etc/passwd; rm -rf /"
26 body["notes"] = "https://example.com/hook?x=`id`"
27 code = append_entry(
28 config=config,
29 repo_root=repo_root,
30 options=LedgerAppendOptions(kind="independent_second_review", body=body),
31 ).exit_code
32 assert code == 0
33
34
35 def test_no_network_or_model_imports_on_isr_paths() -> None:
36 import tools.honesty.ledger as ledger_mod
37 import tools.honesty.status as status_mod
38 import tools.honesty.validate as validate_mod
39 import tools.independent_second_reviewer.surface as surface_mod
40
41 for module in (ledger_mod, status_mod, validate_mod, surface_mod):
42 source = inspect.getsource(module)
43 assert "urllib" not in source
44 assert "requests" not in source
45 assert "httpx" not in source
46 assert "openai" not in source
47 assert "anthropic" not in source
48
49
50 def test_producer_cannot_append_isr(repo_root) -> None:
51 config = seed_isr_repo(repo_root)
52 body = load_isr_entry("isr-producer.json")
53 result = append_entry(
54 config=config,
55 repo_root=repo_root,
56 options=LedgerAppendOptions(kind="independent_second_review", body=body),
57 )
58 assert result.exit_code == 23
59
60
61 def test_equal_session_ids_cannot_pass(repo_root) -> None:
62 config = seed_isr_repo(repo_root)
63 body = load_isr_entry("isr-pass.json")
64 body["actor_session_id"] = "same"
65 body["producer_session_id"] = "same"
66 result = append_entry(
67 config=config,
68 repo_root=repo_root,
69 options=LedgerAppendOptions(kind="independent_second_review", body=body),
70 )
71 assert result.exit_code == 2
72
73
74 def test_exit_38_not_waived_under_require(repo_root) -> None:
75 config = seed_isr_repo(repo_root, require_independent_second_reviewer="require")
76 result = run_honesty_status(
77 config=config,
78 repo_root=repo_root,
79 options=HonestyStatusOptions(
80 hook=None,
81 artifact=None,
82 independent_second_review="ISR-b",
83 ),
84 )
85 assert result.exit_code == EXIT_MISSING_INDEPENDENT_SECOND_REVIEW
86
87
88 def test_gate_payload_no_absolute_machine_paths(repo_root) -> None:
89 config = seed_isr_repo(repo_root, require_independent_second_reviewer="require")
90 report = build_independent_second_reviewer_gate(
91 config,
92 repo_root,
93 handover_text=(
94 "## NEXT SESSION — ISR-b\n\n| | |\n| **ID** | **ISR-b** |\n\n"
95 "Build verified → `pass` (ISR-b-BV-r1).\n"
96 ),
97 roadmap_text=(
98 "| Phase | Model | Status | Deliverable |\n"
99 "| --- | --- | --- | --- |\n"
100 "| **ISR-b Independent second reviewer build** | Auto | **DONE** | "
101 "`docs/archive/phases/PHASE-ISR-INDEPENDENT-SECOND-REVIEWER.md` |\n"
102 ),
103 )
104 payload = independent_second_reviewer_gate_payload(report)
105 assert payload is not None
106 blob = str(payload)
107 assert "/Users/" not in blob
108 assert "C:\\" not in blob