mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
- 管理端和用户端路由中的同步数据库操作提取为独立函数,通过 run_in_threadpool 在线程池中执行,避免阻塞事件循环(涉及 api_keys、payments、users、wallets、 provider_oauth、system、user_me、wallet 等模块) - 抽取 authenticate_user_from_bearer_token 统一 token 验证逻辑,支持 ManagementToken 和 JWT 两种认证方式,消除多处重复代码 - key_command_service 的 CRUD 操作改为线程池执行 - maintenance_scheduler 定时任务中的数据库操作改用 asyncio.to_thread - Dockerfile 中 aether-hub 增加 --worker-idle-timeout 0 防止空闲断连 - 新增 test_api_auth_conventions 和 test_auth_utils 单元测试
26 lines
745 B
Python
26 lines
745 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
def test_no_direct_access_token_verification_outside_pipeline() -> None:
|
|
api_root = Path("src/api")
|
|
allowed = {
|
|
Path("src/api/base/pipeline.py"),
|
|
Path("src/api/auth/routes.py"),
|
|
}
|
|
offenders: list[str] = []
|
|
|
|
for path in api_root.rglob("*.py"):
|
|
if path in allowed:
|
|
continue
|
|
text = path.read_text(encoding="utf-8")
|
|
if "verify_token(" in text and 'token_type="access"' in text:
|
|
offenders.append(str(path))
|
|
|
|
assert (
|
|
offenders == []
|
|
), "这些 API 文件仍在手写 access token 校验,应改为走 pipeline 或 auth_utils 统一入口: " + ", ".join(
|
|
sorted(offenders)
|
|
)
|