|  | 
|  | 1 | +"""Tests for OAuth 2.0 shared code.""" | 
|  | 2 | + | 
|  | 3 | +from mcp.shared.auth import OAuthMetadata | 
|  | 4 | + | 
|  | 5 | + | 
|  | 6 | +class TestOAuthMetadata: | 
|  | 7 | +    """Tests for OAuthMetadata parsing.""" | 
|  | 8 | + | 
|  | 9 | +    def test_oauth(self): | 
|  | 10 | +        """Should not throw when parsing OAuth metadata.""" | 
|  | 11 | +        OAuthMetadata.model_validate( | 
|  | 12 | +            { | 
|  | 13 | +                "issuer": "https://example.com", | 
|  | 14 | +                "authorization_endpoint": "https://example.com/oauth2/authorize", | 
|  | 15 | +                "token_endpoint": "https://example.com/oauth2/token", | 
|  | 16 | +                "scopes_supported": ["read", "write"], | 
|  | 17 | +                "response_types_supported": ["code", "token"], | 
|  | 18 | +                "token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post"], | 
|  | 19 | +            } | 
|  | 20 | +        ) | 
|  | 21 | + | 
|  | 22 | +    def test_oidc(self): | 
|  | 23 | +        """Should not throw when parsing OIDC metadata.""" | 
|  | 24 | +        OAuthMetadata.model_validate( | 
|  | 25 | +            { | 
|  | 26 | +                "issuer": "https://example.com", | 
|  | 27 | +                "authorization_endpoint": "https://example.com/oauth2/authorize", | 
|  | 28 | +                "token_endpoint": "https://example.com/oauth2/token", | 
|  | 29 | +                "end_session_endpoint": "https://example.com/logout", | 
|  | 30 | +                "id_token_signing_alg_values_supported": ["RS256"], | 
|  | 31 | +                "jwks_uri": "https://example.com/.well-known/jwks.json", | 
|  | 32 | +                "response_types_supported": ["code", "token"], | 
|  | 33 | +                "revocation_endpoint": "https://example.com/oauth2/revoke", | 
|  | 34 | +                "scopes_supported": ["openid", "read", "write"], | 
|  | 35 | +                "subject_types_supported": ["public"], | 
|  | 36 | +                "token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post"], | 
|  | 37 | +                "userinfo_endpoint": "https://example.com/oauth2/userInfo", | 
|  | 38 | +            } | 
|  | 39 | +        ) | 
0 commit comments