feat: Implement random password and token generation for tests

This commit is contained in:
2025-11-12 11:53:44 +01:00
parent 3bdae3c54c
commit e06a6ae068
8 changed files with 83 additions and 41 deletions

View File

@@ -25,6 +25,7 @@ from routes.reports import router as reports_router
from services.importers import ImportIngestionService
from services.unit_of_work import UnitOfWork
from services.session import AuthSession, SessionTokens
from tests.utils.security import random_password, random_token
@pytest.fixture()
@@ -85,7 +86,7 @@ def app(session_factory: sessionmaker) -> FastAPI:
user = User(
email="test-superuser@example.com",
username="test-superuser",
password_hash=User.hash_password("test-password"),
password_hash=User.hash_password(random_password()),
is_active=True,
is_superuser=True,
)
@@ -93,8 +94,12 @@ def app(session_factory: sessionmaker) -> FastAPI:
user = uow.users.get(user.id, with_roles=True)
def _override_auth_session(request: Request) -> AuthSession:
session = AuthSession(tokens=SessionTokens(
access_token="test", refresh_token="test"))
session = AuthSession(
tokens=SessionTokens(
access_token=random_token(),
refresh_token=random_token(),
)
)
session.user = user
request.state.auth_session = session
return session