signal-desktop/libtextsecure/test/protocol_wrapper_test.js

36 lines
1 KiB
JavaScript
Raw Normal View History

2018-11-02 18:02:53 +00:00
/* global libsignal, textsecure */
describe('Protocol Wrapper', function thisNeeded() {
2018-07-21 21:51:20 +00:00
const store = textsecure.storage.protocol;
const identifier = '+5558675309';
2018-11-02 18:02:53 +00:00
2018-05-02 16:51:22 +00:00
this.timeout(5000);
2018-11-02 18:02:53 +00:00
2018-07-21 21:51:20 +00:00
before(done => {
2018-05-02 16:51:22 +00:00
localStorage.clear();
libsignal.KeyHelper.generateIdentityKeyPair()
2018-11-02 18:02:53 +00:00
.then(key => textsecure.storage.protocol.saveIdentity(identifier, key))
2018-07-21 21:51:20 +00:00
.then(() => {
2018-05-02 16:51:22 +00:00
done();
});
});
2018-11-02 18:02:53 +00:00
2018-07-21 21:51:20 +00:00
describe('processPreKey', () => {
it('rejects if the identity key changes', () => {
const address = new libsignal.SignalProtocolAddress(identifier, 1);
const builder = new libsignal.SessionBuilder(store, address);
2018-05-02 16:51:22 +00:00
return builder
.processPreKey({
identityKey: textsecure.crypto.getRandomBytes(33),
encodedNumber: address.toString(),
})
2018-07-21 21:51:20 +00:00
.then(() => {
throw new Error('Allowed to overwrite identity key');
2018-05-02 16:51:22 +00:00
})
2018-07-21 21:51:20 +00:00
.catch(e => {
2018-05-02 16:51:22 +00:00
assert.strictEqual(e.message, 'Identity key changed');
2015-07-22 19:48:08 +00:00
});
});
2018-05-02 16:51:22 +00:00
});
2015-07-22 19:48:08 +00:00
});