Eslintify all of libtextsecure
This commit is contained in:
parent
4b3f9e969a
commit
0774ba2903
36 changed files with 1960 additions and 2128 deletions
|
@ -1,55 +1,53 @@
|
|||
'use strict';
|
||||
|
||||
describe('SignalProtocolStore', function() {
|
||||
before(function() {
|
||||
describe('SignalProtocolStore', () => {
|
||||
before(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
var store = textsecure.storage.protocol;
|
||||
var identifier = '+5558675309';
|
||||
var another_identifier = '+5555590210';
|
||||
var identityKey = {
|
||||
const store = textsecure.storage.protocol;
|
||||
const identifier = '+5558675309';
|
||||
const another_identifier = '+5555590210';
|
||||
const identityKey = {
|
||||
pubKey: libsignal.crypto.getRandomBytes(33),
|
||||
privKey: libsignal.crypto.getRandomBytes(32),
|
||||
};
|
||||
var testKey = {
|
||||
const testKey = {
|
||||
pubKey: libsignal.crypto.getRandomBytes(33),
|
||||
privKey: libsignal.crypto.getRandomBytes(32),
|
||||
};
|
||||
it('retrieves my registration id', function(done) {
|
||||
it('retrieves my registration id', done => {
|
||||
store.put('registrationId', 1337);
|
||||
store
|
||||
.getLocalRegistrationId()
|
||||
.then(function(reg) {
|
||||
.then(reg => {
|
||||
assert.strictEqual(reg, 1337);
|
||||
})
|
||||
.then(done, done);
|
||||
});
|
||||
it('retrieves my identity key', function(done) {
|
||||
it('retrieves my identity key', done => {
|
||||
store.put('identityKey', identityKey);
|
||||
store
|
||||
.getIdentityKeyPair()
|
||||
.then(function(key) {
|
||||
.then(key => {
|
||||
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
||||
})
|
||||
.then(done, done);
|
||||
});
|
||||
it('stores identity keys', function(done) {
|
||||
it('stores identity keys', done => {
|
||||
store
|
||||
.saveIdentity(identifier, testKey.pubKey)
|
||||
.then(function() {
|
||||
return store.loadIdentityKey(identifier).then(function(key) {
|
||||
.then(() =>
|
||||
store.loadIdentityKey(identifier).then(key => {
|
||||
assertEqualArrayBuffers(key, testKey.pubKey);
|
||||
});
|
||||
})
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('returns whether a key is trusted', function(done) {
|
||||
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
||||
store.saveIdentity(identifier, testKey.pubKey).then(function() {
|
||||
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(function(trusted) {
|
||||
.then(trusted => {
|
||||
if (trusted) {
|
||||
done(new Error('Allowed to overwrite identity key'));
|
||||
} else {
|
||||
|
@ -59,12 +57,12 @@ describe('SignalProtocolStore', function() {
|
|||
.catch(done);
|
||||
});
|
||||
});
|
||||
it('returns whether a key is untrusted', function(done) {
|
||||
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
||||
store.saveIdentity(identifier, testKey.pubKey).then(function() {
|
||||
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(function(trusted) {
|
||||
.then(trusted => {
|
||||
if (trusted) {
|
||||
done();
|
||||
} else {
|
||||
|
@ -74,124 +72,117 @@ describe('SignalProtocolStore', function() {
|
|||
.catch(done);
|
||||
});
|
||||
});
|
||||
it('stores prekeys', function(done) {
|
||||
it('stores prekeys', done => {
|
||||
store
|
||||
.storePreKey(1, testKey)
|
||||
.then(function() {
|
||||
return store.loadPreKey(1).then(function(key) {
|
||||
.then(() =>
|
||||
store.loadPreKey(1).then(key => {
|
||||
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
||||
});
|
||||
})
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('deletes prekeys', function(done) {
|
||||
before(function(done) {
|
||||
it('deletes prekeys', done => {
|
||||
before(done => {
|
||||
store.storePreKey(2, testKey).then(done);
|
||||
});
|
||||
store
|
||||
.removePreKey(2, testKey)
|
||||
.then(function() {
|
||||
return store.loadPreKey(2).then(function(key) {
|
||||
.then(() =>
|
||||
store.loadPreKey(2).then(key => {
|
||||
assert.isUndefined(key);
|
||||
});
|
||||
})
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('stores signed prekeys', function(done) {
|
||||
it('stores signed prekeys', done => {
|
||||
store
|
||||
.storeSignedPreKey(3, testKey)
|
||||
.then(function() {
|
||||
return store.loadSignedPreKey(3).then(function(key) {
|
||||
.then(() =>
|
||||
store.loadSignedPreKey(3).then(key => {
|
||||
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
||||
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
||||
});
|
||||
})
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('deletes signed prekeys', function(done) {
|
||||
before(function(done) {
|
||||
it('deletes signed prekeys', done => {
|
||||
before(done => {
|
||||
store.storeSignedPreKey(4, testKey).then(done);
|
||||
});
|
||||
store
|
||||
.removeSignedPreKey(4, testKey)
|
||||
.then(function() {
|
||||
return store.loadSignedPreKey(4).then(function(key) {
|
||||
.then(() =>
|
||||
store.loadSignedPreKey(4).then(key => {
|
||||
assert.isUndefined(key);
|
||||
});
|
||||
})
|
||||
})
|
||||
)
|
||||
.then(done, done);
|
||||
});
|
||||
it('stores sessions', function(done) {
|
||||
var testRecord = 'an opaque string';
|
||||
var devices = [1, 2, 3].map(function(deviceId) {
|
||||
return [identifier, deviceId].join('.');
|
||||
});
|
||||
var promise = Promise.resolve();
|
||||
devices.forEach(function(encodedNumber) {
|
||||
promise = promise.then(function() {
|
||||
return store.storeSession(encodedNumber, testRecord + encodedNumber);
|
||||
});
|
||||
it('stores sessions', 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(function() {
|
||||
return Promise.all(devices.map(store.loadSession.bind(store))).then(
|
||||
function(records) {
|
||||
for (var i in records) {
|
||||
.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);
|
||||
});
|
||||
it('removes all sessions for a number', function(done) {
|
||||
var testRecord = 'an opaque string';
|
||||
var devices = [1, 2, 3].map(function(deviceId) {
|
||||
return [identifier, deviceId].join('.');
|
||||
});
|
||||
var promise = Promise.resolve();
|
||||
devices.forEach(function(encodedNumber) {
|
||||
promise = promise.then(function() {
|
||||
return store.storeSession(encodedNumber, testRecord + encodedNumber);
|
||||
});
|
||||
it('removes all sessions 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(function() {
|
||||
return store.removeAllSessions(identifier).then(function(record) {
|
||||
return Promise.all(devices.map(store.loadSession.bind(store))).then(
|
||||
function(records) {
|
||||
for (var i in records) {
|
||||
.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);
|
||||
});
|
||||
it('returns deviceIds for a number', function(done) {
|
||||
var testRecord = 'an opaque string';
|
||||
var devices = [1, 2, 3].map(function(deviceId) {
|
||||
return [identifier, deviceId].join('.');
|
||||
});
|
||||
var promise = Promise.resolve();
|
||||
devices.forEach(function(encodedNumber) {
|
||||
promise = promise.then(function() {
|
||||
return store.storeSession(encodedNumber, testRecord + encodedNumber);
|
||||
});
|
||||
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(function() {
|
||||
return store.getDeviceIds(identifier).then(function(deviceIds) {
|
||||
.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', function() {
|
||||
return store.getDeviceIds('foo').then(function(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