whitehat-security/tests/test_e3_capacity_reporting.py
tegwick 43327183d8 Finish WHITEHAT-WP-0001 and own live residuals in WP-0006
Close T05 and T06 on the same applicable-target rule as T03: E3 cadence
and in-process calibration, platform-pg not_applicable, P1/P2 evaluator
proven against known-good and known-bad samples. Persist offline capacity
calibration. Live E3, P1/P2, flex-auth E2, and a later audit-core run
move to WHITEHAT-WP-0006, which authorizes no packet.

Assistant: grok
Assistant-Session: 01a05e32-c776-72a3-86ec-c490e027aca9
2026-09-01 20:26:47 +02:00

80 lines
3.4 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 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_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