Include sender keys in SignalProtocolStore zones

This commit is contained in:
Scott Nonnenberg 2022-01-07 18:12:13 -08:00 committed by GitHub
parent a17e157e7b
commit 06165cb742
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 231 additions and 108 deletions

View file

@ -1442,7 +1442,9 @@ describe('SignalProtocolStore', () => {
});
describe('zones', () => {
const distributionId = UUID.generate().toString();
const zone = new Zone('zone', {
pendingSenderKeys: true,
pendingSessions: true,
pendingUnprocessed: true,
});
@ -1450,6 +1452,7 @@ describe('SignalProtocolStore', () => {
beforeEach(async () => {
await store.removeAllUnprocessed();
await store.removeAllSessions(theirUuid.toString());
await store.removeAllSenderKeys();
});
it('should not store pending sessions in global zone', async () => {
@ -1467,12 +1470,29 @@ describe('SignalProtocolStore', () => {
assert.equal(await store.loadSession(id), testRecord);
});
it('commits session stores and unprocessed on success', async () => {
it('should not store pending sender keys in global zone', async () => {
const id = new QualifiedAddress(ourUuid, new Address(theirUuid, 1));
const testRecord = getSessionRecord();
const testRecord = getSenderKeyRecord();
await assert.isRejected(
store.withZone(GLOBAL_ZONE, 'test', async () => {
await store.saveSenderKey(id, distributionId, testRecord);
throw new Error('Failure');
}),
'Failure'
);
assert.equal(await store.getSenderKey(id, distributionId), testRecord);
});
it('commits sender keys, sessions and unprocessed on success', async () => {
const id = new QualifiedAddress(ourUuid, new Address(theirUuid, 1));
const testSession = getSessionRecord();
const testSenderKey = getSenderKeyRecord();
await store.withZone(zone, 'test', async () => {
await store.storeSession(id, testRecord, { zone });
await store.storeSession(id, testSession, { zone });
await store.saveSenderKey(id, distributionId, testSenderKey, { zone });
await store.addUnprocessed(
{
@ -1484,10 +1504,16 @@ describe('SignalProtocolStore', () => {
},
{ zone }
);
assert.equal(await store.loadSession(id, { zone }), testRecord);
assert.equal(await store.loadSession(id, { zone }), testSession);
assert.equal(
await store.getSenderKey(id, distributionId, { zone }),
testSenderKey
);
});
assert.equal(await store.loadSession(id), testRecord);
assert.equal(await store.loadSession(id), testSession);
assert.equal(await store.getSenderKey(id, distributionId), testSenderKey);
const allUnprocessed = await store.getAllUnprocessed();
assert.deepEqual(
@ -1496,18 +1522,31 @@ describe('SignalProtocolStore', () => {
);
});
it('reverts session stores and unprocessed on error', async () => {
it('reverts sender keys, sessions and unprocessed on error', async () => {
const id = new QualifiedAddress(ourUuid, new Address(theirUuid, 1));
const testRecord = getSessionRecord();
const failedRecord = getSessionRecord();
const testSession = getSessionRecord();
const failedSession = getSessionRecord();
const testSenderKey = getSenderKeyRecord();
const failedSenderKey = getSenderKeyRecord();
await store.storeSession(id, testRecord);
assert.equal(await store.loadSession(id), testRecord);
await store.storeSession(id, testSession);
assert.equal(await store.loadSession(id), testSession);
await store.saveSenderKey(id, distributionId, testSenderKey);
assert.equal(await store.getSenderKey(id, distributionId), testSenderKey);
await assert.isRejected(
store.withZone(zone, 'test', async () => {
await store.storeSession(id, failedRecord, { zone });
assert.equal(await store.loadSession(id, { zone }), failedRecord);
await store.storeSession(id, failedSession, { zone });
assert.equal(await store.loadSession(id, { zone }), failedSession);
await store.saveSenderKey(id, distributionId, failedSenderKey, {
zone,
});
assert.equal(
await store.getSenderKey(id, distributionId, { zone }),
failedSenderKey
);
await store.addUnprocessed(
{
@ -1525,7 +1564,8 @@ describe('SignalProtocolStore', () => {
'Failure'
);
assert.equal(await store.loadSession(id), testRecord);
assert.equal(await store.loadSession(id), testSession);
assert.equal(await store.getSenderKey(id, distributionId), testSenderKey);
assert.deepEqual(await store.getAllUnprocessed(), []);
});