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({
|
function createOnlineBackupManager({
|
||||||
keyring,
|
keyring,
|
||||||
loadSettings,
|
loadSettings,
|
||||||
@@ -56,10 +64,7 @@ function createOnlineBackupManager({
|
|||||||
} catch {}
|
} catch {}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
const entries = await listEntries();
|
return { ok: true, entry: sanitizeCreatedEntry(prepared, created.key) };
|
||||||
const entry = entries.find((current) => current.id === prepared.id);
|
|
||||||
if (!entry) throw new Error(ERRORS.create);
|
|
||||||
return { ok: true, entry };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteTransaction(id) {
|
async function deleteTransaction(id) {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ describe('transactional online backup manager', () => {
|
|||||||
|
|
||||||
const result = await fixture.manager.createManaged();
|
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.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.match(fixture.createdAt, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
|
||||||
assert.deepEqual(result, {
|
assert.deepEqual(result, {
|
||||||
@@ -108,6 +108,26 @@ describe('transactional online backup manager', () => {
|
|||||||
assert.equal(JSON.stringify(result).includes(key), false);
|
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 () => {
|
it('does not upload when preparing encrypted local state fails', async () => {
|
||||||
const fixture = createFixture({
|
const fixture = createFixture({
|
||||||
initialKey: null,
|
initialKey: null,
|
||||||
@@ -262,7 +282,6 @@ describe('transactional online backup manager', () => {
|
|||||||
'upload:start',
|
'upload:start',
|
||||||
'upload:end',
|
'upload:end',
|
||||||
'commit',
|
'commit',
|
||||||
'list',
|
|
||||||
'getKey',
|
'getKey',
|
||||||
`delete:${key}`,
|
`delete:${key}`,
|
||||||
'remove'
|
'remove'
|
||||||
|
|||||||
Reference in New Issue
Block a user