@@ -1210,6 +1210,9 @@ def handler(request):
12101210 {"resource" : RESOURCE_URL },
12111211 {"resource" : RESOURCE_URL , "authorization_servers" : []},
12121212 {"resource" : RESOURCE_URL , "authorization_servers" : [1 ]},
1213+ {"resource" : RESOURCE_URL , "authorization_servers" : ["https://as.example.com:bad/x" ]},
1214+ {"resource" : RESOURCE_URL , "authorization_servers" : ["https://[bad" ]},
1215+ {"resource" : RESOURCE_URL , "authorization_servers" : ["http://as.example.com/x" ]},
12131216 ],
12141217 )
12151218 async def test_unusable_challenge_document_falls_back_to_well_known (self , fake , document ):
@@ -1223,6 +1226,24 @@ def handler(request):
12231226 )
12241227 assert (await client_with_handler (handler , fake = fake ).discover (challenge ))["issuer" ] == ISSUER
12251228
1229+ async def test_internal_authorization_server_stops_discovery (self , fake ):
1230+ tried = []
1231+
1232+ def handler (request ):
1233+ tried .append (request .url .host )
1234+ if request .url .host == "metadata.example.com" :
1235+ document = {"resource" : RESOURCE_URL , "authorization_servers" : ["https://10.0.0.5/oauth2" ]}
1236+ return httpx .Response (200 , json = document )
1237+ return fake .handle (request )
1238+
1239+ challenge = httpx .Response (
1240+ 401 , headers = {"WWW-Authenticate" : 'Bearer resource_metadata="https://metadata.example.com/prm"' }
1241+ )
1242+ # Refused outright, with no fallback to the well-known document
1243+ with pytest .raises (DiscoveryError , match = "loopback, private or link-local" ):
1244+ await client_with_handler (handler , fake = fake ).discover (challenge )
1245+ assert tried == ["metadata.example.com" ]
1246+
12261247 @pytest .mark .parametrize (
12271248 "url" ,
12281249 ["https://[bad" , "https://m.example.com:bad/p" , "https://m.example.com:99999/p" , "http://m.example.com/p" ],
0 commit comments