test(wave205): path_security 单测重构与补全 +46测 #1172

Merged
xiaoxia merged 2 commits from test/wave205-path-security into develop 2026-07-30 00:26:06 +08:00
Owner

变更内容

  • path_security 单测从 unittest 迁移到 pytest 风格
  • 修正导入路径为标准包导入(apps.worker.video_processing.path_security)
  • 覆盖 sanitize_filename / is_path_safe / is_in_allowed_dirs / safe_resolve_path 核心函数
  • 覆盖边界场景: 路径遍历攻击、空路径、超长路径、特殊字符、符号链接、Windows路径等

测试统计

  • 新增/重构测试: 46个
  • 本地验证: pytest全绿 + black + ruff通过
## 变更内容 - path_security 单测从 unittest 迁移到 pytest 风格 - 修正导入路径为标准包导入(apps.worker.video_processing.path_security) - 覆盖 sanitize_filename / is_path_safe / is_in_allowed_dirs / safe_resolve_path 核心函数 - 覆盖边界场景: 路径遍历攻击、空路径、超长路径、特殊字符、符号链接、Windows路径等 ## 测试统计 - 新增/重构测试: 46个 - 本地验证: pytest全绿 + black + ruff通过
xiaoxia added 1 commit 2026-07-29 22:56:01 +08:00
test(wave205): path_security 单测重构与补全 +46测
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 5s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m14s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m16s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Web Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
92d5b3f26c
- 从 unittest 迁移到 pytest 风格
- 修正导入路径为标准包导入
- 覆盖 sanitize_filename / is_path_safe / is_in_allowed_dirs / safe_resolve_path
- 覆盖边界: 路径遍历、空路径、超长路径、特殊字符、符号链接等
auto-approve-bot added 1 commit 2026-07-29 23:03:18 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 31s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m1s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m31s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m33s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m47s
AI Code Review / AI Code Review (pull_request) Successful in 1m44s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m42s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m39s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m56s
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m56s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 4m35s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m1s
CI/CD Pipeline / CI Gate (pull_request) Successful in 11s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 44s
584a1059b8

🚀 预览环境已部署

项目 详情
PR号 #1172
预览链接 https://pr-1172.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1172 | | 预览链接 | [https://pr-1172.preview.xiaoxiajianji.com](https://pr-1172.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:否
  • 阻塞级问题数量:0 个

📊 审查概览

  • 整体评价:通过
  • 建议级问题数量:2 个

🔴 阻塞级问题(必须修复)

💡 改进建议(不阻塞合并)

  1. [tests/unit/test_path_security.py: 211] 弱断言建议增强

    • 具体内容:在 test_none_allowed_dirs_uses_default 测试中,仅断言返回值为 bool 类型 (isinstance(result, bool))。如果默认允许目录列表被误修改为空列表,导致 /tmp 不再被允许,该测试依然会通过(返回 False)。建议明确断言 assert result is True,以确保默认配置确实包含 /tmp
  2. [tests/unit/test_path_security.py: 100, 103] 平台兼容性建议

    • 具体内容:测试中使用了 /etc/passwd 等 Linux 特有的系统路径来验证“系统路径”拦截逻辑。如果 CI/CD 环境包含 Windows 或其他非 Linux 系统,这些测试可能会无法按预期触发拦截(因为 /etc/passwd 在 Windows 上可能不被视为敏感系统路径)。建议使用 pytest.mark.linux 标记这些测试,或者通过 Mock/注入配置的方式模拟敏感路径列表,以提高测试在不同平台上的通过率和准确性。

良好实践

  • 使用 pytest.fixture 管理临时目录资源,利用上下文管理器自动清理,比旧版的 setUp/tearDown 更简洁可靠。
  • 引入 MAX_PATH_LENGTH 常量替代硬编码数字,使测试边界与业务逻辑保持同步。
  • 增加了 match 参数校验异常信息,确保抛出的异常原因符合预期,提高了测试的精确度。
  • 增加了对 pathlib.Path 对象作为输入的测试用例,增强了代码对现代 Python 路径对象的兼容性验证。
  • 移除了 sys.path.insert 的 hack 写法,改用标准的模块导入路径,有利于代码静态分析和维护。

格式检查通过 | 逻辑审查通过 | 性能无明显隐患


🤖 由 AI 代码审查机器人自动生成 | 2026-07-29 15:09:47 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:否 - 阻塞级问题数量:0 个 ### 📊 审查概览 - 整体评价:通过 - 建议级问题数量:2 个 ### 🔴 阻塞级问题(必须修复) 无 ### 💡 改进建议(不阻塞合并) 1. **[tests/unit/test_path_security.py: 211] 弱断言建议增强** - 具体内容:在 `test_none_allowed_dirs_uses_default` 测试中,仅断言返回值为 `bool` 类型 (`isinstance(result, bool)`)。如果默认允许目录列表被误修改为空列表,导致 `/tmp` 不再被允许,该测试依然会通过(返回 False)。建议明确断言 `assert result is True`,以确保默认配置确实包含 `/tmp`。 2. **[tests/unit/test_path_security.py: 100, 103] 平台兼容性建议** - 具体内容:测试中使用了 `/etc/passwd` 等 Linux 特有的系统路径来验证“系统路径”拦截逻辑。如果 CI/CD 环境包含 Windows 或其他非 Linux 系统,这些测试可能会无法按预期触发拦截(因为 `/etc/passwd` 在 Windows 上可能不被视为敏感系统路径)。建议使用 `pytest.mark.linux` 标记这些测试,或者通过 Mock/注入配置的方式模拟敏感路径列表,以提高测试在不同平台上的通过率和准确性。 ### ✅ 良好实践 - 使用 `pytest.fixture` 管理临时目录资源,利用上下文管理器自动清理,比旧版的 `setUp/tearDown` 更简洁可靠。 - 引入 `MAX_PATH_LENGTH` 常量替代硬编码数字,使测试边界与业务逻辑保持同步。 - 增加了 `match` 参数校验异常信息,确保抛出的异常原因符合预期,提高了测试的精确度。 - 增加了对 `pathlib.Path` 对象作为输入的测试用例,增强了代码对现代 Python 路径对象的兼容性验证。 - 移除了 `sys.path.insert` 的 hack 写法,改用标准的模块导入路径,有利于代码静态分析和维护。 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ✅ 性能无明显隐患 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-29 15:09:47 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit c4144d9e3f into develop 2026-07-30 00:26:06 +08:00

🗑️ 预览环境已清理

PR #1172 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1172 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.