π The fast, Pythonic way to build MCP servers and clients.
test: isolate consent checks and preserve OpenAPI download budget (#5664)
Larry Gao9f70a1b0450e
diff --git a/tests/server/auth/test_oauth_consent_page.py b/tests/server/auth/test_oauth_consent_page.pyindex 3b21946cb..7da65d8fa 100644--- a/tests/server/auth/test_oauth_consent_page.py+++ b/tests/server/auth/test_oauth_consent_page.py@@ -4,7 +4,7 @@ import reimport secretsimport timefrom http.cookies import SimpleCookie-from unittest.mock import Mock+from unittest.mock import AsyncMock, Mockfrom urllib.parse import parse_qs, urlparseimport pytest@@ -36,6 +36,16 @@ class _Verifier(TokenVerifier):)+def failed_token_exchange(monkeypatch: pytest.MonkeyPatch) -> AsyncMock:+ exchange = AsyncMock(side_effect=ValueError("Invalid authorization code"))+ monkeypatch.setattr(+ "fastmcp.server.auth.oauth_proxy.proxy.AsyncOAuth2Client.fetch_token",+ exchange,+ )+ return exchange++@pytest.fixturedef oauth_proxy_https():"""OAuthProxy configured with HTTPS base_url for __Host- cookies."""@@ -720,7 +730,9 @@ class TestConsentBindingCookie:set_cookie_header = r2.headers.get("set-cookie", "")assert "__Host-MCP_CONSENT_BINDING" in set_cookie_header- async def test_parallel_flows_do_not_interfere(self, oauth_proxy_https):+ async def test_parallel_flows_do_not_interfere(+ self, oauth_proxy_https, failed_token_exchange: AsyncMock+ ):"""Multiple concurrent consent flows in the same browser must not clobber each other.Uses two different clients so the second flow also shows a consent form@@ -777,6 +789,9 @@ class TestConsentBindingCookie:# Should NOT be 403 β the binding for txn1 should still be in the cookie.# It will fail at token exchange (500) but not at consent verification.assert r_cb1.status_code != 403+ assert r_cb1.status_code == 500+ failed_token_exchange.assert_awaited_once()+ assert failed_token_exchange.call_args.kwargs["code"] == "fake"async def test_idp_callback_rejects_missing_consent_cookie(self, oauth_proxy_https):"""IdP callback must reject requests without the consent binding cookie.@@ -845,7 +860,9 @@ class TestConsentBindingCookie:)assert r.status_code == 403- async def test_consent_disabled_skips_binding_check(self):+ async def test_consent_disabled_skips_binding_check(+ self, failed_token_exchange: AsyncMock+ ):"""When require_authorization_consent=False, the binding check is skipped."""proxy = OAuthProxy(upstream_authorization_endpoint="https://github.com/login/oauth/authorize",@@ -901,6 +918,8 @@ class TestConsentBindingCookie:follow_redirects=False,)# Should NOT be 403 (consent binding rejection)- # It will be 500 because the fake code can't be exchanged with GitHub,- # but that's fine β we're verifying the consent check was skipped.+ # The mocked token exchange fails after the consent check is skipped.assert r.status_code != 403+ assert r.status_code == 500+ failed_token_exchange.assert_awaited_once()+ assert failed_token_exchange.call_args.kwargs["code"] == "fake-code"diff --git a/tests/server/providers/openapi/test_openapi_performance.py b/tests/server/providers/openapi/test_openapi_performance.pyindex 2eb4ce74e..996819a46 100644--- a/tests/server/providers/openapi/test_openapi_performance.py+++ b/tests/server/providers/openapi/test_openapi_performance.py@@ -17,9 +17,9 @@ from fastmcp import FastMCPclass TestOpenAPIPerformance:"""Performance tests for OpenAPI parsing with real-world large schemas."""- # 10 second maximum timeout for this test no matter what+ # Allow the 30-second download plus the independently asserted 10-second parse.@pytest.mark.integration- @pytest.mark.timeout(10)+ @pytest.mark.timeout(45)async def test_github_api_schema_performance(self):"""Test that GitHub's full API schema parses quickly.