1111
1212import httpx
1313import pytest
14+ from inline_snapshot import snapshot
1415from pydantic import AnyHttpUrl
1516from starlette .applications import Starlette
1617
@@ -197,7 +198,7 @@ def mock_oauth_provider():
197198
198199
199200@pytest .fixture
200- def auth_app (mock_oauth_provider ):
201+ def auth_app (mock_oauth_provider : MockOAuthProvider ):
201202 # Create auth router
202203 auth_routes = create_auth_routes (
203204 mock_oauth_provider ,
@@ -218,25 +219,7 @@ def auth_app(mock_oauth_provider):
218219
219220
220221@pytest .fixture
221- def protected_resource_app (auth_app ):
222- """Fixture to create protected resource routes for testing."""
223-
224- # Create the protected resource routes
225- protected_resource_routes = create_protected_resource_routes (
226- resource_url = AnyHttpUrl ("https://example.com/resource" ),
227- authorization_servers = [AnyHttpUrl ("https://auth.example.com/authorization" )],
228- scopes_supported = ["read" , "write" ],
229- resource_name = "Example Resource" ,
230- resource_documentation = AnyHttpUrl ("https://docs.example.com/resource" ),
231- )
232-
233- # add routes to the auth app
234- auth_app .router .routes .extend (protected_resource_routes )
235- return auth_app
236-
237-
238- @pytest .fixture
239- async def test_client (auth_app ):
222+ async def test_client (auth_app : Starlette ):
240223 async with httpx .AsyncClient (transport = httpx .ASGITransport (app = auth_app ), base_url = "https://mcptest.com" ) as client :
241224 yield client
242225
@@ -268,6 +251,32 @@ async def registered_client(test_client: httpx.AsyncClient, request):
268251 return client_info
269252
270253
254+ @pytest .fixture
255+ def protected_resource_app ():
256+ """Fixture to create protected resource routes for testing."""
257+
258+ # Create the protected resource routes
259+ protected_resource_routes = create_protected_resource_routes (
260+ resource_url = AnyHttpUrl ("https://example.com/resource" ),
261+ authorization_servers = [AnyHttpUrl ("https://auth.example.com/authorization" )],
262+ scopes_supported = ["read" , "write" ],
263+ resource_name = "Example Resource" ,
264+ resource_documentation = AnyHttpUrl ("https://docs.example.com/resource" ),
265+ )
266+
267+ app = Starlette (routes = protected_resource_routes )
268+ return app
269+
270+
271+ @pytest .fixture
272+ async def protected_resource_test_client (protected_resource_app : Starlette ):
273+ """Fixture to create an HTTP client for the protected resource app."""
274+ async with httpx .AsyncClient (
275+ transport = httpx .ASGITransport (app = protected_resource_app ), base_url = "https://mcptest.com"
276+ ) as client :
277+ yield client
278+
279+
271280@pytest .fixture
272281def pkce_challenge ():
273282 """Create a PKCE challenge with code_verifier and code_challenge."""
@@ -354,7 +363,7 @@ class TestAuthEndpoints:
354363 @pytest .mark .anyio
355364 async def test_metadata_endpoint (self , test_client : httpx .AsyncClient ):
356365 """Test the OAuth 2.0 metadata endpoint."""
357-
366+
358367 response = await test_client .get ("/.well-known/oauth-authorization-server" )
359368 assert response .status_code == 200
360369
@@ -1221,15 +1230,19 @@ class TestProtectedResourceMetadata:
12211230 """Test the Protected Resource Metadata model."""
12221231
12231232 @pytest .mark .anyio
1224- async def test_metadata_endpoint (self , protected_resource_app : Starlette , test_client : httpx .AsyncClient ):
1233+ async def test_metadata_endpoint (self , protected_resource_test_client : httpx .AsyncClient ):
12251234 """Test the OAuth 2.0 Protected Resource metadata endpoint."""
1226-
1227- response = await test_client .get ("/.well-known/oauth-protected-resource" )
1235+
1236+ response = await protected_resource_test_client .get ("/.well-known/oauth-protected-resource" )
12281237 assert response .status_code == 200
12291238 metadata = response .json ()
1230- assert metadata ["resource" ] == "https://example.com/resource"
1231- assert metadata ["authorization_servers" ] == ["https://auth.example.com/authorization" ]
1232- assert metadata ["scopes_supported" ] == ["read" , "write" ]
1233- assert metadata ["resource_name" ] == "Example Resource"
1234- assert metadata ["resource_documentation" ] == "https://docs.example.com/resource"
1235- assert metadata ["bearer_methods_supported" ] == ["header" ]
1239+ assert metadata == snapshot (
1240+ {
1241+ "resource" : "https://example.com/resource" ,
1242+ "authorization_servers" : ["https://auth.example.com/authorization" ],
1243+ "scopes_supported" : ["read" , "write" ],
1244+ "resource_name" : "Example Resource" ,
1245+ "resource_documentation" : "https://docs.example.com/resource" ,
1246+ "bearer_methods_supported" : ["header" ],
1247+ }
1248+ )
0 commit comments