Files
opsxsql/tests/test_ldap_config.py
T
logan 5366d5c963 refactor: 重写测试套件对齐Go后端API + 修复superadmin权限
- 删除 29 个旧 Python 后端单元测试 (from app.* 导入已不适用)
- 重写 19 个集成测试文件对齐 Go/Gin 后端实际 API 行为:
  - 创建端点返回 201 (非 200)
  - Settings PUT 需要数组格式
  - SQL 审核 field 是 sql_content (非 sql)
  - 实例/审核规则列表不支持服务端过滤, 改为客户端过滤
  - 实例详情 MySQL 不可达时返回 500 (容错断言)
- 修复 RequireRole 中间件: superadmin 等同 admin 权限
- 测试结果: 81 passed, 4 skipped, 0 failed
2026-05-29 16:12:32 +08:00

33 lines
1.3 KiB
Python

"""LDAP config tests — Go/Gin backend (admin only)."""
import pytest
from httpx import AsyncClient
from tests.conftest import auth_header
class TestLDAPConfig:
async def test_get_config(self, client: AsyncClient, admin_token: str):
resp = await client.get("/api/v1/ldap-config", headers=auth_header(admin_token))
assert resp.status_code == 200
data = resp.json()
assert "ldap_host" in data
assert "ldap_port" in data
async def test_update_config(self, client: AsyncClient, admin_token: str):
resp = await client.put("/api/v1/ldap-config", headers=auth_header(admin_token), json={
"ldap_host": "8.217.205.92",
"ldap_port": 389,
"admin_dn": "cn=admin,dc=opsx,dc=vip",
"admin_password": "admin123",
"base_dn": "dc=opsx,dc=vip",
"use_ldaps": False,
})
assert resp.status_code == 200
async def test_developer_forbidden(self, client: AsyncClient, developer_token: str):
resp = await client.get("/api/v1/ldap-config", headers=auth_header(developer_token))
assert resp.status_code == 403
async def test_no_auth(self, client: AsyncClient):
resp = await client.get("/api/v1/ldap-config")
assert resp.status_code == 401