diff --git a/src/app.ts b/src/app.ts index a1d9a2f..299364a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1326,11 +1326,13 @@ export async function buildApp(options: BuildAppOptions = {}): Promise { }); }); +describe("the failed-callback audit event", () => { + it("keeps the error's class and code, not its text", async () => { + const store = new InMemoryStore(); + const app = await buildApp({ + config: createTestConfig(), + store, + oauthRuntimes: { + discord: { + ...createMockDiscordRuntime(), + async exchangeAuthorizationCode() { + throw Object.assign(new Error("getaddrinfo ENOTFOUND CANARYhost.invalid"), { code: "ENOTFOUND" }); + }, + }, + }, + }); + apps.push(app); + + const stateToken = await startDiscordSignIn(app); + const response = await app.inject({ + method: "GET", + url: `/v1/oauth/discord/callback?code=test-code&state=${encodeURIComponent(stateToken)}`, + }); + expect(response.statusCode).toBe(502); + + const events = [...(store as unknown as { auditEvents: Map }).auditEvents.values()]; + const failed = events.filter((event) => event.eventType === "oauth_callback_failed"); + expect(failed).toHaveLength(1); + expect(failed[0]!.eventPayloadJson).toEqual({ + provider: "discord", + mode: "sign_in", + errorClass: "Error", + errorCode: "ENOTFOUND", + }); + expect(JSON.stringify(events)).not.toContain("CANARY"); + }); +});