Files
thePlug/backend/tests/test_security.py
2026-05-07 09:21:45 +02:00

17 lines
575 B
Python

from datetime import UTC, datetime
from app.core.security import create_access_token, decode_access_token
def test_create_access_token_uses_twelve_hour_default_window(monkeypatch):
monkeypatch.setattr("app.core.security.settings.JWT_EXPIRE_MINUTES", 720)
issued_at = datetime.now(UTC)
token = create_access_token(subject="admin")
payload = decode_access_token(token)
expires_at = datetime.fromtimestamp(payload.exp, UTC)
lifetime_seconds = (expires_at - issued_at).total_seconds()
assert 11.9 * 60 * 60 <= lifetime_seconds <= 12.1 * 60 * 60