Add tests for auth dependencies and security utilities
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user