fix(config,test): 补 auth_fail_ban_seconds 进面板 + 测试与封禁互不干扰

上一轮「封禁列表」功能的两个收尾漏洞(跑测试时暴露):

1. 配置项漏搬面板:server.auth_fail_ban_seconds 在 yaml 与 config.py 里都有,
   但 settings.py 的 _SERVER_KEYS / config_to_view 没带上 → 面板保存一次配置
   就会把它写丢(回退默认 3600)。test_config_view_masks_secrets_and_roundtrips
   正是这道闸。
2. 测试被自己的封禁功能打红:测试会故意制造大量鉴权失败,而「鉴权失败自动封禁」
   会在同一进程内把 testclient 拉黑 60 分钟,导致后半场测试全变 429
   (test_disabled_flag... / test_download_rejects... 等)。测试启动时关掉封禁
   (只保留限流)并清空计数,生产逻辑不变。
3. 顺手更新过时样本:官方把 longcat-2.5-preview-free 改名成 longcat-2.5-free,
   免费模型测试的样本改成"现网确实免费的那几个之一",避免上游改名再把测试打红。

效果(tests/test_gateway.py 直跑):改动前 206 passed / 19 failed,
改动后 214 passed / 11 failed。剩余 11 个为既有失败(日志/账号/视频/CORS 等,
多为跨用例状态污染,单独复现 test_full_view_put_rewrites_nothing 为 0 差异),
不在本轮范围。
This commit is contained in:
Jidekin committed 2026-11-19 08:23:15 +08:00
1 parent 9d679a02cd
commit 42ecd79e19
2 files changed
+20 -1

No files matched your search

+6
View File
@@ -141,6 +141,9 @@ def config_to_view(cfg: GatewayConfig) -> dict[str, Any]:
"webhook_allow_private": s.webhook_allow_private,
"docs_enabled": s.docs_enabled,
"auth_fail_limit_per_min": s.auth_fail_limit_per_min,
# 2026-11-19 补:封禁功能(2026-11-06)加了配置项但面板视图没跟上,
# 一旦在面板里保存配置,这一行就会被写丢(回退成默认 3600)。
"auth_fail_ban_seconds": s.auth_fail_ban_seconds,
},
"auth": {"session_ttl_minutes": cfg.auth.session_ttl_minutes},
"circuit": {
@@ -479,6 +482,9 @@ _SERVER_KEYS = (
"host", "port", "timeout", "retry", "health_auth", "hot_reload", "hot_reload_interval",
"metrics_enabled", "rate_limit_rps", "max_body_size", "cors_origins", "graceful_shutdown",
"batch_max_concurrency", "batch_max_items", "webhook_allow_private", "docs_enabled",
# 2026-11-19 补:封禁功能(2026-11-06)落盘了这两个键但忘了搬上面板,
# 导致「文件里有、面板里没有」—— 保存一次面板就会把它们丢掉。
"auth_fail_limit_per_min", "auth_fail_ban_seconds",
"auth_fail_limit_per_min",
)
_CIRCUIT_KEYS = ("enabled", "failure_threshold", "cooldown", "window")