From 4a8975e4b815ad50e997749b156745647350d672 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 28 Nov 2026 04:10:58 -0800 Subject: [PATCH] fix(auth): clean up the anonymous audit row from the malformed sign-in integration test The rejected sign-in is audited with no resourceId, so the user-scoped afterEach cleanup missed it. The test now sends a unique user-agent, waits for its audit row, and deletes it in finally, matching the legacy-collision test in the same file. --- .../lib/auth/lifecycle-audit.integration.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/sim/lib/auth/lifecycle-audit.integration.ts b/apps/sim/lib/auth/lifecycle-audit.integration.ts index f8fd38023a6..4887e47533f 100644 --- a/apps/sim/lib/auth/lifecycle-audit.integration.ts +++ b/apps/sim/lib/auth/lifecycle-audit.integration.ts @@ -199,10 +199,21 @@ describe('authentication audit history in PostgreSQL', () => { }) it('answers a non-string email with a validation error instead of crashing the sign-in hook', async () => { - const response = await auth.handler( - request('/sign-in/email', { email: { $ne: null }, password: fixturePassword }) - ) - expect(response.status).toBe(400) + const agent = `Malformed sign-in fixture ${generateId()}` + const attempt = request('/sign-in/email', { email: { $ne: null }, password: fixturePassword }) + attempt.headers.set('user-agent', agent) + try { + const response = await auth.handler(attempt) + expect(response.status).toBe(400) + // The rejection is audited anonymously (no resourceId), which the user-scoped cleanup misses. + await expect + .poll( + async () => (await db.select().from(auditLog).where(eq(auditLog.userAgent, agent))).length + ) + .toBe(1) + } finally { + await db.delete(auditLog).where(eq(auditLog.userAgent, agent)) + } }) it('records suspended-account denial without claiming a successful login', async () => {