Meilenstein 1: Grundgerüst mit Login, Sessions und CSRF
- FastAPI-App mit SQLite-Schema (admins, sessions, connections) - Login mit Argon2, serverseitige Sessions (Token nur gehasht gespeichert) - Cookie HttpOnly/Secure/SameSite=Strict, CSRF-Token für schreibende Requests - scripts/create_admin.py zum Anlegen und Zurücksetzen von Admins - Einfaches Frontend mit Login - pytest-Tests, gepinnte requirements.txt, .env.example, .gitignore - SETUP.md Teil 4 ergänzt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
403606ff66
commit
293367f33e
18 files changed
+837
-6
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(tmp_path, monkeypatch):
|
||||
"""TestClient mit eigener, leerer Datenbank pro Test."""
|
||||
monkeypatch.setenv("IT_CONNECT_DB_PATH", str(tmp_path / "test.db"))
|
||||
# TestClient nutzt http://testserver, daher ohne Secure-Flag
|
||||
monkeypatch.setenv("IT_CONNECT_COOKIE_SECURE", "false")
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin(client):
|
||||
"""Legt den Test-Admin 'testadmin' an."""
|
||||
from app.auth import passwort_hashen
|
||||
from app.db import jetzt, verbinden
|
||||
|
||||
conn = verbinden()
|
||||
conn.execute(
|
||||
"INSERT INTO admins (benutzername, passwort_hash, erstellt_am) VALUES (?, ?, ?)",
|
||||
("testadmin", passwort_hashen("geheimes-test-passwort"), jetzt()),
|
||||
)
|
||||
conn.close()
|
||||
return {"benutzername": "testadmin", "passwort": "geheimes-test-passwort"}
|
||||
Reference in new issue
Block a user