22
33import json
44
5+ from pydantic import AnyHttpUrl
6+
57from mcp .shared .auth import OAuthMetadata , ProtectedResourceMetadata
68
79
@@ -74,9 +76,9 @@ class TestIssuerTrailingSlash:
7476 def test_oauth_metadata_issuer_no_trailing_slash_in_json (self ):
7577 """Serialized issuer should not have trailing slash."""
7678 metadata = OAuthMetadata (
77- issuer = "https://example.com" ,
78- authorization_endpoint = "https://example.com/oauth2/authorize" ,
79- token_endpoint = "https://example.com/oauth2/token" ,
79+ issuer = AnyHttpUrl ( "https://example.com" ) ,
80+ authorization_endpoint = AnyHttpUrl ( "https://example.com/oauth2/authorize" ) ,
81+ token_endpoint = AnyHttpUrl ( "https://example.com/oauth2/token" ) ,
8082 )
8183 serialized = json .loads (metadata .model_dump_json ())
8284 assert serialized ["issuer" ] == "https://example.com"
@@ -85,9 +87,9 @@ def test_oauth_metadata_issuer_no_trailing_slash_in_json(self):
8587 def test_oauth_metadata_issuer_with_path_preserves_path (self ):
8688 """Issuer with path should preserve the path, only strip trailing slash."""
8789 metadata = OAuthMetadata (
88- issuer = "https://example.com/auth" ,
89- authorization_endpoint = "https://example.com/oauth2/authorize" ,
90- token_endpoint = "https://example.com/oauth2/token" ,
90+ issuer = AnyHttpUrl ( "https://example.com/auth" ) ,
91+ authorization_endpoint = AnyHttpUrl ( "https://example.com/oauth2/authorize" ) ,
92+ token_endpoint = AnyHttpUrl ( "https://example.com/oauth2/token" ) ,
9193 )
9294 serialized = json .loads (metadata .model_dump_json ())
9395 assert serialized ["issuer" ] == "https://example.com/auth"
@@ -96,18 +98,18 @@ def test_oauth_metadata_issuer_with_path_preserves_path(self):
9698 def test_oauth_metadata_issuer_with_path_and_trailing_slash (self ):
9799 """Issuer with path and trailing slash should only strip the trailing slash."""
98100 metadata = OAuthMetadata (
99- issuer = "https://example.com/auth/" ,
100- authorization_endpoint = "https://example.com/oauth2/authorize" ,
101- token_endpoint = "https://example.com/oauth2/token" ,
101+ issuer = AnyHttpUrl ( "https://example.com/auth/" ) ,
102+ authorization_endpoint = AnyHttpUrl ( "https://example.com/oauth2/authorize" ) ,
103+ token_endpoint = AnyHttpUrl ( "https://example.com/oauth2/token" ) ,
102104 )
103105 serialized = json .loads (metadata .model_dump_json ())
104106 assert serialized ["issuer" ] == "https://example.com/auth"
105107
106108 def test_protected_resource_metadata_no_trailing_slash (self ):
107109 """ProtectedResourceMetadata.resource should not have trailing slash."""
108110 metadata = ProtectedResourceMetadata (
109- resource = "https://example.com" ,
110- authorization_servers = ["https://auth.example.com" ],
111+ resource = AnyHttpUrl ( "https://example.com" ) ,
112+ authorization_servers = [AnyHttpUrl ( "https://auth.example.com" ) ],
111113 )
112114 serialized = json .loads (metadata .model_dump_json ())
113115 assert serialized ["resource" ] == "https://example.com"
@@ -116,10 +118,10 @@ def test_protected_resource_metadata_no_trailing_slash(self):
116118 def test_protected_resource_metadata_auth_servers_no_trailing_slash (self ):
117119 """ProtectedResourceMetadata.authorization_servers should not have trailing slashes."""
118120 metadata = ProtectedResourceMetadata (
119- resource = "https://example.com" ,
121+ resource = AnyHttpUrl ( "https://example.com" ) ,
120122 authorization_servers = [
121- "https://auth1.example.com" ,
122- "https://auth2.example.com/path" ,
123+ AnyHttpUrl ( "https://auth1.example.com" ) ,
124+ AnyHttpUrl ( "https://auth2.example.com/path" ) ,
123125 ],
124126 )
125127 serialized = json .loads (metadata .model_dump_json ())
0 commit comments