2626@pytest .fixture
2727def proxy_server (monkeypatch ):
2828 """Import the proxy OAuth demo server with safe environment + stubs."""
29+
2930 import os
3031
3132 # Avoid real outbound calls by pretending the upstream endpoints were
3233 # supplied explicitly via env vars – this makes `fetch_upstream_metadata`
3334 # construct metadata locally instead of performing an HTTP GET.
34- os .environ .setdefault ("UPSTREAM_AUTHORIZATION_ENDPOINT" , "https://upstream.example.com/authorize" )
35- os .environ .setdefault ("UPSTREAM_TOKEN_ENDPOINT" , "https://upstream.example.com/token" )
35+ os .environ .setdefault (
36+ "UPSTREAM_AUTHORIZATION_ENDPOINT" , "https://upstream.example.com/authorize"
37+ )
38+ os .environ .setdefault (
39+ "UPSTREAM_TOKEN_ENDPOINT" , "https://upstream.example.com/token"
40+ )
3641 os .environ .setdefault ("UPSTREAM_JWKS_URI" , "https://upstream.example.com/jwks" )
3742 os .environ .setdefault ("UPSTREAM_CLIENT_ID" , "client123" )
3843 os .environ .setdefault ("UPSTREAM_CLIENT_SECRET" , "secret123" )
3944
4045 # Deferred import so the env vars above are in effect.
41- from proxy_auth import combo_server as proxy_server_module
42-
4346 # Stub library-level fetch_upstream_metadata to avoid network I/O.
4447 from mcp .server .auth .proxy import routes as proxy_routes
4548
46- < << << << HEAD
47- == == == =
4849 # Import the module and the combo_server instance
4950 from proxy_auth import combo_server
5051
51- >> >> >> > fbb3cb4 (fix imports )
5252 async def _fake_metadata () -> dict [str , Any ]: # noqa: D401
5353 # Access module-level constants directly
5454 return {
@@ -59,17 +59,12 @@ async def _fake_metadata() -> dict[str, Any]: # noqa: D401
5959 "jwks_uri" : "" ,
6060 }
6161
62- < << << << HEAD
63- monkeypatch .setattr (proxy_routes , "fetch_upstream_metadata" , _fake_metadata , raising = True )
64- return proxy_server_module
65- == == == =
6662 monkeypatch .setattr (
6763 proxy_routes , "fetch_upstream_metadata" , _fake_metadata , raising = True
6864 )
6965
7066 # Return the combo_server instance
7167 return combo_server
72- >> >> >> > fbb3cb4 (fix imports )
7368
7469
7570@pytest .fixture
@@ -81,7 +76,9 @@ def app(proxy_server):
8176@pytest .fixture
8277async def client (app ) -> AsyncGenerator [httpx .AsyncClient , None ]:
8378 """Async HTTP client bound to the in-memory ASGI application."""
84- async with httpx .AsyncClient (transport = httpx .ASGITransport (app = app ), base_url = "http://testserver" ) as c :
79+ async with httpx .AsyncClient (
80+ transport = httpx .ASGITransport (app = app ), base_url = "http://testserver"
81+ ) as c :
8582 yield c
8683
8784
@@ -129,11 +126,7 @@ async def test_authorize_redirect(client):
129126 location = r .headers ["location" ]
130127 parsed = urllib .parse .urlparse (location )
131128 assert parsed .scheme .startswith ("http" )
132- < << << << HEAD
133- assert parsed .netloc == urllib .parse .urlparse (proxy_server .UPSTREAM_AUTHORIZE ).netloc
134- == == == =
135129 assert parsed .netloc == urllib .parse .urlparse (UPSTREAM_AUTHORIZE ).netloc
136- >> >> >> > fbb3cb4 (fix imports )
137130
138131 qs = urllib .parse .parse_qs (parsed .query )
139132 # Proxy should inject client_id & default scope
@@ -150,7 +143,8 @@ async def test_revoke_proxy(client, monkeypatch):
150143 async def _mock_post (self , url , data = None , timeout = 10 , ** kwargs ): # noqa: D401
151144 if url .endswith ("/revoke" ):
152145 return httpx .Response (200 , json = {"revoked" : True })
153- # For the test client's own request to /revoke, delegate to original implementation
146+ # For the test client's own request to /revoke,
147+ # delegate to original implementation
154148 return await original_post (self , url , data = data , timeout = timeout , ** kwargs )
155149
156150 monkeypatch .setattr (httpx .AsyncClient , "post" , _mock_post , raising = True )
@@ -231,9 +225,13 @@ async def test_user_info_tool(monkeypatch, proxy_server):
231225 from mcp .server .auth .provider import AccessToken # local import to avoid cycles
232226
233227 def _fake_get_access_token (): # noqa: D401
234- return AccessToken (token = dummy_token , client_id = "client123" , scopes = ["openid" ], expires_at = None )
228+ return AccessToken (
229+ token = dummy_token , client_id = "client123" , scopes = ["openid" ], expires_at = None
230+ )
235231
236- monkeypatch .setattr (auth_context , "get_access_token" , _fake_get_access_token , raising = True )
232+ monkeypatch .setattr (
233+ auth_context , "get_access_token" , _fake_get_access_token , raising = True
234+ )
237235
238236 result = await proxy_server .call_tool ("user_info" , {})
239237
@@ -244,5 +242,7 @@ def _fake_get_access_token(): # noqa: D401
244242 raw = result # fallback
245243
246244 assert raw ["authenticated" ] is True
247- assert ("userid" in raw and raw ["userid" ] == "test-user" ) or ("user_id" in raw and raw ["user_id" ] == "test-user" )
248- assert raw ["username" ] == "tester"
245+ assert ("userid" in raw and raw ["userid" ] == "test-user" ) or (
246+ "user_id" in raw and raw ["user_id" ] == "test-user"
247+ )
248+ assert raw ["username" ] == "tester"
0 commit comments