from __future__ import annotations from fastapi import FastAPI from fastapi.testclient import TestClient from src.api.v1.iwooos import router from src.services.iwooos_runtime_security_readback import ( load_latest_iwooos_runtime_security_readback, ) def _client() -> TestClient: app = FastAPI() app.include_router(router) return TestClient(app) def test_iwooos_runtime_security_readback_preserves_zero_runtime_gates() -> None: payload = load_latest_iwooos_runtime_security_readback() assert payload["schema_version"] == "iwooos_runtime_security_readback_v1" assert payload["status"] == "blocked_waiting_owner_evidence_and_runtime_gates" assert payload["summary"]["source_snapshot_count"] == 8 assert payload["summary"]["p0_lane_count"] == 6 assert payload["summary"]["runtime_gate_count"] == 0 assert payload["summary"]["owner_response_received_count"] == 0 assert payload["summary"]["owner_response_accepted_count"] == 0 assert payload["summary"]["wazuh_manager_registry_accepted_count"] == 0 assert payload["summary"]["kali_active_scan_authorized_count"] == 0 assert payload["summary"]["kali_execute_authorized_count"] == 0 assert payload["summary"]["alert_receipt_runtime_send_count"] == 0 assert payload["boundaries"]["runtime_execution_authorized"] is False assert payload["boundaries"]["active_scan_authorized"] is False assert payload["boundaries"]["wazuh_active_response_authorized"] is False assert payload["boundaries"]["telegram_send_authorized"] is False def test_iwooos_runtime_security_readback_lanes_are_candidate_only() -> None: payload = load_latest_iwooos_runtime_security_readback() lane_ids = {lane["lane_id"] for lane in payload["lanes"]} assert lane_ids == { "wazuh_registry", "wazuh_dashboard_api", "kali_intake", "alert_readability", "owner_dispatch", "intrusion_prevention", } assert all(lane["metrics"] for lane in payload["lanes"]) assert all(lane["next_gate"] for lane in payload["lanes"]) assert all(lane["source_refs"] for lane in payload["lanes"]) assert any(lane["completion_percent"] > 0 for lane in payload["lanes"]) assert all(lane["lane_id"] != "wazuh_registry" or lane["completion_percent"] == 0 for lane in payload["lanes"]) def test_iwooos_runtime_security_readback_api_is_public_safe() -> None: response = _client().get("/api/v1/iwooos/runtime-security-readback") assert response.status_code == 200 data = response.json() assert data["schema_version"] == "iwooos_runtime_security_readback_v1" assert data["summary"]["runtime_gate_count"] == 0 assert data["boundaries"]["secret_value_collection_allowed"] is False assert "192.168.0." not in response.text assert "工作視窗" not in response.text assert "批准!繼續" not in response.text