- Extract AuthIdentity model for multi-provider authentication (email_password, OAuth, Passkey, Magic Link) - Remove password field from User model, credentials now stored in AuthIdentity - Refactor unified login/register to use AuthIdentity-based provider checking - Add site config fields: footer_code, tos_url, privacy_url, auth_methods - Add auth settings defaults in migration (email_password enabled by default) - Update admin user creation to create AuthIdentity records - Update all tests to use AuthIdentity model Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
110 lines
3.3 KiB
Python
110 lines
3.3 KiB
Python
"""
|
|
站点配置端点集成测试
|
|
"""
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_ping(async_client: AsyncClient):
|
|
"""测试 /api/site/ping 返回 200"""
|
|
response = await async_client.get("/api/site/ping")
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_ping_response_format(async_client: AsyncClient):
|
|
"""测试 /api/site/ping 响应包含版本号"""
|
|
response = await async_client.get("/api/site/ping")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "data" in data
|
|
# BackendVersion 应该是字符串格式的版本号
|
|
assert isinstance(data["data"], str)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_config(async_client: AsyncClient):
|
|
"""测试 /api/site/config 返回配置"""
|
|
response = await async_client.get("/api/site/config")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "data" in data
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_config_contains_title(async_client: AsyncClient):
|
|
"""测试配置包含站点标题"""
|
|
response = await async_client.get("/api/site/config")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
config = data["data"]
|
|
assert "title" in config
|
|
assert config["title"] == "DiskNext Test"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_config_contains_themes(async_client: AsyncClient):
|
|
"""测试配置包含主题设置"""
|
|
response = await async_client.get("/api/site/config")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
config = data["data"]
|
|
assert "themes" in config
|
|
assert "defaultTheme" in config
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_config_register_enabled(async_client: AsyncClient):
|
|
"""测试配置包含注册开关"""
|
|
response = await async_client.get("/api/site/config")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
config = data["data"]
|
|
assert "registerEnabled" in config
|
|
assert config["registerEnabled"] is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_config_captcha_settings(async_client: AsyncClient):
|
|
"""测试配置包含验证码设置"""
|
|
response = await async_client.get("/api/site/config")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
config = data["data"]
|
|
assert "loginCaptcha" in config
|
|
assert "regCaptcha" in config
|
|
assert "forgetCaptcha" in config
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_config_auth_methods(async_client: AsyncClient):
|
|
"""测试配置包含认证方式列表"""
|
|
response = await async_client.get("/api/site/config")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
config = data["data"]
|
|
assert "authMethods" in config
|
|
assert isinstance(config["authMethods"], list)
|
|
assert len(config["authMethods"]) > 0
|
|
|
|
# 每个认证方式应包含 provider 和 isEnabled
|
|
for method in config["authMethods"]:
|
|
assert "provider" in method
|
|
assert "isEnabled" in method
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_site_captcha_endpoint_exists(async_client: AsyncClient):
|
|
"""测试验证码端点存在(即使未实现也应返回有效响应)"""
|
|
response = await async_client.get("/api/site/captcha")
|
|
# 未实现的端点可能返回 404 或其他状态码
|
|
assert response.status_code in [200, 404, 501]
|