This commit is contained in:
logan committed 2026-05-24 14:08:45 +08:00
1 parent c7fccf99c7
commit 8471f368eb
33 files changed
+444 -2095

No files matched your search

+3 -7
View File
@@ -100,12 +100,11 @@ async def test_ldap_connection(
db: AsyncSession = Depends(get_db),
current_user: User = Depends(require_role("admin")),
):
"""测试 LDAP 连接 — 使用 mock 模拟"""
"""测试 LDAP 连接"""
ldap = await _get_existing(db)
if not ldap:
raise HTTPException(status_code=404, detail="LDAP 配置不存在,请先创建")
# Use mock for testing — python-ldap may not be installed
try:
import ldap as _ldap # noqa
# Real LDAP test path
@@ -131,12 +130,9 @@ async def test_ldap_connection(
return {"success": True, "message": f"LDAP 连接成功,用户 {data.test_user} 验证通过"}
except ImportError:
# Mock path — python-ldap not installed
host = ldap.ldap_host
port = ldap.ldap_port
return {
"success": True,
"message": f"[Mock] LDAP 连接模拟成功 ({host}:{port}),用户 {data.test_user} 验证通过",
"success": False,
"message": "python-ldap 未安装,无法测试 LDAP 连接。请执行: pip install python-ldap",
}
except Exception as e:
return {"success": False, "message": f"LDAP 连接失败: {str(e)}"}