2022-12-19 17:37:44 +00:00
|
|
|
import pytest
|
2023-11-10 17:40:52 +00:00
|
|
|
from datetime import datetime, timedelta, timezone
|
2022-12-19 17:37:44 +00:00
|
|
|
|
|
|
|
from selfprivacy_api.models.tokens.recovery_key import RecoveryKey
|
2022-12-26 14:01:36 +00:00
|
|
|
from selfprivacy_api.models.tokens.new_device_key import NewDeviceKey
|
2022-12-19 17:37:44 +00:00
|
|
|
|
|
|
|
|
2023-11-10 17:40:52 +00:00
|
|
|
def test_recovery_key_expired_utcnaive():
|
|
|
|
expiration = datetime.utcnow() - timedelta(minutes=5)
|
|
|
|
key = RecoveryKey.generate(expiration=expiration, uses_left=2)
|
|
|
|
assert not key.is_valid()
|
|
|
|
|
|
|
|
|
|
|
|
def test_recovery_key_expired_tzaware():
|
|
|
|
expiration = datetime.now(timezone.utc) - timedelta(minutes=5)
|
2022-12-19 17:37:44 +00:00
|
|
|
key = RecoveryKey.generate(expiration=expiration, uses_left=2)
|
|
|
|
assert not key.is_valid()
|
2022-12-26 14:01:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_new_device_key_expired():
|
2023-11-10 17:40:52 +00:00
|
|
|
# key is supposed to be tzaware
|
|
|
|
expiration = datetime.now(timezone.utc) - timedelta(minutes=5)
|
2022-12-26 14:01:36 +00:00
|
|
|
key = NewDeviceKey.generate()
|
|
|
|
key.expires_at = expiration
|
|
|
|
assert not key.is_valid()
|