network-monitor/tests/test_app.py
neil efd3836945 Serve installers from the hub; document the private-repo install
The repo is private, so anonymous raw URLs return 404. The hub now serves
/install-probe.sh (and /install.sh) from its own checkout, open even with
UI_PASSWORD, and the Add probe command fetches from there. The installers
still ask for a read-only token to clone. Docs use Gitea's
"Authorization: token" header and give a git-clone fallback for the hub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 18:13:19 -08:00

41 lines
1.7 KiB
Python

from fastapi.testclient import TestClient
def test_main_defaults_to_hub():
from app.main import app
with TestClient(app) as client:
r = client.get("/healthz")
assert r.status_code == 200 and r.json()["role"] == "hub"
def test_index_assets_and_spa_fallback(hub):
page = hub.get("/")
assert page.status_code == 200 and "network monitor" in page.text.lower()
css = hub.get("/static/css/app.css")
assert css.status_code == 200 and css.headers["cache-control"] == "no-cache"
assert hub.get("/clients/aa:bb:cc:dd:ee:ff").status_code == 200 # client-side route
assert hub.get("/api/nope").status_code == 404
def test_info(hub):
j = hub.get("/api/info").json()
assert j["role"] == "hub" and j["adguard"] is False
def test_password(hub, monkeypatch):
monkeypatch.setenv("UI_PASSWORD", "s3cret")
assert hub.get("/api/info").status_code == 401
assert hub.get("/api/info", auth=("admin", "wrong")).status_code == 401
assert hub.get("/api/info", auth=("admin", "s3cret")).status_code == 200
assert hub.get("/healthz").status_code == 200
assert hub.post("/api/probe/report", json={}).status_code in (401, 422) # token auth, not the password
def test_hub_serves_installers_without_password(hub, monkeypatch):
monkeypatch.setenv("UI_PASSWORD", "s3cret")
r = hub.get("/install-probe.sh")
assert r.status_code == 200 and r.text.startswith("#!/usr/bin/env bash") and "\nNETMON_ROLE=probe\n" in r.text
assert "\nNETMON_ROLE=hub\n" in hub.get("/install.sh").text
assert hub.get("/api/probes").status_code == 401 # the rest stays protected
monkeypatch.delenv("UI_PASSWORD")
assert hub.get("/api/probes").json()["install_url"] == "" # UI builds <hub>/install-probe.sh