The 18:00Z-18:15Z window ended with no projection-ready notice and zero packets. Mark the identifier terminal. Record platform-pg E3 as not applicable for an ordinary runtime conformance-view identity. Assistant: grok Assistant-Session: 01a02670-3345-76f2-a014-70fde8e2a2bb
93 lines
3.3 KiB
Python
93 lines
3.3 KiB
Python
import json
|
|
from datetime import UTC, datetime
|
|
|
|
import pytest
|
|
|
|
from whitehat_security.engagement import AuthorizationError, Engagement
|
|
|
|
|
|
def record():
|
|
return {
|
|
"engagement_id": "WH-ENG-1", "authorization_id": "auth-1",
|
|
"authorizer": "operator", "approved_at": "2026-08-21T08:00:00Z",
|
|
"expires_at": "2026-08-21T12:00:00Z", "target": "https://fixture.invalid",
|
|
"target_owner": "target-repo", "environment": "build", "source": "runner",
|
|
"routes": ["GET /objects/{id}"], "fixture_ids": ["object-a", "object-b"],
|
|
"credential_lane": "openbao", "credential_role": "runtime",
|
|
"credential_max_ttl_seconds": 900, "techniques": ["e2-differential"],
|
|
"prohibited_techniques": ["saturation"], "rate_limit_per_minute": 10,
|
|
"max_concurrency": 1, "window_start": "2026-08-21T08:00:00Z",
|
|
"window_end": "2026-08-21T10:00:00Z", "operator_contact": "operator",
|
|
"abort_contact": "target-owner", "posture_claim": "E2",
|
|
"attacker_model": "E2-authenticated-tenant-a", "finding_destination": "risk-nexus",
|
|
"target_owner_acknowledged_at": "2026-08-21T08:01:00Z",
|
|
}
|
|
|
|
|
|
def load(tmp_path, data):
|
|
path = tmp_path / "engagement.json"
|
|
path.write_text(json.dumps(data), encoding="utf-8")
|
|
return Engagement.load(path, now=datetime(2026, 8, 21, 9, tzinfo=UTC))
|
|
|
|
|
|
def test_complete_current_record_is_accepted(tmp_path):
|
|
engagement = load(tmp_path, record())
|
|
engagement.permits(technique="e2-differential", route="GET /objects/{id}")
|
|
|
|
|
|
@pytest.mark.parametrize("field", ["target_owner_acknowledged_at", "abort_contact", "fixture_ids"])
|
|
def test_incomplete_record_fails_closed(tmp_path, field):
|
|
data = record()
|
|
del data[field]
|
|
with pytest.raises(AuthorizationError):
|
|
load(tmp_path, data)
|
|
|
|
|
|
def test_expired_record_fails_closed(tmp_path):
|
|
with pytest.raises(AuthorizationError, match="outside"):
|
|
Engagement.load(
|
|
_write(tmp_path, record()), now=datetime(2026, 8, 21, 13, tzinfo=UTC)
|
|
)
|
|
|
|
|
|
def test_unauthorized_route_fails_closed(tmp_path):
|
|
engagement = load(tmp_path, record())
|
|
with pytest.raises(AuthorizationError, match="route"):
|
|
engagement.permits(technique="e2-differential", route="DELETE /objects/{id}")
|
|
|
|
|
|
def test_pending_owner_acknowledgement_fails_closed(tmp_path):
|
|
data = record()
|
|
data["target_owner_acknowledged_at"] = None
|
|
with pytest.raises(AuthorizationError, match="pending"):
|
|
load(tmp_path, data)
|
|
|
|
|
|
def test_elapsed_record_fails_closed_even_inside_old_window(tmp_path):
|
|
data = record()
|
|
data["status"] = "expired"
|
|
with pytest.raises(AuthorizationError, match="elapsed"):
|
|
load(tmp_path, data)
|
|
|
|
|
|
def test_proposed_record_fails_closed_before_window_checks(tmp_path):
|
|
data = record()
|
|
data["status"] = "proposed"
|
|
data["approved_at"] = None
|
|
data["target_owner_acknowledged_at"] = None
|
|
with pytest.raises(AuthorizationError, match="proposed"):
|
|
load(tmp_path, data)
|
|
|
|
|
|
def test_cancelled_record_fails_closed_even_with_owner_acknowledgement(tmp_path):
|
|
data = record()
|
|
data["status"] = "cancelled"
|
|
data["cancelled_at"] = "2026-08-21T08:02:00Z"
|
|
with pytest.raises(AuthorizationError, match="cancelled"):
|
|
load(tmp_path, data)
|
|
|
|
|
|
def _write(tmp_path, data):
|
|
path = tmp_path / "engagement.json"
|
|
path.write_text(json.dumps(data), encoding="utf-8")
|
|
return path
|