|
1 | 1 | """Tests for OAuth 2.0 shared code.""" |
2 | 2 |
|
| 3 | +from typing import Any |
| 4 | + |
3 | 5 | import pytest |
4 | | -from pydantic import ValidationError |
| 6 | +from pydantic import AnyHttpUrl, AnyUrl, ValidationError |
5 | 7 |
|
6 | 8 | from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthMetadata |
7 | 9 |
|
@@ -109,6 +111,27 @@ def test_valid_url_passes_through_unchanged(): |
109 | 111 | assert str(metadata.client_uri) == "https://udemy.com/" |
110 | 112 |
|
111 | 113 |
|
| 114 | +@pytest.mark.parametrize( |
| 115 | + "redirect_uris", |
| 116 | + [ |
| 117 | + [AnyHttpUrl("https://example.com/callback")], |
| 118 | + (AnyHttpUrl("https://example.com/callback"),), |
| 119 | + {AnyHttpUrl("https://example.com/callback")}, |
| 120 | + frozenset({AnyHttpUrl("https://example.com/callback")}), |
| 121 | + ], |
| 122 | +) |
| 123 | +def test_redirect_uri_url_subtypes_are_normalized(redirect_uris: Any): |
| 124 | + info = OAuthClientInformationFull( |
| 125 | + client_id="abc123", |
| 126 | + redirect_uris=redirect_uris, |
| 127 | + ) |
| 128 | + |
| 129 | + incoming = AnyUrl("https://example.com/callback") |
| 130 | + |
| 131 | + assert info.validate_redirect_uri(incoming) == incoming |
| 132 | + assert info.model_dump(mode="json")["redirect_uris"] == ["https://example.com/callback"] |
| 133 | + |
| 134 | + |
112 | 135 | def test_information_full_inherits_coercion(): |
113 | 136 | """OAuthClientInformationFull subclasses OAuthClientMetadata, so the |
114 | 137 | same coercion applies to DCR responses parsed via the full model.""" |
|
0 commit comments