feat(auth): 完成 AUTH-01~04 后端实现 - IP白名单中间件+mfa.py删除+agents.py重构+conftest修复

This commit is contained in:
Simon
2026-07-07 22:54:17 +08:00
parent fab75760e0
commit d56a9a6079
6 changed files with 153 additions and 587 deletions
+1 -22
View File
@@ -81,29 +81,8 @@ from app.models.agent_note import AgentNote
# =============================================================================
# 2026-06-15 修复: monkey-patch starlette.config.Config 强制 UTF-8 读 .env
# 原因: Windows pytest 默认 GBK 读 .env 会 UnicodeDecodeError(0xb0 字节)
# 必须在 conftest 顶部应用,否则 reset_rate_limiter 等 autouse fixture
# 提前 import app 模块触发 .env 读取时会失败
# 注意:已在文件顶部第38行应用过补丁,此处为兼容保留(不重复应用)
# =============================================================================
import starlette.config as _starlette_config
def _read_file_utf8(self, file_name, encoding=None):
"""强制以 UTF-8 编码读 .env,避免 Windows GBK 默认编码触发 UnicodeDecodeError。"""
result = {}
# 始终使用 UTF-8 编码,忽略传入的 encoding 参数
with open(file_name, encoding='utf-8') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'):
continue
if '=' in line:
k, v = line.split('=', 1)
result[k.strip()] = v.strip().strip('"').strip("'")
return result
_starlette_config.Config._read_file = _read_file_utf8
# =============================================================================