eslintify all test files
This commit is contained in:
parent
884bc9333d
commit
dbf0be2db5
44 changed files with 1469 additions and 1484 deletions
|
@ -1,10 +1,11 @@
|
|||
/* global libsignal, textsecure */
|
||||
|
||||
describe('SignalProtocolStore', () => {
|
||||
before(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
const store = textsecure.storage.protocol;
|
||||
const identifier = '+5558675309';
|
||||
const another_identifier = '+5555590210';
|
||||
const identityKey = {
|
||||
pubKey: libsignal.crypto.getRandomBytes(33),
|
||||
privKey: libsignal.crypto.getRandomBytes(32),
|
||||
|
@ -13,176 +14,121 @@ describe('SignalProtocolStore', () => {
|
|||
pubKey: libsignal.crypto.getRandomBytes(33),
|
||||
privKey: libsignal.crypto.getRandomBytes(32),
|
||||
};
|
||||
it('retrieves my registration id', done => {
|
||||
it('retrieves my registration id', async () => {
|
||||
store.put('registrationId', 1337);
|
||||
store
|
||||
.getLocalRegistrationId()
|
||||
.then(reg => {
|
||||
assert.strictEqual(reg, 1337);
|
||||
})
|
||||
.then(done, done);
|
||||
|
||||
const reg = await store.getLocalRegistrationId();
|
||||
assert.strictEqual(reg, 1337);
|
||||
});
|
||||
it('retrieves my identity key', done => {
|
||||
it('retrieves my identity key', async () => {
|
||||
store.put('identityKey', identityKey);
|
||||
store
|
||||
.getIdentityKeyPair()
|
||||
.then(key => {
|
||||
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
||||
const key = await store.getIdentityKeyPair();
|
||||
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
||||
});
|
||||
it('stores identity keys', async () => {
|
||||
await store.saveIdentity(identifier, testKey.pubKey);
|
||||
const key = await store.loadIdentityKey(identifier);
|
||||
assertEqualArrayBuffers(key, testKey.pubKey);
|
||||
});
|
||||
it('returns whether a key is trusted', async () => {
|
||||
const newIdentity = libsignal.crypto.getRandomBytes(33);
|
||||
await store.saveIdentity(identifier, testKey.pubKey);
|
||||
|
||||
const trusted = await store.isTrustedIdentity(identifier, newIdentity);
|
||||
if (trusted) {
|
||||
throw new Error('Allowed to overwrite identity key');
|
||||
}
|
||||
});
|
||||
it('returns whether a key is untrusted', async () => {
|
||||
await store.saveIdentity(identifier, testKey.pubKey);
|
||||
const trusted = await store.isTrustedIdentity(identifier, testKey.pubKey);
|
||||
|
||||
if (!trusted) {
|
||||
throw new Error('Allowed to overwrite identity key');
|
||||
}
|
||||
});
|
||||
it('stores prekeys', async () => {
|
||||
await store.storePreKey(1, testKey);
|
||||
|
||||
const key = await store.loadPreKey(1);
|
||||
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
||||
});
|
||||
it('deletes prekeys', async () => {
|
||||
await store.storePreKey(2, testKey);
|
||||
await store.removePreKey(2, testKey);
|
||||
|
||||
const key = await store.loadPreKey(2);
|
||||
assert.isUndefined(key);
|
||||
});
|
||||
it('stores signed prekeys', async () => {
|
||||
await store.storeSignedPreKey(3, testKey);
|
||||
|
||||
const key = await store.loadSignedPreKey(3);
|
||||
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
||||
});
|
||||
it('deletes signed prekeys', async () => {
|
||||
await store.storeSignedPreKey(4, testKey);
|
||||
await store.removeSignedPreKey(4, testKey);
|
||||
|
||||
const key = await store.loadSignedPreKey(4);
|
||||
assert.isUndefined(key);
|
||||
});
|
||||
it('stores sessions', async () => {
|
||||
const testRecord = 'an opaque string';
|
||||
const devices = [1, 2, 3].map(deviceId => [identifier, deviceId].join('.'));
|
||||
|
||||
await Promise.all(
|
||||
devices.map(async encodedNumber => {
|
||||
await store.storeSession(encodedNumber, testRecord + encodedNumber);
|
||||
})
|
||||
.then(done, done);
|
||||
);
|
||||
|
||||
const records = await Promise.all(
|
||||
devices.map(store.loadSession.bind(store))
|
||||
);
|
||||
|
||||
for (let i = 0, max = records.length; i < max; i += 1) {
|
||||
assert.strictEqual(records[i], testRecord + devices[i]);
|
||||
}
|
||||
});
|
||||
it('stores identity keys', done => {
|
||||
store
|
||||
.saveIdentity(identifier, testKey.pubKey)
|
||||
.then(() =>
|
||||
store.loadIdentityKey(identifier).then(key => {
|
||||
assertEqualArrayBuffers(key, testKey.pubKey);
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('returns whether a key is trusted', done => {
|
||||
const newIdentity = libsignal.crypto.getRandomBytes(33);
|
||||
store.saveIdentity(identifier, testKey.pubKey).then(() => {
|
||||
store
|
||||
.isTrustedIdentity(identifier, newIdentity)
|
||||
.then(trusted => {
|
||||
if (trusted) {
|
||||
done(new Error('Allowed to overwrite identity key'));
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
});
|
||||
it('returns whether a key is untrusted', done => {
|
||||
const newIdentity = libsignal.crypto.getRandomBytes(33);
|
||||
store.saveIdentity(identifier, testKey.pubKey).then(() => {
|
||||
store
|
||||
.isTrustedIdentity(identifier, testKey.pubKey)
|
||||
.then(trusted => {
|
||||
if (trusted) {
|
||||
done();
|
||||
} else {
|
||||
done(new Error('Allowed to overwrite identity key'));
|
||||
}
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
});
|
||||
it('stores prekeys', done => {
|
||||
store
|
||||
.storePreKey(1, testKey)
|
||||
.then(() =>
|
||||
store.loadPreKey(1).then(key => {
|
||||
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('deletes prekeys', done => {
|
||||
before(done => {
|
||||
store.storePreKey(2, testKey).then(done);
|
||||
});
|
||||
store
|
||||
.removePreKey(2, testKey)
|
||||
.then(() =>
|
||||
store.loadPreKey(2).then(key => {
|
||||
assert.isUndefined(key);
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('stores signed prekeys', done => {
|
||||
store
|
||||
.storeSignedPreKey(3, testKey)
|
||||
.then(() =>
|
||||
store.loadSignedPreKey(3).then(key => {
|
||||
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('deletes signed prekeys', done => {
|
||||
before(done => {
|
||||
store.storeSignedPreKey(4, testKey).then(done);
|
||||
});
|
||||
store
|
||||
.removeSignedPreKey(4, testKey)
|
||||
.then(() =>
|
||||
store.loadSignedPreKey(4).then(key => {
|
||||
assert.isUndefined(key);
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('stores sessions', done => {
|
||||
it('removes all sessions for a number', async () => {
|
||||
const testRecord = 'an opaque string';
|
||||
const devices = [1, 2, 3].map(deviceId => [identifier, deviceId].join('.'));
|
||||
let promise = Promise.resolve();
|
||||
devices.forEach(encodedNumber => {
|
||||
promise = promise.then(() =>
|
||||
store.storeSession(encodedNumber, testRecord + encodedNumber)
|
||||
);
|
||||
});
|
||||
promise
|
||||
.then(() =>
|
||||
Promise.all(devices.map(store.loadSession.bind(store))).then(
|
||||
records => {
|
||||
for (const i in records) {
|
||||
assert.strictEqual(records[i], testRecord + devices[i]);
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.then(done, done);
|
||||
|
||||
await Promise.all(
|
||||
devices.map(async encodedNumber => {
|
||||
await store.storeSession(encodedNumber, testRecord + encodedNumber);
|
||||
})
|
||||
);
|
||||
|
||||
await store.removeAllSessions(identifier);
|
||||
|
||||
const records = await Promise.all(
|
||||
devices.map(store.loadSession.bind(store))
|
||||
);
|
||||
|
||||
for (let i = 0, max = records.length; i < max; i += 1) {
|
||||
assert.isUndefined(records[i]);
|
||||
}
|
||||
});
|
||||
it('removes all sessions for a number', done => {
|
||||
it('returns deviceIds for a number', async () => {
|
||||
const testRecord = 'an opaque string';
|
||||
const devices = [1, 2, 3].map(deviceId => [identifier, deviceId].join('.'));
|
||||
let promise = Promise.resolve();
|
||||
devices.forEach(encodedNumber => {
|
||||
promise = promise.then(() =>
|
||||
store.storeSession(encodedNumber, testRecord + encodedNumber)
|
||||
);
|
||||
});
|
||||
promise
|
||||
.then(() =>
|
||||
store.removeAllSessions(identifier).then(record =>
|
||||
Promise.all(devices.map(store.loadSession.bind(store))).then(
|
||||
records => {
|
||||
for (const i in records) {
|
||||
assert.isUndefined(records[i]);
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(done, done);
|
||||
|
||||
await Promise.all(
|
||||
devices.map(async encodedNumber => {
|
||||
await store.storeSession(encodedNumber, testRecord + encodedNumber);
|
||||
})
|
||||
);
|
||||
|
||||
const deviceIds = await store.getDeviceIds(identifier);
|
||||
assert.sameMembers(deviceIds, [1, 2, 3]);
|
||||
});
|
||||
it('returns deviceIds for a number', done => {
|
||||
const testRecord = 'an opaque string';
|
||||
const devices = [1, 2, 3].map(deviceId => [identifier, deviceId].join('.'));
|
||||
let promise = Promise.resolve();
|
||||
devices.forEach(encodedNumber => {
|
||||
promise = promise.then(() =>
|
||||
store.storeSession(encodedNumber, testRecord + encodedNumber)
|
||||
);
|
||||
});
|
||||
promise
|
||||
.then(() =>
|
||||
store.getDeviceIds(identifier).then(deviceIds => {
|
||||
assert.sameMembers(deviceIds, [1, 2, 3]);
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
it('returns empty array for a number with no device ids', async () => {
|
||||
const deviceIds = await store.getDeviceIds('foo');
|
||||
assert.sameMembers(deviceIds, []);
|
||||
});
|
||||
it('returns empty array for a number with no device ids', () =>
|
||||
store.getDeviceIds('foo').then(deviceIds => {
|
||||
assert.sameMembers(deviceIds, []);
|
||||
}));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue