Skip to content

Commit c2d714a

Browse files
committed
add test for 500
1 parent d4da6c6 commit c2d714a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/client/auth.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ describe("OAuth Authorization", () => {
212212
expect(url.toString()).toBe("https://resource.example.com/.well-known/oauth-protected-resource/path?param=value");
213213
});
214214

215-
it("falls back to root discovery when path-aware discovery fails", async () => {
215+
it.each([400, 401, 403, 404, 410, 422, 429])("falls back to root discovery when path-aware discovery returns %d", async (statusCode) => {
216216
// First call (path-aware) returns 4xx
217217
mockFetch.mockResolvedValueOnce({
218218
ok: false,
219-
status: 401,
219+
status: statusCode,
220220
});
221221

222222
// Second call (root fallback) succeeds
@@ -267,6 +267,20 @@ describe("OAuth Authorization", () => {
267267
expect(calls.length).toBe(2);
268268
});
269269

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+
270284
it("does not fallback when the original URL is already at root path", async () => {
271285
// First call (path-aware for root) returns 404
272286
mockFetch.mockResolvedValueOnce({

0 commit comments

Comments
 (0)