refactor(auth): tz_aware expiration comparison

This commit is contained in:
Houkime 2023-11-10 13:31:12 +00:00
parent 8453f62c74
commit 8badb9aaaf
2 changed files with 4 additions and 2 deletions

View file

@ -7,6 +7,7 @@ from typing import Optional
from pydantic import BaseModel from pydantic import BaseModel
from mnemonic import Mnemonic from mnemonic import Mnemonic
from selfprivacy_api.utils.timeutils import ensure_tz_aware
from selfprivacy_api.repositories.tokens.redis_tokens_repository import ( from selfprivacy_api.repositories.tokens.redis_tokens_repository import (
RedisTokensRepository, RedisTokensRepository,
) )
@ -121,8 +122,9 @@ def get_new_api_recovery_key(
) -> str: ) -> str:
"""Get new recovery key""" """Get new recovery key"""
if expiration_date is not None: if expiration_date is not None:
current_time = datetime.now().timestamp() expiration_date = ensure_tz_aware(expiration_date)
if expiration_date.timestamp() < current_time: current_time = datetime.now(timezone.utc)
if expiration_date < current_time:
raise InvalidExpirationDate("Expiration date is in the past") raise InvalidExpirationDate("Expiration date is in the past")
if uses_left is not None: if uses_left is not None:
if uses_left <= 0: if uses_left <= 0: