@@ -25,20 +25,20 @@ def proxy_server(monkeypatch):
2525 # Avoid real outbound calls by pretending the upstream endpoints were
2626 # supplied explicitly via env vars – this makes `fetch_upstream_metadata`
2727 # construct metadata locally instead of performing an HTTP GET.
28- os .environ .setdefault ("UPSTREAM_AUTHORIZATION_ENDPOINT" , "https://upstream.example.com/authorize" )
29- os .environ .setdefault ("UPSTREAM_TOKEN_ENDPOINT" , "https://upstream.example.com/token" )
28+ os .environ .setdefault (
29+ "UPSTREAM_AUTHORIZATION_ENDPOINT" , "https://upstream.example.com/authorize"
30+ )
31+ os .environ .setdefault (
32+ "UPSTREAM_TOKEN_ENDPOINT" , "https://upstream.example.com/token"
33+ )
3034 os .environ .setdefault ("UPSTREAM_JWKS_URI" , "https://upstream.example.com/jwks" )
3135 os .environ .setdefault ("UPSTREAM_CLIENT_ID" , "client123" )
3236 os .environ .setdefault ("UPSTREAM_CLIENT_SECRET" , "secret123" )
3337
3438 # Deferred import so the env vars above are in effect.
35- from proxy_auth import combo_server as proxy_server_module
36-
3739 # Stub library-level fetch_upstream_metadata to avoid network I/O.
3840 from mcp .server .auth .proxy import routes as proxy_routes
3941
40- < << << << Updated upstream
41- == == == =
4242 # Handle imports whether running from root or project directory
4343 try :
4444 # Try direct import first (when running from project directory)
@@ -51,7 +51,6 @@ def proxy_server(monkeypatch):
5151 sys .path .insert (0 , project_dir )
5252 from proxy_auth import combo_server as proxy_server_module
5353
54- >> >> >> > Stashed changes
5554 async def _fake_metadata () -> dict [str , Any ]: # noqa: D401
5655 return {
5756 "issuer" : proxy_server_module .UPSTREAM_BASE ,
@@ -61,7 +60,9 @@ async def _fake_metadata() -> dict[str, Any]: # noqa: D401
6160 "jwks_uri" : "" ,
6261 }
6362
64- monkeypatch .setattr (proxy_routes , "fetch_upstream_metadata ", _fake_metadata , raising = True )
63+ monkeypatch .setattr (
64+ proxy_routes , "fetch_upstream_metadata" , _fake_metadata , raising = True
65+ )
6566 return proxy_server_module
6667
6768
@@ -74,7 +75,9 @@ def app(proxy_server):
7475@pytest .fixture
7576async def client (app ) -> AsyncGenerator [httpx .AsyncClient , None ]:
7677 """Async HTTP client bound to the in-memory ASGI application."""
77- async with httpx .AsyncClient (transport = httpx .ASGITransport (app = app ), base_url = "http :// testserver ") as c :
78+ async with httpx .AsyncClient (
79+ transport = httpx .ASGITransport (app = app ), base_url = "http://testserver"
80+ ) as c :
7881 yield c
7982
8083
@@ -122,7 +125,9 @@ async def test_authorize_redirect(client, proxy_server):
122125 location = r .headers ["location" ]
123126 parsed = urllib .parse .urlparse (location )
124127 assert parsed .scheme .startswith ("http" )
125- assert parsed .netloc == urllib .parse .urlparse (proxy_server .UPSTREAM_AUTHORIZE ).netloc
128+ assert (
129+ parsed .netloc == urllib .parse .urlparse (proxy_server .UPSTREAM_AUTHORIZE ).netloc
130+ )
126131
127132 qs = urllib .parse .parse_qs (parsed .query )
128133 # Proxy should inject client_id & default scope
@@ -139,7 +144,8 @@ async def test_revoke_proxy(client, monkeypatch, proxy_server):
139144 async def _mock_post (self , url , data = None , timeout = 10 , ** kwargs ): # noqa: D401
140145 if url .endswith ("/revoke" ):
141146 return httpx .Response (200 , json = {"revoked" : True })
142- # For the test client's own request to /revoke, delegate to original implementation
147+ # For the test client's own request to /revoke,
148+ # delegate to original implementation
143149 return await original_post (self , url , data = data , timeout = timeout , ** kwargs )
144150
145151 monkeypatch .setattr (httpx .AsyncClient , "post" , _mock_post , raising = True )
@@ -220,9 +226,13 @@ async def test_user_info_tool(monkeypatch, proxy_server):
220226 from mcp .server .auth .provider import AccessToken # local import to avoid cycles
221227
222228 def _fake_get_access_token (): # noqa: D401
223- return AccessToken (token = dummy_token , client_id = "client123 ", scopes = ["openid "], expires_at = None )
229+ return AccessToken (
230+ token = dummy_token , client_id = "client123" , scopes = ["openid" ], expires_at = None
231+ )
224232
225- monkeypatch .setattr (auth_context , "get_access_token ", _fake_get_access_token , raising = True )
233+ monkeypatch .setattr (
234+ auth_context , "get_access_token" , _fake_get_access_token , raising = True
235+ )
226236
227237 result = await proxy_server .mcp .call_tool ("user_info" , {})
228238
@@ -233,5 +243,7 @@ def _fake_get_access_token(): # noqa: D401
233243 raw = result # fallback
234244
235245 assert raw ["authenticated" ] is True
236- assert ("userid " in raw and raw ["userid "] == "test - user ") or ("user_id " in raw and raw ["user_id "] == "test - user ")
237- assert raw ["username "] == "tester "
246+ assert ("userid" in raw and raw ["userid" ] == "test-user" ) or (
247+ "user_id" in raw and raw ["user_id" ] == "test-user"
248+ )
249+ assert raw ["username" ] == "tester"
0 commit comments