feat(auth): add Pydantic auth models and unit tests; update docs
This commit is contained in:
46
tests/unit/test_auth_models.py
Normal file
46
tests/unit/test_auth_models.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from server.models.auth import (
|
||||
AuthStatus,
|
||||
LoginRequest,
|
||||
LoginResponse,
|
||||
SessionModel,
|
||||
SetupRequest,
|
||||
)
|
||||
|
||||
|
||||
def test_login_request_validation():
|
||||
# password is required
|
||||
with pytest.raises(ValueError):
|
||||
LoginRequest(password="")
|
||||
|
||||
req = LoginRequest(password="hunter2", remember=True)
|
||||
assert req.password == "hunter2"
|
||||
assert req.remember is True
|
||||
|
||||
|
||||
def test_setup_request_requires_min_length():
|
||||
with pytest.raises(ValueError):
|
||||
SetupRequest(master_password="short")
|
||||
|
||||
good = SetupRequest(master_password="longenoughpassword")
|
||||
assert good.master_password == "longenoughpassword"
|
||||
|
||||
|
||||
def test_login_response_and_session_model():
|
||||
expires = datetime.utcnow() + timedelta(hours=1)
|
||||
lr = LoginResponse(access_token="tok", expires_at=expires)
|
||||
assert lr.token_type == "bearer"
|
||||
assert lr.access_token == "tok"
|
||||
|
||||
s = SessionModel(session_id="abc123", user="admin", expires_at=expires)
|
||||
assert s.session_id == "abc123"
|
||||
assert s.user == "admin"
|
||||
|
||||
|
||||
def test_auth_status_defaults():
|
||||
status = AuthStatus(configured=False, authenticated=False)
|
||||
assert status.configured is False
|
||||
assert status.authenticated is False
|
||||
Reference in New Issue
Block a user