2FA setup required: the missing-column log reads the error's cause chain
R3-1: the SQL adapters throw "Failed query: …" and put the database's own words
("column … does not exist", "no such column") in the error's cause, so the loud
start-up line never appeared on a real Postgres or SQLite. The reason is now
built from the whole cause chain; other failures (ECONNREFUSED, a locked
database) still only warn. Tested with wrapped errors and against the real
adapter with the column dropped.
Docs and the doctor's fix text name how the migration is applied
(deployment.md 4.3) wherever they said only "before the site serves".
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
01e3813723
commit
b52193ae47
@@ -497,6 +497,39 @@ describe('ipalKit and the 2FA plugin', () => {
|
||||
expect(other.logger.warn).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
expect(String(pg.logger.error.mock.calls[0]?.[0])).toMatch(/prodMigrations.*not in a pre-deployment command/s)
|
||||
|
||||
// What the SQL adapters really throw: Drizzle's "Failed query: …" with the database's own words in `cause`.
|
||||
const wrapped = (name: string, cause: unknown, message = 'Failed query: select count(*) from "users" where …') => {
|
||||
const logger = { error: vi.fn(), warn: vi.fn() }
|
||||
return { logger, payload: { count: async () => { throw Object.assign(new Error(message), { cause }) }, db: { name }, logger } }
|
||||
}
|
||||
for (const real of [
|
||||
wrapped('postgres', Object.assign(new Error('column users.totp_setup_from does not exist'), { code: '42703' })),
|
||||
wrapped('sqlite', new Error('SQLITE_ERROR: no such column: users.totp_setup_from')),
|
||||
wrapped('sqlite', { message: 'no such column: totp_setup_from' }), // a plain object as the cause
|
||||
wrapped('postgres', Object.assign(new Error('driver'), { cause: new Error('column "totp_setup_from" does not exist') })), // two levels down
|
||||
]) {
|
||||
await backfillSetupFrom(real.payload as never, 'users')
|
||||
expect(real.logger.warn).not.toHaveBeenCalled()
|
||||
expect(String(real.logger.error.mock.calls[0]?.[0])).toMatch(/NOBODY CAN LOG IN/)
|
||||
expect(String(real.logger.error.mock.calls[0]?.[0])).toMatch(/totp_setup_from/) // the database's own words are in the line
|
||||
}
|
||||
for (const other of [
|
||||
wrapped('postgres', Object.assign(new Error('connect ECONNREFUSED 127.0.0.1:5432'), { code: 'ECONNREFUSED' })),
|
||||
wrapped('sqlite', new Error('SQLITE_BUSY: database is locked')),
|
||||
wrapped('postgres', new Error('relation "users" does not exist')),
|
||||
]) {
|
||||
await backfillSetupFrom(other.payload as never, 'users')
|
||||
expect(other.logger.error).not.toHaveBeenCalled()
|
||||
expect(other.logger.warn).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
// a cause that points at itself does not loop
|
||||
const loop = new Error('Failed query') as { cause?: unknown } & Error
|
||||
loop.cause = loop
|
||||
const looping = { logger: { error: vi.fn(), warn: vi.fn() }, payload: {} as Record<string, unknown> }
|
||||
looping.payload = { count: async () => { throw loop }, db: { name: 'postgres' }, logger: looping.logger }
|
||||
await backfillSetupFrom(looping.payload as never, 'users')
|
||||
expect(looping.logger.warn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
// The reset removes a second factor: by default only a session that entered its own TOTP code may do it.
|
||||
|
||||
Reference in New Issue
Block a user