Alerts: configuration, test and search entries are a superuser's; subscribing a browser stays open

Any signed-in account could save an ntfy channel with its own `server` and a
`{"$secret": ...}` token and press Test, which sent the stored secret to that
host. The config GET/PUT, the test route and the global search's alert entries
now answer to superusers, like /secrets. The webpush key and subscribe routes
stay open to every account, and the Alerts page shows a non-superuser only the
button for its own browser. The events table in the docs gains run_finished.
This commit is contained in:
2026-10-28 12:40:44 +01:00
parent 29f4d93c2a
commit 2dc20911a3
8 changed files with 153 additions and 14 deletions
+22
View File
@@ -2,6 +2,7 @@
from typing import Any
import pytest
from fastapi.testclient import TestClient
from fluksio.api.routes.search import MASK, setting_text
@@ -190,3 +191,24 @@ def test_index_lists_a_nodes_settings(
assert found["hook.secret"]["detail"] == "secret"
assert "hook_secret" not in text
assert "s3cr3t-value" not in text
def test_alert_channels_are_named_only_to_a_superuser(
client: TestClient,
superuser_token_headers: dict[str, str],
normal_user_token_headers: dict[str, str],
tmp_path: Any,
monkeypatch: pytest.MonkeyPatch,
) -> None:
from fluksio.api.routes.alerts import write_config
from fluksio.flow.alerts import AlertsConfig, Channel
monkeypatch.setattr(settings, "ALERTS_FILE", tmp_path / "alerts.json")
write_config(AlertsConfig(channels=[Channel(name="phone", kind="ntfy")]))
def channels(headers: dict[str, str]) -> set[str]:
entries = client.get(f"{PREFIX}/", headers=headers).json()
return {e["name"] for e in entries if e["category"] == "alert"}
assert channels(superuser_token_headers) == {"phone"}
assert channels(normal_user_token_headers) == set()