whitehat-security/tests/test_e3_capacity_reporting.py
tegwick 5384f051d2 Promote ASM T-01–T-10 into WHITEHAT-WP-0007 and triage each test
Extend whitehat-target/v1 with fixture-asm/asm instead of mapping onto
E2, E3, or capacity. Register all ten Canon tests as pending with named
blockers, known-bad designs, and result routes. Add a value-safe
conformance-message renderer. Authorizes no probe.

Assistant: grok
Assistant-Session: 01a05e32-c776-72a3-86ec-c490e027aca9
2026-09-02 01:11:16 +02:00

100 lines
4.3 KiB
Python

from whitehat_security.capacity import CapacitySample, capacity_calibration, characterize
from whitehat_security.e3 import PROBES, evaluate
from whitehat_security.model import RunReport
from whitehat_security.reporting import conformance_message, risk_nexus_message
def test_e3_expected_failures_are_findings_and_limit_is_not():
conformance = next(probe for probe in PROBES if probe.probe_id == "conformance-view-empty")
boundary = next(probe for probe in PROBES if probe.probe_id == "sql-compromise-reset")
assert evaluate(conformance, rows=1).outcome == "finding"
assert evaluate(conformance, rows=0).outcome == "pass"
assert evaluate(boundary, rows=1).outcome == "inconclusive"
def test_capacity_records_neighbour_degradation():
result = characterize(
baseline=[CapacitySample("n", 10, 0, 100)],
loaded=[CapacitySample("n", 15, .01, 75)],
governor_bound=True, aggressor_peak=5, aggressor_ceiling=5,
)
assert result.outcome == "pass"
assert result.neighbour_degradation["n"] == {
"latency_increase_percent": 50.0,
"error_rate_increase_points": .01,
"throughput_decrease_percent": 25.0,
}
def test_capacity_unbound_governor_is_finding():
result = characterize(
baseline=[], loaded=[], governor_bound=False,
aggressor_peak=7, aggressor_ceiling=5,
)
assert result.outcome == "aborted"
assert len(result.reasons) == 2
def test_capacity_calibration_detects_known_bad_without_generating_load():
report = capacity_calibration()
assert report["outcome"] == "pass"
assert report["evidence_class"] == "fixture"
good = {item["case"]: item for item in report["known_good"]}
bad = {item["case"]: item for item in report["known_bad"]}
assert good["governor_bound_within_ceiling"]["outcome"] == "pass"
assert good["governor_bound_within_ceiling"]["neighbour_degradation"]["neighbour"][
"latency_increase_percent"
] == 50.0
assert bad["unbound_governor"]["outcome"] == "finding"
assert bad["exceeded_ceiling"]["outcome"] == "aborted"
assert bad["missing_neighbour"]["outcome"] == "finding"
def test_risk_message_contains_pass_and_no_severity():
report = RunReport(
schema_version="whitehat-run/v1", run_id="run-1", evidence_class="target",
engagement_id="eng-1", authorization_id="auth-1", target="service",
target_revision="abc", posture_claim="E2", attacker_model="E2",
started_at="2026-08-21T00:00:00Z", ended_at="2026-08-21T00:01:00Z",
outcome="pass", attempted_operations=1, cleanup="complete",
credential_revocation="complete",
)
message = risk_nexus_message(report)
assert "**pass**" in message
assert "Severity" not in message
assert "not proof" in message
def test_conformance_message_uses_canon_test_id_and_omits_severity():
report = RunReport(
schema_version="whitehat-run/v1", run_id="run-asm-1", evidence_class="target",
engagement_id="eng-1", authorization_id="auth-1", target="access-engine",
target_revision="abc", posture_claim="ASM T-01", attacker_model="ASM",
started_at="2026-09-02T00:00:00Z", ended_at="2026-09-02T00:01:00Z",
outcome="pass", attempted_operations=1, cleanup="complete",
credential_revocation="complete",
)
message = conformance_message(
report, specification="asm-assurance-targets.v1", test_id="T-01",
invariant_ids=["A-01"],
)
assert message.startswith("[GH-CONFORMANCE] T-01 pass access-engine@abc") or \
"Subject: [GH-CONFORMANCE] T-01 pass access-engine@abc" in message
assert "Severity" not in message
assert "asm-assurance-targets.v1" in message
assert "`A-01`" in message
def test_abort_message_is_not_target_assurance():
report = RunReport(
schema_version="whitehat-run/v1", run_id="abort-1", evidence_class="abort",
engagement_id="eng-1", authorization_id="auth-1", target="audit-core",
target_revision="abc", posture_claim="E2", attacker_model="E2",
started_at="2026-08-22T19:17:54Z", ended_at="2026-08-22T19:21:39Z",
outcome="aborted", attempted_operations=0, cleanup="complete",
credential_revocation="custody-owned",
)
message = risk_nexus_message(report)
assert "`abort`" in message
assert "not target assurance" in message
assert "Severity" not in message