Skip to content

Commit aa5690b

Browse files
committed
Zod parsing for registration response
1 parent c7ce1a2 commit aa5690b

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/server/auth/proxyProvider.test.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ describe("Proxy OAuth Server Provider", () => {
6464
});
6565
});
6666

67+
// Add helper function for failed responses
68+
const mockFailedResponse = () => {
69+
(global.fetch as jest.Mock).mockImplementation(() =>
70+
Promise.resolve({
71+
ok: false,
72+
status: 400,
73+
})
74+
);
75+
};
76+
6777
afterEach(() => {
6878
global.fetch = originalFetch;
6979
jest.clearAllMocks();
@@ -178,13 +188,7 @@ describe("Proxy OAuth Server Provider", () => {
178188
});
179189

180190
it("handles token exchange failure", async () => {
181-
(global.fetch as jest.Mock).mockImplementation(() =>
182-
Promise.resolve({
183-
ok: false,
184-
status: 400,
185-
})
186-
);
187-
191+
mockFailedResponse();
188192
await expect(
189193
provider.exchangeAuthorizationCode(validClient, "invalid-code")
190194
).rejects.toThrow(ServerError);
@@ -221,13 +225,7 @@ describe("Proxy OAuth Server Provider", () => {
221225
});
222226

223227
it("handles registration failure", async () => {
224-
(global.fetch as jest.Mock).mockImplementation(() =>
225-
Promise.resolve({
226-
ok: false,
227-
status: 400,
228-
})
229-
);
230-
228+
mockFailedResponse();
231229
const newClient: OAuthClientInformationFull = {
232230
client_id: "new-client",
233231
redirect_uris: ["https://new-client.com/callback"],
@@ -265,13 +263,7 @@ describe("Proxy OAuth Server Provider", () => {
265263
});
266264

267265
it("handles revocation failure", async () => {
268-
(global.fetch as jest.Mock).mockImplementation(() =>
269-
Promise.resolve({
270-
ok: false,
271-
status: 400,
272-
})
273-
);
274-
266+
mockFailedResponse();
275267
await expect(
276268
provider.revokeToken!(validClient, {
277269
token: "invalid-token",

src/server/auth/proxyProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Response } from "express";
22
import { OAuthRegisteredClientsStore } from "./clients.js";
33
import {
44
OAuthClientInformationFull,
5+
OAuthClientInformationFullSchema,
56
OAuthTokenRevocationRequest,
67
OAuthTokens,
78
OAuthTokensSchema,
@@ -106,7 +107,8 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
106107
throw new ServerError(`Client registration failed: ${response.status}`);
107108
}
108109

109-
return response.json();
110+
const data = await response.json();
111+
return OAuthClientInformationFullSchema.parse(data);
110112
}
111113
})
112114
}

0 commit comments

Comments
 (0)