relax validation (#879)

This commit is contained in:
dr3s
2025-06-09 14:21:01 -04:00
committed by GitHub
parent 2cbc435c6c
commit 1a9ead07f5
4 changed files with 41 additions and 34 deletions

View File

@@ -91,7 +91,7 @@ def oauth_client_info():
def oauth_token():
return OAuthToken(
access_token="test_access_token",
token_type="bearer",
token_type="Bearer",
expires_in=3600,
refresh_token="test_refresh_token",
scope="read write",
@@ -143,7 +143,8 @@ class TestOAuthClientProvider:
verifiers = {oauth_provider._generate_code_verifier() for _ in range(10)}
assert len(verifiers) == 10
def test_generate_code_challenge(self, oauth_provider):
@pytest.mark.anyio
async def test_generate_code_challenge(self, oauth_provider):
"""Test PKCE code challenge generation."""
verifier = "test_code_verifier_123"
challenge = oauth_provider._generate_code_challenge(verifier)
@@ -161,7 +162,8 @@ class TestOAuthClientProvider:
assert "+" not in challenge
assert "/" not in challenge
def test_get_authorization_base_url(self, oauth_provider):
@pytest.mark.anyio
async def test_get_authorization_base_url(self, oauth_provider):
"""Test authorization base URL extraction."""
# Test with path
assert (
@@ -348,11 +350,13 @@ class TestOAuthClientProvider:
None,
)
def test_has_valid_token_no_token(self, oauth_provider):
@pytest.mark.anyio
async def test_has_valid_token_no_token(self, oauth_provider):
"""Test token validation with no token."""
assert not oauth_provider._has_valid_token()
def test_has_valid_token_valid(self, oauth_provider, oauth_token):
@pytest.mark.anyio
async def test_has_valid_token_valid(self, oauth_provider, oauth_token):
"""Test token validation with valid token."""
oauth_provider._current_tokens = oauth_token
oauth_provider._token_expiry_time = time.time() + 3600 # Future expiry
@@ -370,7 +374,7 @@ class TestOAuthClientProvider:
@pytest.mark.anyio
async def test_validate_token_scopes_no_scope(self, oauth_provider):
"""Test scope validation with no scope returned."""
token = OAuthToken(access_token="test", token_type="bearer")
token = OAuthToken(access_token="test", token_type="Bearer")
# Should not raise exception
await oauth_provider._validate_token_scopes(token)
@@ -381,7 +385,7 @@ class TestOAuthClientProvider:
oauth_provider.client_metadata = client_metadata
token = OAuthToken(
access_token="test",
token_type="bearer",
token_type="Bearer",
scope="read write",
)
@@ -394,7 +398,7 @@ class TestOAuthClientProvider:
oauth_provider.client_metadata = client_metadata
token = OAuthToken(
access_token="test",
token_type="bearer",
token_type="Bearer",
scope="read",
)
@@ -409,7 +413,7 @@ class TestOAuthClientProvider:
oauth_provider.client_metadata = client_metadata
token = OAuthToken(
access_token="test",
token_type="bearer",
token_type="Bearer",
scope="read write admin", # Includes unauthorized "admin"
)
@@ -423,7 +427,7 @@ class TestOAuthClientProvider:
oauth_provider.client_metadata.scope = None
token = OAuthToken(
access_token="test",
token_type="bearer",
token_type="Bearer",
scope="admin super",
)
@@ -530,7 +534,7 @@ class TestOAuthClientProvider:
new_token = OAuthToken(
access_token="new_access_token",
token_type="bearer",
token_type="Bearer",
expires_in=3600,
refresh_token="new_refresh_token",
scope="read write",
@@ -563,7 +567,7 @@ class TestOAuthClientProvider:
"""Test token refresh with no refresh token."""
oauth_provider._current_tokens = OAuthToken(
access_token="test",
token_type="bearer",
token_type="Bearer",
# No refresh_token
)
@@ -756,7 +760,8 @@ class TestOAuthClientProvider:
# No Authorization header should be added if no token
assert "Authorization" not in updated_request.headers
def test_scope_priority_client_metadata_first(
@pytest.mark.anyio
async def test_scope_priority_client_metadata_first(
self, oauth_provider, oauth_client_info
):
"""Test that client metadata scope takes priority."""
@@ -785,7 +790,8 @@ class TestOAuthClientProvider:
assert auth_params["scope"] == "read write"
def test_scope_priority_no_client_metadata_scope(
@pytest.mark.anyio
async def test_scope_priority_no_client_metadata_scope(
self, oauth_provider, oauth_client_info
):
"""Test that no scope parameter is set when client metadata has no scope."""