Add cache support to Signal Protocol Store
This commit is contained in:
parent
1d2c3ae23c
commit
9c540ab977
7 changed files with 171 additions and 52 deletions
|
@ -10,6 +10,7 @@ describe('SignalProtocolStore', () => {
|
|||
|
||||
before(done => {
|
||||
store = textsecure.storage.protocol;
|
||||
store.hydrateCaches();
|
||||
identityKey = {
|
||||
pubKey: libsignal.crypto.getRandomBytes(33),
|
||||
privKey: libsignal.crypto.getRandomBytes(32),
|
||||
|
@ -86,6 +87,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.DEFAULT,
|
||||
});
|
||||
|
||||
await store.hydrateCaches();
|
||||
await store.saveIdentity(identifier, newIdentity);
|
||||
});
|
||||
it('marks the key not firstUse', async () => {
|
||||
|
@ -107,6 +109,7 @@ describe('SignalProtocolStore', () => {
|
|||
nonblockingApproval: false,
|
||||
verified: store.VerifiedStatus.DEFAULT,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
|
||||
await store.saveIdentity(identifier, newIdentity);
|
||||
});
|
||||
|
@ -125,6 +128,8 @@ describe('SignalProtocolStore', () => {
|
|||
nonblockingApproval: false,
|
||||
verified: store.VerifiedStatus.VERIFIED,
|
||||
});
|
||||
|
||||
await store.hydrateCaches();
|
||||
await store.saveIdentity(identifier, newIdentity);
|
||||
});
|
||||
it('sets the new key to unverified', async () => {
|
||||
|
@ -147,6 +152,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.UNVERIFIED,
|
||||
});
|
||||
|
||||
await store.hydrateCaches();
|
||||
await store.saveIdentity(identifier, newIdentity);
|
||||
});
|
||||
it('sets the new key to unverified', async () => {
|
||||
|
@ -168,12 +174,14 @@ describe('SignalProtocolStore', () => {
|
|||
nonblockingApproval: false,
|
||||
verified: store.VerifiedStatus.DEFAULT,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
describe('If it is marked firstUse', () => {
|
||||
before(async () => {
|
||||
const identity = await window.Signal.Data.getIdentityKeyById(number);
|
||||
identity.firstUse = true;
|
||||
await window.Signal.Data.createOrUpdateIdentityKey(identity);
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
it('nothing changes', async () => {
|
||||
await store.saveIdentity(identifier, testKey.pubKey, true);
|
||||
|
@ -188,6 +196,7 @@ describe('SignalProtocolStore', () => {
|
|||
const identity = await window.Signal.Data.getIdentityKeyById(number);
|
||||
identity.firstUse = false;
|
||||
await window.Signal.Data.createOrUpdateIdentityKey(identity);
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
describe('If nonblocking approval is required', () => {
|
||||
let now;
|
||||
|
@ -198,6 +207,7 @@ describe('SignalProtocolStore', () => {
|
|||
);
|
||||
identity.timestamp = now;
|
||||
await window.Signal.Data.createOrUpdateIdentityKey(identity);
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
it('sets non-blocking approval', async () => {
|
||||
await store.saveIdentity(identifier, testKey.pubKey, true);
|
||||
|
@ -311,6 +321,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.DEFAULT,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
}
|
||||
describe('with no public key argument', () => {
|
||||
before(saveRecordDefault);
|
||||
|
@ -370,6 +381,7 @@ describe('SignalProtocolStore', () => {
|
|||
describe('when there is no existing record', () => {
|
||||
before(async () => {
|
||||
await window.Signal.Data.removeIdentityKeyById(number);
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('does nothing', async () => {
|
||||
|
@ -403,6 +415,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.VERIFIED,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('does not save the new identity (because this is a less secure state)', async () => {
|
||||
|
@ -434,6 +447,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.VERIFIED,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('updates the verified status', async () => {
|
||||
|
@ -462,6 +476,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.DEFAULT,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('does not hang', async () => {
|
||||
|
@ -480,6 +495,7 @@ describe('SignalProtocolStore', () => {
|
|||
describe('when there is no existing record', () => {
|
||||
before(async () => {
|
||||
await window.Signal.Data.removeIdentityKeyById(number);
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('saves the new identity and marks it verified', async () => {
|
||||
|
@ -510,6 +526,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.VERIFIED,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('saves the new identity and marks it UNVERIFIED', async () => {
|
||||
|
@ -541,6 +558,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.DEFAULT,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('updates the verified status', async () => {
|
||||
|
@ -571,6 +589,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.UNVERIFIED,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('does not hang', async () => {
|
||||
|
@ -589,6 +608,7 @@ describe('SignalProtocolStore', () => {
|
|||
describe('when there is no existing record', () => {
|
||||
before(async () => {
|
||||
await window.Signal.Data.removeIdentityKeyById(number);
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('saves the new identity and marks it verified', async () => {
|
||||
|
@ -615,6 +635,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.VERIFIED,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('saves the new identity and marks it VERIFIED', async () => {
|
||||
|
@ -646,6 +667,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.UNVERIFIED,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('saves the identity and marks it verified', async () => {
|
||||
|
@ -676,6 +698,7 @@ describe('SignalProtocolStore', () => {
|
|||
verified: store.VerifiedStatus.VERIFIED,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
});
|
||||
|
||||
it('does not hang', async () => {
|
||||
|
@ -703,6 +726,7 @@ describe('SignalProtocolStore', () => {
|
|||
nonblockingApproval: false,
|
||||
});
|
||||
|
||||
await store.hydrateCaches();
|
||||
const untrusted = await store.isUntrusted(number);
|
||||
assert.strictEqual(untrusted, false);
|
||||
});
|
||||
|
@ -716,6 +740,7 @@ describe('SignalProtocolStore', () => {
|
|||
firstUse: false,
|
||||
nonblockingApproval: true,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
|
||||
const untrusted = await store.isUntrusted(number);
|
||||
assert.strictEqual(untrusted, false);
|
||||
|
@ -730,6 +755,7 @@ describe('SignalProtocolStore', () => {
|
|||
firstUse: true,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
|
||||
const untrusted = await store.isUntrusted(number);
|
||||
assert.strictEqual(untrusted, false);
|
||||
|
@ -744,6 +770,8 @@ describe('SignalProtocolStore', () => {
|
|||
firstUse: false,
|
||||
nonblockingApproval: false,
|
||||
});
|
||||
await store.hydrateCaches();
|
||||
|
||||
const untrusted = await store.isUntrusted(number);
|
||||
assert.strictEqual(untrusted, true);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue