|
1 | 1 | """Tests for OAuth 2.0 shared code.""" |
2 | 2 |
|
3 | | -import pytest |
4 | | - |
5 | | -from mcp.shared.auth import OAuthMetadata, ProtectedResourceMetadata |
| 3 | +from mcp.shared.auth import OAuthMetadata |
6 | 4 |
|
7 | 5 |
|
8 | 6 | class TestOAuthMetadata: |
@@ -39,84 +37,3 @@ def test_oidc(self): |
39 | 37 | "userinfo_endpoint": "https://example.com/oauth2/userInfo", |
40 | 38 | } |
41 | 39 | ) |
42 | | - |
43 | | - |
44 | | -class TestProtectedResourceMetadataInvalid: |
45 | | - """Tests for ProtectedResourceMetadata parsing.""" |
46 | | - |
47 | | - def test_invalid_metadata(self): |
48 | | - """Should throw when parsing invalid metadata.""" |
49 | | - with pytest.raises(ValueError): |
50 | | - ProtectedResourceMetadata.model_validate( |
51 | | - { |
52 | | - "resource": "Not a valid URL", |
53 | | - "authorization_servers": ["https://example.com/oauth2/authorize"], |
54 | | - "scopes_supported": ["read", "write"], |
55 | | - "bearer_methods_supported": ["header"], |
56 | | - } |
57 | | - ) |
58 | | - |
59 | | - def test_valid_metadata(self): |
60 | | - """Should not throw when parsing protected resource metadata.""" |
61 | | - |
62 | | - ProtectedResourceMetadata.model_validate( |
63 | | - { |
64 | | - "resource": "https://example.com/resource", |
65 | | - "authorization_servers": ["https://example.com/oauth2/authorize"], |
66 | | - "scopes_supported": ["read", "write"], |
67 | | - "bearer_methods_supported": ["header"], |
68 | | - } |
69 | | - ) |
70 | | - |
71 | | - def test_valid_with_resource_metadata(self): |
72 | | - """Should not throw when parsing metadata with resource_name and resource_documentation.""" |
73 | | - |
74 | | - ProtectedResourceMetadata.model_validate( |
75 | | - { |
76 | | - "resource": "https://example.com/resource", |
77 | | - "authorization_servers": ["https://example.com/oauth2/authorize"], |
78 | | - "scopes_supported": ["read", "write"], |
79 | | - "bearer_methods_supported": ["header"], |
80 | | - "resource_name": "Example Resource", |
81 | | - "resource_documentation": "https://example.com/resource/documentation", |
82 | | - } |
83 | | - ) |
84 | | - |
85 | | - def test_valid_with_invalid_resource_documentation(self): |
86 | | - """Should throw when parsing metadata with resource_name and invalid resource_documentation.""" |
87 | | - with pytest.raises(ValueError): |
88 | | - ProtectedResourceMetadata.model_validate( |
89 | | - { |
90 | | - "resource": "https://example.com/resource", |
91 | | - "authorization_servers": ["https://example.com/oauth2/authorize"], |
92 | | - "scopes_supported": ["read", "write"], |
93 | | - "bearer_methods_supported": ["header"], |
94 | | - "resource_name": "Example Resource", |
95 | | - "resource_documentation": "Not a valid URL", |
96 | | - } |
97 | | - ) |
98 | | - |
99 | | - def test_valid_full_protected_resource_metadata(self): |
100 | | - """Should not throw when parsing full metadata.""" |
101 | | - |
102 | | - ProtectedResourceMetadata.model_validate( |
103 | | - { |
104 | | - "resource": "https://example.com/resource", |
105 | | - "authorization_servers": ["https://example.com/oauth2/authorize"], |
106 | | - "jwks_uri": "https://example.com/.well-known/jwks.json", |
107 | | - "scopes_supported": ["read", "write"], |
108 | | - "bearer_methods_supported": ["header"], |
109 | | - "resource_signing_alg_values_supported": ["RS256"], |
110 | | - "resource_name": "Example Resource", |
111 | | - "resource_documentation": "https://example.com/resource/documentation", |
112 | | - "resource_policy_uri": "https://example.com/resource/policy", |
113 | | - "resource_tos_uri": "https://example.com/resource/tos", |
114 | | - "tls_client_certificate_bound_access_tokens": True, |
115 | | - # authorization_details_types_supported is a complex type |
116 | | - # so we use an empty list for simplicity |
117 | | - # see RFC9396 |
118 | | - "authorization_details_types_supported": [], |
119 | | - "dpop_signing_alg_values_supported": ["RS256", "ES256"], |
120 | | - "dpop_signing_access_tokens": True, |
121 | | - } |
122 | | - ) |
0 commit comments