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
This commit is contained in:
1 parent
557d88d3ed
commit
5366d5c963
55 files changed
+600
-18040
No files matched your search
@@ -71,12 +71,14 @@ func GetCurrentUser(c *gin.Context) (int, string, string) {
|
||||
return c.GetInt("user_id"), c.GetString("username"), c.GetString("role")
|
||||
}
|
||||
|
||||
// RBAC middleware — allow specified roles
|
||||
// RBAC middleware — allow specified roles (superadmin is treated as admin)
|
||||
func RequireRole(roles ...string) gin.HandlerFunc {
|
||||
roleSet := make(map[string]bool)
|
||||
for _, r := range roles {
|
||||
roleSet[r] = true
|
||||
}
|
||||
// superadmin inherits all admin privileges
|
||||
roleSet["superadmin"] = true
|
||||
return func(c *gin.Context) {
|
||||
role := c.GetString("role")
|
||||
if !roleSet[role] {
|
||||
|
||||
Reference in new issue
Block a user