diff --git a/src/server/auth/proxyProvider.test.ts b/src/server/auth/proxyProvider.test.ts index 8c6106ff..ab73d7b4 100644 --- a/src/server/auth/proxyProvider.test.ts +++ b/src/server/auth/proxyProvider.test.ts @@ -64,6 +64,16 @@ describe("Proxy OAuth Server Provider", () => { }); }); + // Add helper function for failed responses + const mockFailedResponse = () => { + (global.fetch as jest.Mock).mockImplementation(() => + Promise.resolve({ + ok: false, + status: 400, + }) + ); + }; + afterEach(() => { global.fetch = originalFetch; jest.clearAllMocks(); @@ -178,13 +188,7 @@ describe("Proxy OAuth Server Provider", () => { }); it("handles token exchange failure", async () => { - (global.fetch as jest.Mock).mockImplementation(() => - Promise.resolve({ - ok: false, - status: 400, - }) - ); - + mockFailedResponse(); await expect( provider.exchangeAuthorizationCode(validClient, "invalid-code") ).rejects.toThrow(ServerError); @@ -221,13 +225,7 @@ describe("Proxy OAuth Server Provider", () => { }); it("handles registration failure", async () => { - (global.fetch as jest.Mock).mockImplementation(() => - Promise.resolve({ - ok: false, - status: 400, - }) - ); - + mockFailedResponse(); const newClient: OAuthClientInformationFull = { client_id: "new-client", redirect_uris: ["https://new-client.com/callback"], @@ -265,13 +263,7 @@ describe("Proxy OAuth Server Provider", () => { }); it("handles revocation failure", async () => { - (global.fetch as jest.Mock).mockImplementation(() => - Promise.resolve({ - ok: false, - status: 400, - }) - ); - + mockFailedResponse(); await expect( provider.revokeToken!(validClient, { token: "invalid-token", diff --git a/src/server/auth/proxyProvider.ts b/src/server/auth/proxyProvider.ts index 81727548..2b5ad3f2 100644 --- a/src/server/auth/proxyProvider.ts +++ b/src/server/auth/proxyProvider.ts @@ -2,6 +2,7 @@ import { Response } from "express"; import { OAuthRegisteredClientsStore } from "./clients.js"; import { OAuthClientInformationFull, + OAuthClientInformationFullSchema, OAuthTokenRevocationRequest, OAuthTokens, OAuthTokensSchema, @@ -106,7 +107,8 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider { throw new ServerError(`Client registration failed: ${response.status}`); } - return response.json(); + const data = await response.json(); + return OAuthClientInformationFullSchema.parse(data); } }) }