后端新增 4 个 LDAP 管理端点: - POST /ldap-config/create-ou: 创建组织单元 - POST /ldap-config/create-user: 创建单个用户 (SSHA加密) - POST /ldap-config/delete-user: 删除用户 - POST /ldap-config/batch-import-ldap: 批量导入用户 - POST /ldap-config/user-list: 查询用户列表(恢复) 前端 LdapConfigPage 增强: - LDAP 账号管理折叠区(配置存在即显示) - OU 下拉选择 + 根节点选项 + 数量统计 - 用户列表表格(全选/单选/DN显示) - 新建 OU 弹框(名称+父级DN+描述) - 添加用户弹框(用户名+密码+显示名+邮箱+目标OU) - 删除选中用户按钮(确认后批量删除) 前端 UsersPage BatchImportModal 三 Tab: - 本地导入 / 导入到 LDAP / 从 LDAP 导入 测试修复: - test_user_endpoint.py: 分页格式兼容 - test_users.py: 分页格式兼容 - test_system_settings.py: 精简后配置项匹配
79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
from tests.conftest import auth_header
|
|
|
|
|
|
class TestListUsers:
|
|
async def test_admin_list_users(self, client: AsyncClient, admin_token):
|
|
resp = await client.get("/api/v1/users", headers=auth_header(admin_token))
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert isinstance(data, dict) and "items" in data
|
|
|
|
async def test_non_admin_list_users(self, client: AsyncClient, developer_token):
|
|
resp = await client.get("/api/v1/users", headers=auth_header(developer_token))
|
|
assert resp.status_code == 403
|
|
|
|
|
|
class TestCreateUser:
|
|
async def test_create_user_success(self, client: AsyncClient, admin_token):
|
|
resp = await client.post("/api/v1/users", headers=auth_header(admin_token), json={
|
|
"username": "newuser",
|
|
"display_name": "新用户",
|
|
"password": "123456",
|
|
"role": "developer",
|
|
})
|
|
assert resp.status_code == 201
|
|
data = resp.json()
|
|
assert data["username"] == "newuser"
|
|
assert data["role"] == "developer"
|
|
assert "id" in data
|
|
|
|
async def test_create_duplicate_username(self, client: AsyncClient, admin_user, admin_token):
|
|
resp = await client.post("/api/v1/users", headers=auth_header(admin_token), json={
|
|
"username": "admin",
|
|
"display_name": "重复",
|
|
"password": "123456",
|
|
"role": "developer",
|
|
})
|
|
assert resp.status_code == 400
|
|
|
|
|
|
class TestGetUser:
|
|
async def test_get_single_user(self, client: AsyncClient, admin_user, admin_token):
|
|
resp = await client.get(f"/api/v1/users/{admin_user.id}", headers=auth_header(admin_token))
|
|
assert resp.status_code == 200
|
|
assert resp.json()["username"] == "admin"
|
|
|
|
async def test_get_nonexistent_user(self, client: AsyncClient, admin_token):
|
|
resp = await client.get("/api/v1/users/9999", headers=auth_header(admin_token))
|
|
assert resp.status_code == 404
|
|
|
|
|
|
class TestUpdateUser:
|
|
async def test_update_user(self, client: AsyncClient, admin_user, admin_token):
|
|
resp = await client.put(
|
|
f"/api/v1/users/{admin_user.id}",
|
|
headers=auth_header(admin_token),
|
|
json={"display_name": "管理员改名"},
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["display_name"] == "管理员改名"
|
|
|
|
|
|
class TestDeleteUser:
|
|
async def test_delete_user(self, client: AsyncClient, admin_user, dba_user, admin_token):
|
|
resp = await client.delete(
|
|
f"/api/v1/users/{dba_user.id}",
|
|
headers=auth_header(admin_token),
|
|
)
|
|
assert resp.status_code == 200
|
|
|
|
async def test_delete_self(self, client: AsyncClient, admin_user, admin_token):
|
|
resp = await client.delete(
|
|
f"/api/v1/users/{admin_user.id}",
|
|
headers=auth_header(admin_token),
|
|
)
|
|
assert resp.status_code == 400
|