|
1 | 1 | """Tests for OAuth 2.0 shared code.""" |
2 | 2 |
|
3 | 3 | import pytest |
4 | | -from pydantic import AnyUrl, ValidationError |
5 | | - |
6 | | -from mcp.shared.auth import InvalidRedirectUriError, OAuthClientInformationFull, OAuthClientMetadata, OAuthMetadata |
| 4 | +from pydantic import AnyHttpUrl, AnyUrl, ValidationError |
| 5 | + |
| 6 | +from mcp.shared.auth import ( |
| 7 | + InvalidRedirectUriError, |
| 8 | + OAuthClientInformationFull, |
| 9 | + OAuthClientMetadata, |
| 10 | + OAuthMetadata, |
| 11 | + ProtectedResourceMetadata, |
| 12 | +) |
7 | 13 |
|
8 | 14 |
|
9 | 15 | def test_oauth(): |
@@ -109,6 +115,27 @@ def test_valid_url_passes_through_unchanged(): |
109 | 115 | assert str(metadata.client_uri) == "https://udemy.com/" |
110 | 116 |
|
111 | 117 |
|
| 118 | +def test_protected_resource_metadata_preserves_empty_root_path(): |
| 119 | + metadata = ProtectedResourceMetadata.model_validate( |
| 120 | + { |
| 121 | + "resource": "https://example.com", |
| 122 | + "authorization_servers": ["https://auth.example.com"], |
| 123 | + } |
| 124 | + ) |
| 125 | + |
| 126 | + assert str(metadata.resource) == "https://example.com" |
| 127 | + assert '"resource":"https://example.com"' in metadata.model_dump_json() |
| 128 | + |
| 129 | + |
| 130 | +def test_protected_resource_metadata_strips_normalized_root_path(): |
| 131 | + metadata = ProtectedResourceMetadata( |
| 132 | + resource=AnyHttpUrl("https://example.com"), |
| 133 | + authorization_servers=[AnyHttpUrl("https://auth.example.com")], |
| 134 | + ) |
| 135 | + |
| 136 | + assert str(metadata.resource) == "https://example.com" |
| 137 | + |
| 138 | + |
112 | 139 | def test_information_full_inherits_coercion(): |
113 | 140 | """OAuthClientInformationFull shares the metadata base, so the same |
114 | 141 | coercion applies to DCR responses parsed via the full model.""" |
|
0 commit comments