fix(backup): refuse a Postgres restore the role or tools cannot run before anything is copied

The admin restore now answers a privileged role, old client tools or an unreachable server with a 400 naming the reason, before it keeps a pre-restore dump. RESTORE_FROM_BACKUP checks the same before it unpacks the archive, and removes the unpacked copy when the load fails.
This commit is contained in:
Maurice
2026-11-23 14:57:15 +01:00
parent e630e92183
commit 89da19e535
5 changed files with 112 additions and 13 deletions
@@ -136,6 +136,26 @@ describe('PostgresDatabaseBackup', () => {
else expect(refused.message).toMatch(message);
});
it.each([
{
id: 'PGBACKUP-002f',
server: { privileged: true },
message: /^TREK_DB_URL connects as a superuser or a member of a superuser role/,
},
{
id: 'PGBACKUP-002g',
server: { versionNum: '180001' },
message: /^pg_restore is version 17, older than the PostgreSQL 18 server/,
},
])('$id: verify refuses what the restore itself would refuse, before a copy is kept', async ({ server, message }) => {
writeFileSync(path.join(extract, 'travel.pgdump'), 'dump');
installFakeTool(bin, 'pg_restore', { snippets: [listsMigrations(KNOWN.slice(0, 3))] });
installFakeTool(bin, 'psql', { snippets: [answersSchema('public', 'public', server)] });
const refused = await refusal(backup.verify(extract));
expect(refused.status).toBe(400);
expect(refused.message).toMatch(message);
});
it('PGBACKUP-003: keeps a dump of the database a restore replaces, or says it could not', async () => {
vi.spyOn(console, 'log').mockImplementation(() => undefined);
vi.spyOn(console, 'warn').mockImplementation(() => undefined);