fix:deadlock und doppelte Mails
CI / audit (push) Skipped
CI / checks (push) Failing after 3m21s
CI / image (push) Skipped

This commit is contained in:
marco.morath committed 2026-11-25 22:15:34 +01:00
1 parent b1531e41e1
commit 8b6f74f364
13 files changed
+69 -27

No files matched your search

+27 -13
View File
@@ -18,7 +18,6 @@ import pytest
pytest.importorskip("fastapi")
from fastapi.routing import APIRoute
from helpers import PASSWORD, login, new_client, token_for
from test_forms import creator, participant, simple_form
from test_mail import admin
@@ -35,28 +34,43 @@ PROTECTED_PREFIXES = ("/admin", "/forms", "/account")
DUMMY_ID = "00000000-0000-0000-0000-000000000000"
def _routes(app: Any) -> list[APIRoute]:
return [r for r in app.routes if isinstance(r, APIRoute)]
def _routes(app: Any) -> list[tuple[str, Any]]:
"""(voller Pfad, Endpunkt) für alle Endpunkte, auch in eingebundenen Routern."""
found: list[tuple[str, Any]] = []
def walk(routes: Any, prefix: str) -> None:
for route in routes:
path = getattr(route, "path", "") or ""
full = path if path.startswith(prefix) else prefix + path
sub = getattr(route, "routes", None)
if sub and not getattr(route, "methods", None):
walk(sub, full)
elif getattr(route, "methods", None) and getattr(route, "dependant", None):
found.append((full, route))
walk(app.routes, "")
return found
def _fill(route: APIRoute) -> str:
def _fill(path: str, route: Any) -> str:
"""Pfad mit Platzhalter-Werten passenden Typs (Zahl oder UUID-Text)."""
kinds = {p.name: p.field_info.annotation for p in route.dependant.path_params}
return re.sub(r"\{([^}:]+)[^}]*\}",
lambda m: "1" if kinds.get(m.group(1)) is int else DUMMY_ID, route.path)
lambda m: "1" if kinds.get(m.group(1)) is int else DUMMY_ID, path)
def test_every_post_route_checks_csrf(app: Any) -> None:
from surveybox.web.deps import verify_csrf
missing = []
for route in _routes(app):
if not route.methods & {"POST", "PUT", "PATCH", "DELETE"}:
for full, route in _routes(app):
if not set(route.methods) & {"POST", "PUT", "PATCH", "DELETE"}:
continue
deps = {d.call for d in route.dependant.dependencies}
if verify_csrf not in deps and route.path not in CSRF_EXEMPT:
missing.append(route.path)
if verify_csrf not in deps and full not in CSRF_EXEMPT:
missing.append(full)
assert missing == [], f"POST ohne CSRF-Prüfung: {missing}"
assert sum(1 for _, r in _routes(app) if "POST" in r.methods) > 40 # wirklich erfasst
# Und wirklich: angemeldet, aber ohne Token wird abgewiesen
root = admin(app)
for path in ("/admin/appearance", "/forms", "/logout"):
@@ -67,15 +81,15 @@ def test_protected_pages_need_login_and_rights(app: Any) -> None:
guest = new_client(app)
paul = participant(app)
checked = 0
for route in _routes(app):
if "GET" not in route.methods or not route.path.startswith(PROTECTED_PREFIXES):
for full, route in _routes(app):
if "GET" not in route.methods or not full.startswith(PROTECTED_PREFIXES):
continue
path = _fill(route)
path = _fill(full, route)
resp = guest.get(path)
assert resp.status_code in (303, 401, 403, 404), (path, resp.status_code)
if resp.status_code == 303:
assert resp.headers["location"].startswith("/login"), path
if route.path.startswith("/admin"):
if full.startswith("/admin"):
denied = paul.get(path)
assert denied.status_code in (303, 403, 404), path
if denied.status_code == 303: