2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2015-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-04-16 23:13:13 +00:00
|
|
|
/* global textsecure */
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
describe('MessageReceiver', () => {
|
2018-11-02 18:02:53 +00:00
|
|
|
const { WebSocket } = window;
|
2018-07-21 21:51:20 +00:00
|
|
|
const number = '+19999999999';
|
2020-03-05 21:14:58 +00:00
|
|
|
const uuid = 'AAAAAAAA-BBBB-4CCC-9DDD-EEEEEEEEEEEE';
|
2018-07-21 21:51:20 +00:00
|
|
|
const deviceId = 1;
|
2021-04-16 23:13:13 +00:00
|
|
|
const signalingKey = window.Signal.Crypto.getRandomBytes(32 + 20);
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
before(() => {
|
2021-02-18 16:40:26 +00:00
|
|
|
localStorage.clear();
|
2018-05-02 16:51:22 +00:00
|
|
|
window.WebSocket = MockSocket;
|
|
|
|
textsecure.storage.user.setNumberAndDeviceId(number, deviceId, 'name');
|
2020-03-05 21:14:58 +00:00
|
|
|
textsecure.storage.user.setUuidAndDeviceId(uuid, deviceId);
|
2018-05-02 16:51:22 +00:00
|
|
|
textsecure.storage.put('password', 'password');
|
|
|
|
textsecure.storage.put('signaling_key', signalingKey);
|
|
|
|
});
|
2018-07-21 21:51:20 +00:00
|
|
|
after(() => {
|
2021-02-18 16:40:26 +00:00
|
|
|
localStorage.clear();
|
2018-05-02 16:51:22 +00:00
|
|
|
window.WebSocket = WebSocket;
|
|
|
|
});
|
2015-07-28 01:03:28 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
describe('connecting', () => {
|
2021-02-18 16:40:26 +00:00
|
|
|
let attrs;
|
|
|
|
let websocketmessage;
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
attrs = {
|
|
|
|
type: textsecure.protobuf.Envelope.Type.CIPHERTEXT,
|
|
|
|
source: number,
|
|
|
|
sourceUuid: uuid,
|
|
|
|
sourceDevice: deviceId,
|
|
|
|
timestamp: Date.now(),
|
2021-04-16 23:13:13 +00:00
|
|
|
content: window.Signal.Crypto.getRandomBytes(200),
|
2021-02-18 16:40:26 +00:00
|
|
|
};
|
|
|
|
const body = new textsecure.protobuf.Envelope(attrs).toArrayBuffer();
|
2015-06-01 21:08:21 +00:00
|
|
|
|
2021-02-18 16:40:26 +00:00
|
|
|
websocketmessage = new textsecure.protobuf.WebSocketMessage({
|
|
|
|
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
|
|
|
request: { verb: 'PUT', path: '/api/v1/message', body },
|
|
|
|
});
|
2018-05-02 16:51:22 +00:00
|
|
|
});
|
2015-07-16 20:16:50 +00:00
|
|
|
|
2021-05-28 19:11:19 +00:00
|
|
|
it('generates decryption-error event when it cannot decrypt', done => {
|
2021-02-18 16:40:26 +00:00
|
|
|
const mockServer = new MockServer('ws://localhost:8081/');
|
2015-07-28 01:03:28 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
mockServer.on('connection', server => {
|
2021-02-18 16:40:26 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
server.send(new Blob([websocketmessage.toArrayBuffer()]));
|
|
|
|
}, 1);
|
2018-05-02 16:51:22 +00:00
|
|
|
});
|
2015-07-28 01:03:28 +00:00
|
|
|
|
2021-02-18 16:40:26 +00:00
|
|
|
const messageReceiver = new textsecure.MessageReceiver(
|
2021-04-16 23:13:13 +00:00
|
|
|
'oldUsername.2',
|
|
|
|
'username.2',
|
2021-02-18 16:40:26 +00:00
|
|
|
'password',
|
|
|
|
'signalingKey',
|
|
|
|
{
|
|
|
|
serverTrustRoot: 'AAAAAAAA',
|
2018-05-02 16:51:22 +00:00
|
|
|
}
|
2021-02-18 16:40:26 +00:00
|
|
|
);
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2021-05-28 19:11:19 +00:00
|
|
|
messageReceiver.addEventListener('decrytion-error', done());
|
2021-02-18 16:40:26 +00:00
|
|
|
});
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2021-05-28 19:11:19 +00:00
|
|
|
// For when we start testing individual MessageReceiver methods
|
|
|
|
|
|
|
|
// describe('methods', () => {
|
|
|
|
// let messageReceiver;
|
|
|
|
// let mockServer;
|
|
|
|
|
|
|
|
// beforeEach(() => {
|
|
|
|
// // Necessary to populate the server property inside of MockSocket. Without it, we
|
|
|
|
// // crash when doing any number of things to a MockSocket instance.
|
|
|
|
// mockServer = new MockServer('ws://localhost:8081');
|
|
|
|
|
|
|
|
// messageReceiver = new textsecure.MessageReceiver(
|
|
|
|
// 'oldUsername.3',
|
|
|
|
// 'username.3',
|
|
|
|
// 'password',
|
|
|
|
// 'signalingKey',
|
|
|
|
// {
|
|
|
|
// serverTrustRoot: 'AAAAAAAA',
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
// });
|
|
|
|
// afterEach(() => {
|
|
|
|
// mockServer.close();
|
|
|
|
// });
|
|
|
|
// });
|
2015-06-01 21:08:21 +00:00
|
|
|
});
|