mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-11 03:39:49 +08:00
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from __future__ import annotations
|
|||
|
|
|
||
|
|
from datetime import datetime, timezone
|
||
|
|
from types import SimpleNamespace
|
||
|
|
|
||
|
|
from src.api.admin.pool import routes as pool_routes
|
||
|
|
|
||
|
|
|
||
|
|
def test_derive_oauth_expires_at_from_auth_config_seconds(monkeypatch) -> None:
|
||
|
|
key = SimpleNamespace(auth_type="oauth", auth_config="enc", expires_at=None)
|
||
|
|
|
||
|
|
monkeypatch.setattr(
|
||
|
|
pool_routes.crypto_service,
|
||
|
|
"decrypt",
|
||
|
|
lambda _v: '{"expires_at": 1710000000}',
|
||
|
|
)
|
||
|
|
|
||
|
|
assert pool_routes._derive_oauth_expires_at(key) == 1710000000
|
||
|
|
|
||
|
|
|
||
|
|
def test_derive_oauth_expires_at_from_auth_config_milliseconds(monkeypatch) -> None:
|
||
|
|
key = SimpleNamespace(auth_type="oauth", auth_config="enc", expires_at=None)
|
||
|
|
|
||
|
|
monkeypatch.setattr(
|
||
|
|
pool_routes.crypto_service,
|
||
|
|
"decrypt",
|
||
|
|
lambda _v: '{"expires_at": 1710000000000}',
|
||
|
|
)
|
||
|
|
|
||
|
|
assert pool_routes._derive_oauth_expires_at(key) == 1710000000
|
||
|
|
|
||
|
|
|
||
|
|
def test_derive_oauth_expires_at_fallback_to_legacy_datetime() -> None:
|
||
|
|
key = SimpleNamespace(
|
||
|
|
auth_type="oauth",
|
||
|
|
auth_config=None,
|
||
|
|
expires_at=datetime(2026, 3, 4, 1, 2, 3, tzinfo=timezone.utc),
|
||
|
|
)
|
||
|
|
|
||
|
|
assert pool_routes._derive_oauth_expires_at(key) == 1772586123
|