chore: 忽略离线部署包,提交安全加固、数据库初始化与文档
- .gitignore: 忽略 docker/offline 离线部署包(镜像/运行时等大文件) - 安全加固: 新增 compute/api/security.py 及各端安全测试,补充 docs/security-hardening.md - 数据库: 新增完整初始化 SQL 与 docs/database-config.md - 数据转换与评测: 修复类型检查、增强校验并补充测试 - Docker 配置与环境变量更新 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
40
compute/tests/test_security.py
Normal file
40
compute/tests/test_security.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""计算节点文档路由(/docs、/redoc、/openapi.json)安全开关测试。
|
||||
|
||||
生产默认(COMPUTE_AUTH_ENABLED=true)关闭文档路由,避免未授权泄露 API 结构;
|
||||
显式配置 ENABLE_DOCS 可覆盖默认行为。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from compute.api.security import docs_enabled, docs_kwargs
|
||||
|
||||
|
||||
def test_docs_disabled_when_auth_enabled(monkeypatch) -> None:
|
||||
monkeypatch.delenv("ENABLE_DOCS", raising=False)
|
||||
monkeypatch.setenv("COMPUTE_AUTH_ENABLED", "true")
|
||||
assert docs_enabled() is False
|
||||
assert docs_kwargs() == {"docs_url": None, "redoc_url": None, "openapi_url": None}
|
||||
|
||||
|
||||
def test_docs_enabled_when_auth_disabled(monkeypatch) -> None:
|
||||
monkeypatch.delenv("ENABLE_DOCS", raising=False)
|
||||
monkeypatch.setenv("COMPUTE_AUTH_ENABLED", "false")
|
||||
assert docs_enabled() is True
|
||||
assert docs_kwargs() == {}
|
||||
|
||||
|
||||
def test_docs_env_override_enables_with_auth(monkeypatch) -> None:
|
||||
monkeypatch.setenv("ENABLE_DOCS", "true")
|
||||
monkeypatch.setenv("COMPUTE_AUTH_ENABLED", "true")
|
||||
assert docs_enabled() is True
|
||||
|
||||
|
||||
def test_docs_env_override_disables_without_auth(monkeypatch) -> None:
|
||||
monkeypatch.setenv("ENABLE_DOCS", "false")
|
||||
monkeypatch.setenv("COMPUTE_AUTH_ENABLED", "false")
|
||||
assert docs_enabled() is False
|
||||
|
||||
|
||||
def test_docs_default_when_auth_env_missing(monkeypatch) -> None:
|
||||
monkeypatch.delenv("ENABLE_DOCS", raising=False)
|
||||
monkeypatch.delenv("COMPUTE_AUTH_ENABLED", raising=False)
|
||||
assert docs_enabled() is False
|
||||
Reference in New Issue
Block a user