|
2 | 2 | from pydantic import AnyHttpUrl |
3 | 3 |
|
4 | 4 | from mcp.server.auth.routes import build_metadata, validate_issuer_url |
5 | | -from mcp.server.auth.url_validators import validate_redirect_uri |
6 | 5 | from mcp.server.auth.settings import AuthSettings, ClientRegistrationOptions, RevocationOptions |
| 6 | +from mcp.server.auth.url_validators import validate_redirect_uri |
7 | 7 |
|
8 | 8 |
|
9 | 9 | def test_validate_issuer_url_https_allowed(): |
@@ -72,42 +72,43 @@ def test_build_metadata_serves_issuer_without_trailing_slash(): |
72 | 72 | assert served["authorization_endpoint"] == "https://as.example.com/authorize" |
73 | 73 | assert served["token_endpoint"] == "https://as.example.com/token" |
74 | 74 |
|
| 75 | + |
75 | 76 | def test_validate_redirect_uri_https_allowed(): |
76 | | - validate_redirect_uri(AnyHttpUrl('https://example.com/cb')) |
| 77 | + validate_redirect_uri(AnyHttpUrl("https://example.com/cb")) |
77 | 78 |
|
78 | 79 |
|
79 | 80 | def test_validate_redirect_uri_http_localhost_allowed(): |
80 | | - validate_redirect_uri(AnyHttpUrl('http://localhost:3000/cb')) |
| 81 | + validate_redirect_uri(AnyHttpUrl("http://localhost:3000/cb")) |
81 | 82 |
|
82 | 83 |
|
83 | 84 | def test_validate_redirect_uri_http_127_0_0_1_allowed(): |
84 | | - validate_redirect_uri(AnyHttpUrl('http://127.0.0.1:8080/cb')) |
| 85 | + validate_redirect_uri(AnyHttpUrl("http://127.0.0.1:8080/cb")) |
85 | 86 |
|
86 | 87 |
|
87 | 88 | def test_validate_redirect_uri_http_ipv6_loopback_allowed(): |
88 | | - validate_redirect_uri(AnyHttpUrl('http://[::1]:9090/cb')) |
| 89 | + validate_redirect_uri(AnyHttpUrl("http://[::1]:9090/cb")) |
89 | 90 |
|
90 | 91 |
|
91 | 92 | def test_validate_redirect_uri_javascript_scheme_rejected(): |
92 | 93 | with pytest.raises(ValueError, match="Redirect URI must use HTTPS"): |
93 | | - validate_redirect_uri(AnyHttpUrl('javascript:alert(1)')) |
| 94 | + validate_redirect_uri(AnyHttpUrl("javascript:alert(1)")) |
94 | 95 |
|
95 | 96 |
|
96 | 97 | def test_validate_redirect_uri_file_scheme_rejected(): |
97 | 98 | with pytest.raises(ValueError, match="Redirect URI must use HTTPS"): |
98 | | - validate_redirect_uri(AnyHttpUrl('file:///etc/passwd')) |
| 99 | + validate_redirect_uri(AnyHttpUrl("file:///etc/passwd")) |
99 | 100 |
|
100 | 101 |
|
101 | 102 | def test_validate_redirect_uri_http_non_loopback_rejected(): |
102 | 103 | with pytest.raises(ValueError, match="Redirect URI must use HTTPS"): |
103 | | - validate_redirect_uri(AnyHttpUrl('http://evil.com/cb')) |
| 104 | + validate_redirect_uri(AnyHttpUrl("http://evil.com/cb")) |
104 | 105 |
|
105 | 106 |
|
106 | 107 | def test_validate_redirect_uri_fragment_rejected(): |
107 | 108 | with pytest.raises(ValueError, match="Redirect URI must not contain a fragment"): |
108 | | - validate_redirect_uri(AnyHttpUrl('https://example.com/cb#frag')) |
| 109 | + validate_redirect_uri(AnyHttpUrl("https://example.com/cb#frag")) |
109 | 110 |
|
110 | 111 |
|
111 | 112 | def test_validate_redirect_uri_empty_fragment_rejected(): |
112 | 113 | with pytest.raises(ValueError, match="Redirect URI must not contain a fragment"): |
113 | | - validate_redirect_uri(AnyHttpUrl('https://example.com/cb#')) |
| 114 | + validate_redirect_uri(AnyHttpUrl("https://example.com/cb#")) |
0 commit comments