-
Notifications
You must be signed in to change notification settings - Fork 2.6k
relax validation #879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pcarleton
merged 7 commits into
modelcontextprotocol:main
from
dr3s:814-relax-validation
Jun 9, 2025
Merged
relax validation #879
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a2643d3
fix failing tests
dr3s 482cb3e
relax validation
dr3s 5eb7d80
format
dr3s 6488b40
fix casing
dr3s d941508
fix pyright
dr3s a79562f
reduce validation
dr3s 28dd7db
Merge branch 'main' into 814-relax-validation
dr3s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 @@ def test_generate_code_verifier(self, oauth_provider): | |
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 @@ def test_generate_code_challenge(self, oauth_provider): | |
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 @@ async def test_register_oauth_client_failure(self, oauth_provider): | |
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): | ||
Comment on lines
+353
to
+354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change those? |
||
"""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 @@ async def test_has_valid_token_expired(self, oauth_provider, oauth_token): | |
@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 @@ async def test_validate_token_scopes_valid(self, oauth_provider, client_metadata | |
oauth_provider.client_metadata = client_metadata | ||
token = OAuthToken( | ||
access_token="test", | ||
token_type="bearer", | ||
token_type="Bearer", | ||
scope="read write", | ||
) | ||
|
||
|
@@ -394,7 +398,7 @@ async def test_validate_token_scopes_subset(self, oauth_provider, client_metadat | |
oauth_provider.client_metadata = client_metadata | ||
token = OAuthToken( | ||
access_token="test", | ||
token_type="bearer", | ||
token_type="Bearer", | ||
scope="read", | ||
) | ||
|
||
|
@@ -409,7 +413,7 @@ async def test_validate_token_scopes_unauthorized( | |
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 @@ async def test_validate_token_scopes_no_requested(self, oauth_provider): | |
oauth_provider.client_metadata.scope = None | ||
token = OAuthToken( | ||
access_token="test", | ||
token_type="bearer", | ||
token_type="Bearer", | ||
scope="admin super", | ||
) | ||
|
||
|
@@ -530,7 +534,7 @@ async def test_refresh_access_token_success( | |
|
||
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 @@ async def test_refresh_access_token_no_refresh_token(self, oauth_provider): | |
"""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 @@ async def test_async_auth_flow_no_token(self, oauth_provider): | |
# 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 @@ def test_scope_priority_client_metadata_first( | |
|
||
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.""" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.