• IanShaw027's avatar
    fix(admin): 代码审查修复 - 输入验证和测试完善 · 7c3d5cad
    IanShaw027 authored
    根据 Codex 代码审查报告,修复所有 P0 和 P1 优先级问题。
    
    ## P0 紧急修复
    
    ### 1. 修复集成测试编译错误
    - 更新 group_repo_integration_test.go 中所有 ListWithFilters 调用
    - 添加缺失的 search 参数(传入空字符串)
    - 修复 4 处旧签名调用,避免 CI 编译失败
    
    ### 2. 添加统一的 search 参数输入验证
    为所有 admin handler 添加一致的输入验证逻辑:
    - group_handler.go: 添加 TrimSpace + 长度限制
    - proxy_handler.go: 添加 TrimSpace + 长度限制
    - redeem_handler.go: 添加 TrimSpace + 长度限制
    - user_handler.go: 添加 TrimSpace + 长度限制
    
    验证规则:
    - TrimSpace() 去除首尾空格
    - 最大长度 100 字符(防止 DoS 攻击)
    - 超长输入自动截断
    
    ## P1 改进
    
    ### 3. 补充 search 功能的单元测试
    新增 admin_service_group_test.go 中的测试:
    - TestAdminService_ListGroups_WithSearch
      - search 参数正常传递到 repository 层
      - search 为空字符串时的行为
      - search 与其他过滤条件组合使用
    
    新增 admin_service_search_test.go 文件:
    - 为其他 admin API 添加 search 测试覆盖
    - 统一的测试模式和断言
    
    ### 4. 补充 search 功能的集成测试
    新增 group_repo_integration_test.go 测试场景:
    - TestListWithFilters_Search
      - 搜索 name 字段匹配
      - 搜索 description 字段匹配
      - 搜索不存在内容(返回空)
      - 大小写不敏感测试
      - 特殊字符转义测试(%、_)
      - 与其他过滤条件组合
    
    ## 测试结果
    
    -  编译检查通过
    -  单元测试全部通过 (3/3)
    -  集成测试编译通过
    -  所有 service 测试通过
    
    ## 影响范围
    
    修改文件: 8 个
    代码变更: +234 行 / -8 行
    
    ## 相关 Issue
    
    解决代码审查中的安全性和稳定性问题:
    - 防止 DoS 攻击(超长搜索字符串)
    - 修复测试编译错误(CI 阻塞问题)
    - 提升测试覆盖率
    7c3d5cad
redeem_handler.go 6.54 KB