fix: breaking change with dependency FastAPI v0.137.0

https://fastapi.tiangolo.com/release-notes/#specific-breaking-changes
This commit is contained in:
grossmj committed 2026-08-11 18:47:02 +02:00
1 parent 3689e2bb87
commit 0219914103
3 files changed
+115 -35

No files matched your search

+1
View File
@@ -87,6 +87,7 @@ class TestACLRoutes:
response = await authorized_client.post(app.url_path_for("create_project"), json={"name": "test"})
assert response.status_code == status.HTTP_201_CREATED
async def test_create_ace_not_existing_endpoint(
self,
app: FastAPI,
+65 -22
View File
@@ -17,11 +17,12 @@
import pytest
from fastapi import FastAPI, status
from fastapi.routing import APIRoute, APIWebSocketRoute
from starlette.routing import Mount
from fastapi.routing import APIRoute, APIWebSocketRoute, _IncludedRouter
from starlette.routing import BaseRoute, Mount
from httpx import AsyncClient
from httpx_ws import aconnect_ws
from httpx_ws.transport import ASGIWebSocketTransport
from typing import Iterator, Sequence, Tuple
@@ -46,6 +47,43 @@ ALLOWED_CONTROLLER_ENDPOINTS = [
("/v3/mcp/", "GET"),
]
def _join_paths(prefix: str, path: str) -> str:
if not prefix:
return path
normalized_prefix = prefix
while normalized_prefix.endswith("/"):
normalized_prefix = normalized_prefix[:-1]
normalized_path = path
while normalized_path.startswith("/"):
normalized_path = normalized_path[1:]
return f"{normalized_prefix}/{normalized_path}"
def _iter_routes(
routes: Sequence[BaseRoute],
prefix: str = "",
include_mounted_routes: bool = False
) -> Iterator[Tuple[str, BaseRoute]]:
for route in routes:
if isinstance(route, _IncludedRouter):
include_prefix = route.include_context.prefix or ""
yield from _iter_routes(route.original_router.routes, _join_paths(prefix, include_prefix), include_mounted_routes)
continue
if isinstance(route, (APIRoute, APIWebSocketRoute)):
yield _join_paths(prefix, route.path), route
continue
if isinstance(route, Mount) and include_mounted_routes:
mounted_routes = getattr(route, "routes", None)
if isinstance(mounted_routes, Sequence):
yield from _iter_routes(mounted_routes, _join_paths(prefix, route.path), include_mounted_routes)
class TestRoutes:
# Controller endpoints have a OAuth2 bearer token authentication
@@ -55,16 +93,17 @@ class TestRoutes:
unauthorized_client: AsyncClient
) -> None:
for route in app.routes:
for path, route in _iter_routes(app.routes):
if isinstance(route, APIRoute):
for method in list(route.methods):
if (route.path, method) not in ALLOWED_CONTROLLER_ENDPOINTS:
response = await getattr(unauthorized_client, method.lower())(route.path)
assert response.status_code == status.HTTP_401_UNAUTHORIZED
elif isinstance(route, APIWebSocketRoute):
if (path, method) not in ALLOWED_CONTROLLER_ENDPOINTS:
request_path = path.rstrip("/")
response = await getattr(unauthorized_client, method.lower())(request_path)
assert response.status_code == status.HTTP_401_UNAUTHORIZED, f"{method} {request_path} -> {response.status_code}"
elif isinstance(route, APIWebSocketRoute) and not path.startswith("/v3/compute"):
params = {"token": "wrong_token"}
async with AsyncClient(base_url="http://test-api", transport=ASGIWebSocketTransport(app=app)) as client:
async with aconnect_ws(route.path, client, params=params) as ws:
async with aconnect_ws(path, client, params=params) as ws:
json_notification = await ws.receive_json()
assert json_notification['event'] == {
'message': 'Could not authenticate while connecting to controller WebSocket: Could not validate credentials'
@@ -78,17 +117,21 @@ class TestRoutes:
unauthorized_client: AsyncClient
) -> None:
for route in app.routes:
if isinstance(route, Mount):
for compute_route in route.routes:
if isinstance(compute_route, APIRoute):
for method in list(compute_route.methods):
response = await getattr(unauthorized_client, method.lower())(route.path + compute_route.path)
assert response.status_code == status.HTTP_401_UNAUTHORIZED
elif isinstance(compute_route, APIWebSocketRoute):
async with AsyncClient(base_url="http://test-api", transport=ASGIWebSocketTransport(app=app)) as client:
async with aconnect_ws(route.path + compute_route.path, client, auth=("wrong_user", "password123")) as ws:
json_notification = await ws.receive_json()
assert json_notification['event'] == {
'message': 'Could not authenticate while connecting to compute WebSocket: Could not validate credentials'
}
for path, route in _iter_routes(app.routes, include_mounted_routes=True):
if not path.startswith("/v3/compute"):
continue
if isinstance(route, APIRoute):
for method in list(route.methods):
request_path = path.rstrip("/")
response = await getattr(unauthorized_client, method.lower())(request_path)
#if response.status_code == status.HTTP_307_TEMPORARY_REDIRECT:
# response = await getattr(unauthorized_client, method.lower())(response.headers["location"])
assert response.status_code == status.HTTP_401_UNAUTHORIZED, f"{method} {request_path} -> {response.status_code}"
elif isinstance(route, APIWebSocketRoute):
async with AsyncClient(base_url="http://test-api", transport=ASGIWebSocketTransport(app=app)) as client:
async with aconnect_ws(path, client, auth=("wrong_user", "password123")) as ws:
json_notification = await ws.receive_json()
assert json_notification['event'] == {
'message': 'Could not authenticate while connecting to compute WebSocket: Could not validate credentials'
}