@@ -102,22 +102,28 @@ def oauth_metadata_response():
102
102
103
103
104
104
@pytest .fixture
105
- def prm_metadata ():
106
- """PRM metadata with scopes."""
107
- return ProtectedResourceMetadata (
108
- resource = AnyHttpUrl ("https://api.example.com/v1/mcp" ),
109
- authorization_servers = [AnyHttpUrl ("https://auth.example.com" )],
110
- scopes_supported = ["resource:read" , "resource:write" ],
105
+ def prm_metadata_response ():
106
+ """PRM metadata response with scopes."""
107
+ return httpx .Response (
108
+ 200 ,
109
+ content = (
110
+ b'{"resource": "https://api.example.com/v1/mcp", '
111
+ b'"authorization_servers": ["https://auth.example.com"], '
112
+ b'"scopes_supported": ["resource:read", "resource:write"]}'
113
+ ),
111
114
)
112
115
113
116
114
117
@pytest .fixture
115
- def prm_metadata_without_scopes ():
116
- """PRM metadata without scopes."""
117
- return ProtectedResourceMetadata (
118
- resource = AnyHttpUrl ("https://api.example.com/v1/mcp" ),
119
- authorization_servers = [AnyHttpUrl ("https://auth.example.com" )],
120
- scopes_supported = None ,
118
+ def prm_metadata_without_scopes_response ():
119
+ """PRM metadata response without scopes."""
120
+ return httpx .Response (
121
+ 200 ,
122
+ content = (
123
+ b'{"resource": "https://api.example.com/v1/mcp", '
124
+ b'"authorization_servers": ["https://auth.example.com"], '
125
+ b'"scopes_supported": null}'
126
+ ),
121
127
)
122
128
123
129
@@ -437,20 +443,16 @@ async def test_handle_metadata_response_success(self, oauth_provider: OAuthClien
437
443
async def test_prioritize_www_auth_scope_over_prm (
438
444
self ,
439
445
oauth_provider_without_scope : OAuthClientProvider ,
440
- oauth_metadata_response : httpx .Response ,
441
- prm_metadata : ProtectedResourceMetadata ,
446
+ prm_metadata_response : httpx .Response ,
442
447
):
443
448
"""Test that WWW-Authenticate scope is prioritized over PRM scopes."""
444
449
provider = oauth_provider_without_scope
445
450
446
- # Set up PRM metadata with scopes
447
- provider .context .protected_resource_metadata = prm_metadata
448
-
449
451
# Set WWW-Authenticate scope (priority 1)
450
452
provider .context .www_authenticate_scope = "special:scope from:www-authenticate"
451
453
452
- # Process the OAuth metadata
453
- await provider ._handle_oauth_metadata_response ( oauth_metadata_response )
454
+ # Process the PRM metadata
455
+ await provider ._handle_protected_resource_response ( prm_metadata_response )
454
456
455
457
# Verify that WWW-Authenticate scope is used (not PRM scopes)
456
458
assert provider .context .client_metadata .scope == "special:scope from:www-authenticate"
@@ -459,17 +461,13 @@ async def test_prioritize_www_auth_scope_over_prm(
459
461
async def test_prioritize_prm_scopes_when_no_www_auth_scope (
460
462
self ,
461
463
oauth_provider_without_scope : OAuthClientProvider ,
462
- oauth_metadata_response : httpx .Response ,
463
- prm_metadata : ProtectedResourceMetadata ,
464
+ prm_metadata_response : httpx .Response ,
464
465
):
465
466
"""Test that PRM scopes are prioritized when WWW-Authenticate header has no scopes."""
466
467
provider = oauth_provider_without_scope
467
468
468
- # Set up PRM metadata with specific scopes
469
- provider .context .protected_resource_metadata = prm_metadata
470
-
471
- # Process the OAuth metadata (no WWW-Authenticate scope)
472
- await provider ._handle_oauth_metadata_response (oauth_metadata_response )
469
+ # Process the PRM metadata (no WWW-Authenticate scope)
470
+ await provider ._handle_protected_resource_response (prm_metadata_response )
473
471
474
472
# Verify that PRM scopes are used
475
473
assert provider .context .client_metadata .scope == "resource:read resource:write"
@@ -478,17 +476,13 @@ async def test_prioritize_prm_scopes_when_no_www_auth_scope(
478
476
async def test_omit_scope_when_no_prm_scopes_or_www_auth (
479
477
self ,
480
478
oauth_provider_without_scope : OAuthClientProvider ,
481
- oauth_metadata_response : httpx .Response ,
482
- prm_metadata_without_scopes : ProtectedResourceMetadata ,
479
+ prm_metadata_without_scopes_response : httpx .Response ,
483
480
):
484
481
"""Test that scope is omitted when PRM has no scopes and WWW-Authenticate doesn't specify scope."""
485
482
provider = oauth_provider_without_scope
486
483
487
- # Set up PRM metadata without scopes
488
- provider .context .protected_resource_metadata = prm_metadata_without_scopes
489
-
490
- # Process the OAuth metadata (no WWW-Authenticate scope set)
491
- await provider ._handle_oauth_metadata_response (oauth_metadata_response )
484
+ # Process the PRM metadata (no WWW-Authenticate scope set)
485
+ await provider ._handle_protected_resource_response (prm_metadata_without_scopes_response )
492
486
493
487
# Verify that scope is omitted
494
488
assert provider .context .client_metadata .scope is None
@@ -497,20 +491,16 @@ async def test_omit_scope_when_no_prm_scopes_or_www_auth(
497
491
async def test_preserve_existing_client_scope (
498
492
self ,
499
493
oauth_provider : OAuthClientProvider ,
500
- oauth_metadata_response : httpx .Response ,
501
- prm_metadata : ProtectedResourceMetadata ,
494
+ prm_metadata_response : httpx .Response ,
502
495
):
503
496
"""Test that existing client scope is preserved regardless of metadata."""
504
497
provider = oauth_provider
505
498
506
499
# Set WWW-Authenticate scope
507
500
provider .context .www_authenticate_scope = "special:scope from:www-authenticate"
508
501
509
- # Set up PRM metadata with scopes
510
- provider .context .protected_resource_metadata = prm_metadata
511
-
512
502
# Process the OAuth metadata
513
- await provider ._handle_oauth_metadata_response ( oauth_metadata_response )
503
+ await provider ._handle_protected_resource_response ( prm_metadata_response )
514
504
515
505
# Verify that predefined scope is preserved
516
506
assert provider .context .client_metadata .scope == "read write"
0 commit comments