fix: make MagicLink.expires_at required, document validation test TODOs
This commit is contained in:
parent
7454f8c8cb
commit
e4e484dc4b
2 changed files with 12 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
from datetime import UTC, datetime, timedelta
|
from datetime import UTC, datetime
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
@ -8,10 +8,6 @@ def _utcnow() -> datetime:
|
||||||
return datetime.now(UTC)
|
return datetime.now(UTC)
|
||||||
|
|
||||||
|
|
||||||
def _default_expiry() -> datetime:
|
|
||||||
return datetime.now(UTC) + timedelta(hours=24)
|
|
||||||
|
|
||||||
|
|
||||||
class CredentialType(StrEnum):
|
class CredentialType(StrEnum):
|
||||||
WEBAUTHN = "webauthn"
|
WEBAUTHN = "webauthn"
|
||||||
PASSWORD = "password"
|
PASSWORD = "password"
|
||||||
|
|
@ -56,7 +52,7 @@ class PasswordCredential(BaseModel):
|
||||||
class MagicLink(BaseModel):
|
class MagicLink(BaseModel):
|
||||||
token: str
|
token: str
|
||||||
username: str
|
username: str
|
||||||
expires_at: datetime = Field(default_factory=_default_expiry)
|
expires_at: datetime
|
||||||
used: bool = False
|
used: bool = False
|
||||||
created_by: str | None = None
|
created_by: str | None = None
|
||||||
note: str | None = None
|
note: str | None = None
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime, timedelta
|
||||||
|
|
||||||
from fastapi_oidc_op.models import (
|
from fastapi_oidc_op.models import (
|
||||||
CredentialType,
|
CredentialType,
|
||||||
|
|
@ -8,6 +8,12 @@ from fastapi_oidc_op.models import (
|
||||||
WebAuthnCredential,
|
WebAuthnCredential,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: Add model validation tests:
|
||||||
|
# - Required fields reject missing values (userid, username, etc.)
|
||||||
|
# - CredentialType rejects invalid enum values
|
||||||
|
# - WebAuthnCredential requires credential_id and public_key
|
||||||
|
# - sign_count rejects negative values
|
||||||
|
|
||||||
|
|
||||||
def test_user_creation() -> None:
|
def test_user_creation() -> None:
|
||||||
user = User(
|
user = User(
|
||||||
|
|
@ -68,12 +74,14 @@ def test_password_credential() -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_magic_link() -> None:
|
def test_magic_link() -> None:
|
||||||
|
expires = datetime.now(UTC) + timedelta(hours=24)
|
||||||
link = MagicLink(
|
link = MagicLink(
|
||||||
token="abc123def456",
|
token="abc123def456",
|
||||||
username="newuser",
|
username="newuser",
|
||||||
|
expires_at=expires,
|
||||||
)
|
)
|
||||||
assert link.token == "abc123def456"
|
assert link.token == "abc123def456"
|
||||||
assert link.username == "newuser"
|
assert link.username == "newuser"
|
||||||
assert link.used is False
|
assert link.used is False
|
||||||
assert link.created_by is None
|
assert link.created_by is None
|
||||||
assert link.expires_at > datetime.now(UTC)
|
assert link.expires_at == expires
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue