fix: preserve committed backup creation success
This commit is contained in:
@@ -20,6 +20,14 @@ function sanitizeEntry(entry) {
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizeCreatedEntry(entry, key) {
|
||||
return {
|
||||
id: entry.id,
|
||||
displayKey: `${key.slice(0, 9)}…${key.slice(-4)}`,
|
||||
createdAt: entry.createdAt
|
||||
};
|
||||
}
|
||||
|
||||
function createOnlineBackupManager({
|
||||
keyring,
|
||||
loadSettings,
|
||||
@@ -56,10 +64,7 @@ function createOnlineBackupManager({
|
||||
} catch {}
|
||||
throw error;
|
||||
}
|
||||
const entries = await listEntries();
|
||||
const entry = entries.find((current) => current.id === prepared.id);
|
||||
if (!entry) throw new Error(ERRORS.create);
|
||||
return { ok: true, entry };
|
||||
return { ok: true, entry: sanitizeCreatedEntry(prepared, created.key) };
|
||||
}
|
||||
|
||||
async function deleteTransaction(id) {
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('transactional online backup manager', () => {
|
||||
|
||||
const result = await fixture.manager.createManaged();
|
||||
|
||||
assert.deepEqual(fixture.events, ['prepare', 'upload', 'commit', 'list']);
|
||||
assert.deepEqual(fixture.events, ['prepare', 'upload', 'commit']);
|
||||
assert.deepEqual(fixture.createArguments, [settings, '2.1.31', fixture.createdAt]);
|
||||
assert.match(fixture.createdAt, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
|
||||
assert.deepEqual(result, {
|
||||
@@ -108,6 +108,26 @@ describe('transactional online backup manager', () => {
|
||||
assert.equal(JSON.stringify(result).includes(key), false);
|
||||
});
|
||||
|
||||
it('keeps a committed create successful without a post-commit keyring read', async () => {
|
||||
const fixture = createFixture({ initialKey: null });
|
||||
fixture.keyring.list = async () => {
|
||||
fixture.events.push('list');
|
||||
throw new Error('list unavailable after commit');
|
||||
};
|
||||
|
||||
const result = await fixture.manager.createManaged();
|
||||
|
||||
assert.deepEqual(fixture.events, ['prepare', 'upload', 'commit']);
|
||||
assert.deepEqual(result, {
|
||||
ok: true,
|
||||
entry: {
|
||||
id,
|
||||
displayKey: `${key.slice(0, 9)}…${key.slice(-4)}`,
|
||||
createdAt: fixture.createdAt
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('does not upload when preparing encrypted local state fails', async () => {
|
||||
const fixture = createFixture({
|
||||
initialKey: null,
|
||||
@@ -262,7 +282,6 @@ describe('transactional online backup manager', () => {
|
||||
'upload:start',
|
||||
'upload:end',
|
||||
'commit',
|
||||
'list',
|
||||
'getKey',
|
||||
`delete:${key}`,
|
||||
'remove'
|
||||
|
||||
Reference in New Issue
Block a user