mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user