43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""
|
|
Tests for authentication service.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
class TestUserContext:
|
|
"""Tests for UserContext dataclass."""
|
|
|
|
def test_user_context_accepts_l2_server(self) -> None:
|
|
"""
|
|
Regression test: UserContext must accept l2_server field.
|
|
|
|
Bug found 2026-01-12: auth_service.py passes l2_server to UserContext
|
|
but the art-common library was pinned to old version without this field.
|
|
"""
|
|
from artdag_common.middleware.auth import UserContext
|
|
|
|
# This should not raise TypeError
|
|
ctx = UserContext(
|
|
username="testuser",
|
|
actor_id="@testuser@example.com",
|
|
token="test-token",
|
|
l2_server="https://l2.example.com",
|
|
)
|
|
|
|
assert ctx.username == "testuser"
|
|
assert ctx.actor_id == "@testuser@example.com"
|
|
assert ctx.token == "test-token"
|
|
assert ctx.l2_server == "https://l2.example.com"
|
|
|
|
def test_user_context_l2_server_optional(self) -> None:
|
|
"""l2_server should be optional (default None)."""
|
|
from artdag_common.middleware.auth import UserContext
|
|
|
|
ctx = UserContext(
|
|
username="testuser",
|
|
actor_id="@testuser@example.com",
|
|
)
|
|
|
|
assert ctx.l2_server is None
|