@@ -78,6 +78,7 @@ async def callback_handler() -> tuple[str, str | None]:
78
78
callback_handler = callback_handler ,
79
79
)
80
80
81
+
81
82
@pytest .fixture
82
83
def oauth_provider_without_scope (oauth_provider : OAuthClientProvider ) -> OAuthClientProvider :
83
84
"""Create OAuth provider without predefined scope."""
@@ -119,6 +120,22 @@ def prm_metadata_without_scopes():
119
120
scopes_supported = None ,
120
121
)
121
122
123
+
124
+ @pytest .fixture
125
+ def oauth_metadata_response_without_scopes ():
126
+ """OAuth metadata response without scopes."""
127
+ return httpx .Response (
128
+ 200 ,
129
+ content = (
130
+ b'{"issuer": "https://auth.example.com", '
131
+ b'"authorization_endpoint": "https://auth.example.com/authorize", '
132
+ b'"token_endpoint": "https://auth.example.com/token", '
133
+ b'"registration_endpoint": "https://auth.example.com/register"}'
134
+ # No scopes_supported field
135
+ ),
136
+ )
137
+
138
+
122
139
class TestPKCEParameters :
123
140
"""Test PKCE parameter generation."""
124
141
@@ -433,8 +450,10 @@ async def test_handle_metadata_response_success(self, oauth_provider: OAuthClien
433
450
434
451
@pytest .mark .anyio
435
452
async def test_prioritize_prm_scopes_over_oauth_metadata (
436
- self , oauth_provider_without_scope : OAuthClientProvider ,
437
- oauth_metadata_response : httpx .Response , prm_metadata : ProtectedResourceMetadata
453
+ self ,
454
+ oauth_provider_without_scope : OAuthClientProvider ,
455
+ oauth_metadata_response : httpx .Response ,
456
+ prm_metadata : ProtectedResourceMetadata ,
438
457
):
439
458
"""Test that PRM scopes are prioritized over auth server metadata scopes."""
440
459
provider = oauth_provider_without_scope
@@ -450,8 +469,10 @@ async def test_prioritize_prm_scopes_over_oauth_metadata(
450
469
451
470
@pytest .mark .anyio
452
471
async def test_fallback_to_oauth_metadata_scopes_when_no_prm_scopes (
453
- self , oauth_provider_without_scope : OAuthClientProvider ,
454
- oauth_metadata_response : httpx .Response , prm_metadata_without_scopes : ProtectedResourceMetadata
472
+ self ,
473
+ oauth_provider_without_scope : OAuthClientProvider ,
474
+ oauth_metadata_response : httpx .Response ,
475
+ prm_metadata_without_scopes : ProtectedResourceMetadata ,
455
476
):
456
477
"""Test fallback to OAuth metadata scopes when PRM has no scopes."""
457
478
provider = oauth_provider_without_scope
@@ -467,37 +488,29 @@ async def test_fallback_to_oauth_metadata_scopes_when_no_prm_scopes(
467
488
468
489
@pytest .mark .anyio
469
490
async def test_no_scope_changes_when_both_missing (
470
- self , oauth_provider_without_scope : OAuthClientProvider ,
471
- prm_metadata_without_scopes : ProtectedResourceMetadata
491
+ self ,
492
+ oauth_provider_without_scope : OAuthClientProvider ,
493
+ prm_metadata_without_scopes : ProtectedResourceMetadata ,
494
+ oauth_metadata_response_without_scopes : httpx .Response ,
472
495
):
473
496
"""Test that no scope changes occur when both PRM and OAuth metadata lack scopes."""
474
497
provider = oauth_provider_without_scope
475
498
476
499
# Set up PRM metadata without scopes
477
500
provider .context .protected_resource_metadata = prm_metadata_without_scopes
478
501
479
- # Create OAuth metadata response without scopes
480
- custom_oauth_metadata_response = httpx .Response (
481
- 200 ,
482
- content = (
483
- b'{"issuer": "https://auth.example.com", '
484
- b'"authorization_endpoint": "https://auth.example.com/authorize", '
485
- b'"token_endpoint": "https://auth.example.com/token", '
486
- b'"registration_endpoint": "https://auth.example.com/register"}'
487
- # No scopes_supported field
488
- ),
489
- )
490
-
491
502
# Process the OAuth metadata
492
- await provider ._handle_oauth_metadata_response (custom_oauth_metadata_response )
503
+ await provider ._handle_oauth_metadata_response (oauth_metadata_response_without_scopes )
493
504
494
505
# Verify that scope remains None
495
506
assert provider .context .client_metadata .scope is None
496
507
497
508
@pytest .mark .anyio
498
509
async def test_preserve_existing_client_scope (
499
- self , oauth_provider : OAuthClientProvider ,
500
- oauth_metadata_response : httpx .Response , prm_metadata : ProtectedResourceMetadata
510
+ self ,
511
+ oauth_provider : OAuthClientProvider ,
512
+ oauth_metadata_response : httpx .Response ,
513
+ prm_metadata : ProtectedResourceMetadata ,
501
514
):
502
515
"""Test that existing client scope is preserved regardless of metadata."""
503
516
provider = oauth_provider
@@ -1079,4 +1092,3 @@ async def callback_handler() -> tuple[str, str | None]:
1079
1092
1080
1093
result = provider ._extract_resource_metadata_from_www_auth (init_response )
1081
1094
assert result is None , f"Should return None for { description } "
1082
-
0 commit comments