Skip to content

Commit e3b103d

Browse files
committed
Fix test to use handle() instead of deleted response() method
1 parent c1e8aea commit e3b103d

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tests/server/auth/test_oauth_proxy.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,29 +1248,36 @@ async def test_token_endpoint_invalid_client_error(self, jwt_verifier):
12481248
class TestTokenHandlerErrorTransformation:
12491249
"""Tests for TokenHandler's OAuth 2.1 compliant error transformation."""
12501250

1251-
def test_transforms_client_auth_failure_to_invalid_client_401(self):
1251+
async def test_transforms_client_auth_failure_to_invalid_client_401(self):
12521252
"""Test that client authentication failures return invalid_client with 401."""
1253-
from mcp.server.auth.handlers.token import TokenErrorResponse
1253+
from unittest.mock import AsyncMock, patch
1254+
1255+
from mcp.server.auth.handlers.token import TokenHandler as SDKTokenHandler
12541256

12551257
from fastmcp.server.auth.oauth_proxy import TokenHandler
12561258

12571259
handler = TokenHandler(provider=Mock(), client_authenticator=Mock())
12581260

1259-
# Simulate error from ClientAuthenticator.authenticate() failure
1260-
error_response = TokenErrorResponse(
1261-
error="unauthorized_client",
1262-
error_description="Invalid client_id 'test-client-id'",
1261+
# Create a mock 401 response like the SDK returns for auth failures
1262+
mock_response = Mock()
1263+
mock_response.status_code = 401
1264+
mock_response.body = (
1265+
b'{"error":"unauthorized_client","error_description":"Invalid client_id"}'
12631266
)
12641267

1265-
response = handler.response(error_response)
1268+
# Patch the parent class's handle() to return our mock response
1269+
with patch.object(
1270+
SDKTokenHandler,
1271+
"handle",
1272+
new_callable=AsyncMock,
1273+
return_value=mock_response,
1274+
):
1275+
response = await handler.handle(Mock())
12661276

12671277
# Should transform to OAuth 2.1 compliant response
12681278
assert response.status_code == 401
12691279
assert b'"error":"invalid_client"' in response.body
1270-
assert (
1271-
b'"error_description":"Invalid client_id \'test-client-id\'"'
1272-
in response.body
1273-
)
1280+
assert b'"error_description":"Invalid client_id"' in response.body
12741281

12751282
def test_does_not_transform_grant_type_unauthorized_to_invalid_client(self):
12761283
"""Test that grant type authorization errors stay as unauthorized_client with 400."""

0 commit comments

Comments
 (0)