diff --git a/tests/test_app.py b/tests/test_app.py index a8d4645..5c6b2d7 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -266,6 +266,39 @@ def test_audit_persists_and_redacts_secrets(tmp_path, monkeypatch): assert entry["detail"].count("[REDACTED]") == 3 +def test_audit_records_ai_and_web_ui_actor(tmp_path, monkeypatch): + db = tmp_path / "audit.sqlite3" + monkeypatch.setattr(app, "AUDIT_DB_PATH", str(db)) + + async def empty_status(): + return {} + + monkeypatch.setattr(app, "_collect_service_status", empty_status) + app._ui_sessions.clear() + with TestClient(app.app) as client: + ai = client.get( + "/status", + headers={"Authorization": "Bearer test-token", "X-Butler-Actor": "Trulla"}, + ) + assert ai.status_code == 200 + + client.headers.pop("Authorization", None) + client.get("/ui/session") + web = client.get("/status") + assert web.status_code == 200 + + entries = client.get("/audit").json() + + assert [item["actor"] for item in entries[:2]] == ["Weboberfläche", "Trulla"] + + +def test_ui_audit_has_actor_column_and_filter(): + with TestClient(app.app) as client: + response = client.get("/ui") + assert 'Akteur' in response.text + assert 'id="audit-actor"' in response.text + + def test_wireguard_status_returns_redacted_live_state(monkeypatch): payload = { "interface": "wg0",