UUID-keyed lookups in SignalProtocolStore
This commit is contained in:
parent
6323aedd9b
commit
c7e7d55af4
46 changed files with 2094 additions and 1447 deletions
|
@ -2,10 +2,12 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { v4 as getGuid } from 'uuid';
|
||||
|
||||
import { getRandomBytes } from '../../Crypto';
|
||||
import AccountManager from '../../textsecure/AccountManager';
|
||||
import { OuterSignedPrekeyType } from '../../textsecure/Types.d';
|
||||
import { UUID } from '../../types/UUID';
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
|
@ -21,15 +23,18 @@ describe('AccountManager', () => {
|
|||
let originalGetIdentityKeyPair: any;
|
||||
let originalLoadSignedPreKeys: any;
|
||||
let originalRemoveSignedPreKey: any;
|
||||
let originalGetUuid: any;
|
||||
let signedPreKeys: Array<OuterSignedPrekeyType>;
|
||||
const DAY = 1000 * 60 * 60 * 24;
|
||||
|
||||
const pubKey = getRandomBytes(33);
|
||||
const privKey = getRandomBytes(32);
|
||||
const identityKey = window.Signal.Curve.generateKeyPair();
|
||||
|
||||
beforeEach(async () => {
|
||||
const identityKey = window.Signal.Curve.generateKeyPair();
|
||||
const ourUuid = new UUID(getGuid());
|
||||
|
||||
originalGetUuid = window.textsecure.storage.user.getUuid;
|
||||
originalGetIdentityKeyPair =
|
||||
window.textsecure.storage.protocol.getIdentityKeyPair;
|
||||
originalLoadSignedPreKeys =
|
||||
|
@ -37,12 +42,15 @@ describe('AccountManager', () => {
|
|||
originalRemoveSignedPreKey =
|
||||
window.textsecure.storage.protocol.removeSignedPreKey;
|
||||
|
||||
window.textsecure.storage.user.getUuid = () => ourUuid;
|
||||
|
||||
window.textsecure.storage.protocol.getIdentityKeyPair = async () =>
|
||||
identityKey;
|
||||
window.textsecure.storage.protocol.loadSignedPreKeys = async () =>
|
||||
signedPreKeys;
|
||||
});
|
||||
afterEach(() => {
|
||||
window.textsecure.storage.user.getUuid = originalGetUuid;
|
||||
window.textsecure.storage.protocol.getIdentityKeyPair = originalGetIdentityKeyPair;
|
||||
window.textsecure.storage.protocol.loadSignedPreKeys = originalLoadSignedPreKeys;
|
||||
window.textsecure.storage.protocol.removeSignedPreKey = originalRemoveSignedPreKey;
|
||||
|
@ -51,7 +59,10 @@ describe('AccountManager', () => {
|
|||
describe('encrypted device name', () => {
|
||||
it('roundtrips', async () => {
|
||||
const deviceName = 'v2.5.0 on Ubunto 20.04';
|
||||
const encrypted = await accountManager.encryptDeviceName(deviceName);
|
||||
const encrypted = await accountManager.encryptDeviceName(
|
||||
deviceName,
|
||||
identityKey
|
||||
);
|
||||
if (!encrypted) {
|
||||
throw new Error('failed to encrypt!');
|
||||
}
|
||||
|
@ -62,7 +73,10 @@ describe('AccountManager', () => {
|
|||
});
|
||||
|
||||
it('handles falsey deviceName', async () => {
|
||||
const encrypted = await accountManager.encryptDeviceName('');
|
||||
const encrypted = await accountManager.encryptDeviceName(
|
||||
'',
|
||||
identityKey
|
||||
);
|
||||
assert.strictEqual(encrypted, null);
|
||||
});
|
||||
});
|
||||
|
@ -146,7 +160,10 @@ describe('AccountManager', () => {
|
|||
];
|
||||
|
||||
let count = 0;
|
||||
window.textsecure.storage.protocol.removeSignedPreKey = async keyId => {
|
||||
window.textsecure.storage.protocol.removeSignedPreKey = async (
|
||||
_,
|
||||
keyId
|
||||
) => {
|
||||
if (keyId !== 4) {
|
||||
throw new Error(`Wrong keys were eliminated! ${keyId}`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue