fix: Host中间件审查修复(本地开发文档/顺序守护测试/ws断连分支/夹具清理)
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,8 @@ import shutil
|
||||
import pytest
|
||||
from starlette.websockets import WebSocketDisconnect
|
||||
|
||||
from app.main import app
|
||||
from app.platform.host_middleware import TenantHostMiddleware
|
||||
from tests.conftest import (
|
||||
AUTO_HOST,
|
||||
JIANCAI_HOST,
|
||||
@@ -22,10 +24,20 @@ from tests.conftest import (
|
||||
NOPE_HOST = "nope.example.com"
|
||||
|
||||
|
||||
# ---- 中间件挂载顺序守护 -------------------------------------------------------
|
||||
|
||||
|
||||
def test_tenant_middleware_is_outermost_user_middleware():
|
||||
# add_middleware 后加者居 user_middleware[0] = 最外层。租户解析必须
|
||||
# 先于一切用户中间件(里层中间件/路由才读得到 state.tenant)——未来
|
||||
# 新中间件若更晚 add_middleware 插到租户中间件外层,此测试即红。
|
||||
assert app.user_middleware[0].cls is TenantHostMiddleware
|
||||
|
||||
|
||||
# ---- 平台级豁免 -------------------------------------------------------------
|
||||
|
||||
|
||||
def test_known_host_serves_health(app_client):
|
||||
def test_health_served_for_any_host(app_client):
|
||||
# /health 在任何 Host 下可达(部署健康检查 curl 127.0.0.1:8018,
|
||||
# Host 是 IP:端口,对 registry 必然未知)
|
||||
assert app_client.get("/health").status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user