Add tests for auth dependencies and security utilities
All checks were successful
Build and Push Docker Images / changes (push) Successful in 4s
Build and Push Docker Images / build-backend (push) Successful in 49s
Build and Push Docker Images / build-frontend (push) Has been skipped

Introduced unit tests for `get_current_user`, `get_current_active_user`, and security functions like token creation and decoding. Also refactored imports for consistency and cleaned up unused or misplaced code to improve maintainability.
This commit is contained in:
2025-02-28 16:34:59 +01:00
parent 43df9d73b0
commit c3a55b26c7
4 changed files with 149 additions and 5 deletions

View File

@@ -3,13 +3,13 @@ from fastapi.security import OAuth2PasswordBearer
from jose import JWTError, jwt
from sqlalchemy.ext.asyncio import AsyncSession
from auth.security import SECRET_KEY, ALGORITHM
from app.core.database import get_db
from models.user import User
from app.schemas.token import TokenData
from auth.security import SECRET_KEY, ALGORITHM
from app.models.user import User
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/token")
async def get_current_user(
token: str = Depends(oauth2_scheme),
db: AsyncSession = Depends(get_db)
@@ -37,9 +37,10 @@ async def get_current_user(
return user
async def get_current_active_user(
current_user: User = Depends(get_current_user),
):
if not current_user.is_active:
raise HTTPException(status_code=400, detail="Inactive user")
return current_user
return current_user

View File

@@ -5,7 +5,7 @@ from uuid import uuid4
from jose import jwt, JWTError
from passlib.context import CryptContext
from app.core.config import settings
from .token import TokenPayload, TokenResponse
from app.schemas.token import TokenPayload, TokenResponse
# Configuration
SECRET_KEY = settings.SECRET_KEY