Sicherheits-Härtung und Bugfixes

This commit is contained in:
Patrick Asmus
2026-10-11 17:39:03 +02:00
parent c3f68ace96
commit 65b0b5ac0f
25 changed files with 2577 additions and 686 deletions
+54
View File
@@ -0,0 +1,54 @@
import base64
import os
import sys
import tempfile
import pytest
_TMP = tempfile.mkdtemp(prefix="stream-recorder-tests-")
os.environ["DATA_DIR"] = os.path.join(_TMP, "data")
os.environ["STATIC_DIR"] = os.path.join(_TMP, "no-static")
os.environ["RECORDING_ROOTS"] = os.path.join(_TMP, "recordings")
os.environ.pop("ENABLE_API_DOCS", None)
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import app as app_module # noqa: E402
from config import hash_password # noqa: E402
from fastapi.testclient import TestClient # noqa: E402
from models import get_session, Job, Station, Recording, LogEntry # noqa: E402
TEST_PASSWORD = "geheim-12345"
# Schneller Hash für Tests
TEST_HASH = hash_password(TEST_PASSWORD, iterations=1000)
def basic(user, password):
return "Basic " + base64.b64encode(f"{user}:{password}".encode()).decode()
@pytest.fixture
def app_mod():
return app_module
@pytest.fixture
def client(app_mod):
cfg = app_mod.config
with cfg.lock:
cfg.data["auth"] = {"enabled": False, "username": "admin", "password_hash": TEST_HASH}
cfg.data["ntfy"] = {"url": "https://ntfy.example/topic", "token": "tk_secret", "events": "error"}
cfg.data["plik"] = {"url": "https://plik.example", "api_key": "plik_secret", "ttl": "30d"}
cfg.data["recording"]["download_path"] = os.environ["RECORDING_ROOTS"]
app_mod.clear_auth_cache()
app_mod.reset_auth_failures()
session = get_session()
try:
for model in (Job, Station, Recording, LogEntry):
session.query(model).delete()
session.commit()
finally:
session.close()
return TestClient(app_mod.app)