refactorisation pour correction de sécurité
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled

This commit is contained in:
2026-03-03 08:29:52 -05:00
parent 21d99a0f48
commit 88742892d0
18 changed files with 3016 additions and 9085 deletions
+30 -14
View File
@@ -7,10 +7,33 @@ from typing import Optional
from pydantic import BaseModel, EmailStr, Field, field_validator
def _validate_password_strength(password: str) -> str:
"""Shared password strength validator.
Requirements:
- Minimum 8 characters
- At least 1 uppercase letter
- At least 1 lowercase letter
- At least 1 digit
- At least 1 special character
"""
if len(password) < 8:
raise ValueError("Le mot de passe doit contenir au moins 8 caractères")
if not any(c.isupper() for c in password):
raise ValueError("Le mot de passe doit contenir au moins une majuscule")
if not any(c.islower() for c in password):
raise ValueError("Le mot de passe doit contenir au moins une minuscule")
if not any(c.isdigit() for c in password):
raise ValueError("Le mot de passe doit contenir au moins un chiffre")
if not any(c in "!@#$%^&*()_+-=[]{}|;:',.<>?/~`" for c in password):
raise ValueError("Le mot de passe doit contenir au moins un caractère spécial")
return password
class LoginRequest(BaseModel):
"""Request schema for user login."""
username: str = Field(..., min_length=3, max_length=50, description="Username")
password: str = Field(..., min_length=6, description="Password")
password: str = Field(..., min_length=1, description="Password")
class Token(BaseModel):
@@ -39,15 +62,12 @@ class UserBase(BaseModel):
class UserCreate(UserBase):
"""Schema for creating a new user."""
password: str = Field(..., min_length=6, max_length=128, description="Password (min 6 chars)")
password: str = Field(..., min_length=8, max_length=128, description="Password (min 8 chars, requires uppercase, lowercase, digit, special char)")
@field_validator('password')
@classmethod
def password_strength(cls, v: str) -> str:
"""Validate password has minimum complexity."""
if len(v) < 6:
raise ValueError('Password must be at least 6 characters')
return v
return _validate_password_strength(v)
class UserUpdate(BaseModel):
@@ -61,14 +81,12 @@ class UserUpdate(BaseModel):
class PasswordChange(BaseModel):
"""Schema for changing password."""
current_password: str = Field(..., description="Current password")
new_password: str = Field(..., min_length=6, max_length=128, description="New password")
new_password: str = Field(..., min_length=8, max_length=128, description="New password")
@field_validator('new_password')
@classmethod
def password_strength(cls, v: str) -> str:
if len(v) < 6:
raise ValueError('Password must be at least 6 characters')
return v
return _validate_password_strength(v)
class UserOut(BaseModel):
@@ -90,16 +108,14 @@ class UserOut(BaseModel):
class UserSetup(BaseModel):
"""Schema for initial admin setup (first user creation)."""
username: str = Field(..., min_length=3, max_length=50)
password: str = Field(..., min_length=6, max_length=128)
password: str = Field(..., min_length=8, max_length=128)
email: Optional[EmailStr] = None
display_name: Optional[str] = None
@field_validator('password')
@classmethod
def password_strength(cls, v: str) -> str:
if len(v) < 6:
raise ValueError('Password must be at least 6 characters')
return v
return _validate_password_strength(v)
class AuthStatus(BaseModel):