Sicherheit + Tests + A11y, SW by-v1118
PYDANTIC max_length (38 Routen, ~400 Field-Constraints): Schützt vor DoS durch Riesen-Payloads (10MB Thread-Titel etc.). Pragmatische Limits: - Titel/Name: 200 · Beschreibung/Body: 10000 · Notiz: 5000 - Email: 254 (RFC 5321) · URL: 500 · Slug/Kategorie: 100 - Hund-Name/Rasse: 80 · Hund-Bio: 2000 Top-betroffen: forum.py, diary.py, health.py, dogs.py, expenses.py, notes.py, auth.py, profile.py. Manuelle len()-Checks in profile, chat, ki entfernt (jetzt durch Field abgedeckt). PYTEST COVERAGE (+19 Tests, 37 grün + 1 xfail): - test_security.py: require_owner (Places GET/PATCH/DELETE mit Fremduser → 403), JWT-Blacklist (Logout invalidiert Token), Login-Lockout (5 Fehlversuche → 429 + Retry-After Header) - test_race.py: Invoice-Counter (20 parallele Threads, alle unique), Founder-Number (atomare Vergabe, voll bei 100) - test_validation.py: Forum-Titel 30k Zeichen → 422, Diary-Text 50k → 422 (verifiziert Pydantic max_length-Sweep) A11Y (Tap-Targets ≥44×44 + Dark-Mode-Kontrast): - #header-user-btn 36→44px, .header-back 40→44, .header-menu-btn 40→44 - dog-profile Wrapped-Slider Prev/Next 40→44 - forum-Lightbox Close 40→44 - --c-text-muted Light: #B0A090 (2.37:1 FAIL) → #7F6B58 (4.74:1 PASS) - --c-text-muted Dark: #806A58 (3.58:1 FAIL) → #A08878 (5.46:1 PASS) - Branding-Farben unangetastet
This commit is contained in:
parent
7751d303bb
commit
1ff66a7083
57 changed files with 1253 additions and 612 deletions
|
|
@ -7,7 +7,7 @@ import uuid
|
|||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from auth import get_current_user
|
||||
from database import db
|
||||
|
|
@ -20,17 +20,17 @@ VALID_SICHTBARKEIT = {"public", "friends", "private"}
|
|||
|
||||
|
||||
class ProfileUpdate(BaseModel):
|
||||
real_name: Optional[str] = None
|
||||
bio: Optional[str] = None
|
||||
wohnort: Optional[str] = None
|
||||
erfahrung: Optional[str] = None
|
||||
social_link: Optional[str] = None
|
||||
profil_sichtbarkeit: Optional[str] = None
|
||||
real_name: Optional[str] = Field(None, max_length=100)
|
||||
bio: Optional[str] = Field(None, max_length=300)
|
||||
wohnort: Optional[str] = Field(None, max_length=60)
|
||||
erfahrung: Optional[str] = Field(None, max_length=30)
|
||||
social_link: Optional[str] = Field(None, max_length=120)
|
||||
profil_sichtbarkeit: Optional[str] = Field(None, max_length=30)
|
||||
notes_ki_enabled: Optional[int] = None
|
||||
gassi_stunde_push: Optional[int] = None
|
||||
preferred_theme: Optional[str] = None
|
||||
billing_address: Optional[str] = None
|
||||
geburtstag: Optional[str] = None
|
||||
preferred_theme: Optional[str] = Field(None, max_length=20)
|
||||
billing_address: Optional[str] = Field(None, max_length=500)
|
||||
geburtstag: Optional[str] = Field(None, max_length=10)
|
||||
|
||||
|
||||
def _load_user(user_id: int) -> dict:
|
||||
|
|
@ -61,12 +61,7 @@ async def update_profile(data: ProfileUpdate, user=Depends(get_current_user)):
|
|||
raise HTTPException(400, f"profil_sichtbarkeit muss eines von {sorted(VALID_SICHTBARKEIT)} sein.")
|
||||
if "preferred_theme" in fields and fields["preferred_theme"] not in ("system", "light", "dark"):
|
||||
raise HTTPException(400, "preferred_theme muss 'system', 'light' oder 'dark' sein.")
|
||||
if "bio" in fields and len(fields["bio"]) > 300:
|
||||
raise HTTPException(400, "bio darf maximal 300 Zeichen lang sein.")
|
||||
if "wohnort" in fields and len(fields["wohnort"]) > 60:
|
||||
raise HTTPException(400, "wohnort darf maximal 60 Zeichen lang sein.")
|
||||
if "social_link" in fields and len(fields["social_link"]) > 120:
|
||||
raise HTTPException(400, "social_link darf maximal 120 Zeichen lang sein.")
|
||||
# Längen-Begrenzungen sind jetzt via Field max_length im Schema abgedeckt.
|
||||
if "geburtstag" in fields and fields["geburtstag"]:
|
||||
if not re.fullmatch(r"\d{2}\.\d{2}", fields["geburtstag"]):
|
||||
raise HTTPException(400, "geburtstag muss im Format TT.MM sein (z.B. 16.05).")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue