@@ -212,11 +212,11 @@ describe("OAuth Authorization", () => {
212
212
expect ( url . toString ( ) ) . toBe ( "https://resource.example.com/.well-known/oauth-protected-resource/path?param=value" ) ;
213
213
} ) ;
214
214
215
- it ( "falls back to root discovery when path-aware discovery returns 404 " , async ( ) => {
216
- // First call (path-aware) returns 404
215
+ it . each ( [ 400 , 401 , 403 , 404 , 410 , 422 , 429 ] ) ( "falls back to root discovery when path-aware discovery returns %d " , async ( statusCode ) => {
216
+ // First call (path-aware) returns 4xx
217
217
mockFetch . mockResolvedValueOnce ( {
218
218
ok : false ,
219
- status : 404 ,
219
+ status : statusCode ,
220
220
} ) ;
221
221
222
222
// Second call (root fallback) succeeds
@@ -267,6 +267,20 @@ describe("OAuth Authorization", () => {
267
267
expect ( calls . length ) . toBe ( 2 ) ;
268
268
} ) ;
269
269
270
+ it ( "throws error on 500 status and does not fallback" , async ( ) => {
271
+ // First call (path-aware) returns 500
272
+ mockFetch . mockResolvedValueOnce ( {
273
+ ok : false ,
274
+ status : 500 ,
275
+ } ) ;
276
+
277
+ await expect ( discoverOAuthProtectedResourceMetadata ( "https://resource.example.com/path/name" ) )
278
+ . rejects . toThrow ( ) ;
279
+
280
+ const calls = mockFetch . mock . calls ;
281
+ expect ( calls . length ) . toBe ( 1 ) ; // Should not attempt fallback
282
+ } ) ;
283
+
270
284
it ( "does not fallback when the original URL is already at root path" , async ( ) => {
271
285
// First call (path-aware for root) returns 404
272
286
mockFetch . mockResolvedValueOnce ( {
@@ -907,7 +921,7 @@ describe("OAuth Authorization", () => {
907
921
const metadata = await discoverAuthorizationServerMetadata ( "https://auth.example.com/tenant1" ) ;
908
922
909
923
expect ( metadata ) . toBeUndefined ( ) ;
910
-
924
+
911
925
// Verify that all discovery URLs were attempted
912
926
expect ( mockFetch ) . toHaveBeenCalledTimes ( 8 ) ; // 4 URLs × 2 attempts each (with and without headers)
913
927
} ) ;
0 commit comments