use pubkeys and toRawMessage()

pull/1166/head
Audric Ackermann 5 years ago
parent da1edab63d
commit 2b58aff532
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -3,10 +3,8 @@ import { SessionResetMessage } from '../messages/outgoing';
import { createOrUpdateItem, getItemById } from '../../../js/modules/data'; import { createOrUpdateItem, getItemById } from '../../../js/modules/data';
import { libloki, libsignal, textsecure } from '../../window'; import { libloki, libsignal, textsecure } from '../../window';
import { MessageSender } from '../sending'; import { MessageSender } from '../sending';
import { RawMessage } from '../types/RawMessage';
import { EncryptionType } from '../types/EncryptionType';
import { TextEncoder } from 'util';
import * as MessageUtils from '../utils'; import * as MessageUtils from '../utils';
import { PubKey } from '../types';
interface StringToNumberMap { interface StringToNumberMap {
[key: string]: number; [key: string]: number;
@ -51,9 +49,9 @@ export class SessionProtocol {
} }
/** Returns true if we already have a session with that device */ /** Returns true if we already have a session with that device */
public static async hasSession(device: string): Promise<boolean> { public static async hasSession(pubkey: PubKey): Promise<boolean> {
// Session does not use the concept of a deviceId, thus it's always 1 // Session does not use the concept of a deviceId, thus it's always 1
const address = new libsignal.SignalProtocolAddress(device, 1); const address = new libsignal.SignalProtocolAddress(pubkey.key, 1);
const sessionCipher = new libsignal.SessionCipher( const sessionCipher = new libsignal.SessionCipher(
textsecure.storage.protocol, textsecure.storage.protocol,
address address
@ -66,11 +64,11 @@ export class SessionProtocol {
* Returns true if we sent a session request to that device already OR * Returns true if we sent a session request to that device already OR
* if a session request to that device is right now being sent. * if a session request to that device is right now being sent.
*/ */
public static async hasSentSessionRequest(device: string): Promise<boolean> { public static async hasSentSessionRequest(pubkey: PubKey): Promise<boolean> {
const pendingSend = SessionProtocol.pendingSendSessionsTimestamp.has( const pendingSend = SessionProtocol.pendingSendSessionsTimestamp.has(
device pubkey.key
); );
const hasSent = await SessionProtocol._hasSentSessionRequest(device); const hasSent = await SessionProtocol._hasSentSessionRequest(pubkey.key);
return pendingSend || hasSent; return pendingSend || hasSent;
} }
@ -82,17 +80,17 @@ export class SessionProtocol {
* - we do not have a session request currently being send to that device * - we do not have a session request currently being send to that device
*/ */
public static async sendSessionRequestIfNeeded( public static async sendSessionRequestIfNeeded(
device: string pubkey: PubKey
): Promise<void> { ): Promise<void> {
if ( if (
(await SessionProtocol.hasSession(device)) || (await SessionProtocol.hasSession(pubkey)) ||
(await SessionProtocol.hasSentSessionRequest(device)) (await SessionProtocol.hasSentSessionRequest(pubkey))
) { ) {
return Promise.resolve(); return Promise.resolve();
} }
const preKeyBundle = await libloki.storage.getPreKeyBundleForContact( const preKeyBundle = await libloki.storage.getPreKeyBundleForContact(
device pubkey.key
); );
const sessionReset = new SessionResetMessage({ const sessionReset = new SessionResetMessage({
@ -101,51 +99,50 @@ export class SessionProtocol {
}); });
try { try {
await SessionProtocol.sendSessionRequest(sessionReset, device); await SessionProtocol.sendSessionRequest(sessionReset, pubkey);
} catch (error) { } catch (error) {
window.console.warn('Failed to send session request to:', device, error); window.console.warn('Failed to send session request to:', pubkey.key, error);
} }
} }
/** */ /** */
public static async sendSessionRequest( public static async sendSessionRequest(
message: SessionResetMessage, message: SessionResetMessage,
device: string pubkey: PubKey
): Promise<void> { ): Promise<void> {
const timestamp = Date.now(); const timestamp = Date.now();
// mark the session as being pending send with current timestamp // mark the session as being pending send with current timestamp
// so we know we already triggered a new session with that device // so we know we already triggered a new session with that device
SessionProtocol.pendingSendSessionsTimestamp.add(device); SessionProtocol.pendingSendSessionsTimestamp.add(pubkey.key);
try { try {
// TODO: Send out the request via MessageSender const rawMessage = MessageUtils.toRawMessage(pubkey, message);
const rawMessage = MessageUtils.toRawMessage(device, message);
await MessageSender.send(rawMessage); await MessageSender.send(rawMessage);
await SessionProtocol.updateSentSessionTimestamp(device, timestamp); await SessionProtocol.updateSentSessionTimestamp(pubkey.key, timestamp);
} catch (e) { } catch (e) {
throw e; throw e;
} finally { } finally {
SessionProtocol.pendingSendSessionsTimestamp.delete(device); SessionProtocol.pendingSendSessionsTimestamp.delete(pubkey.key);
} }
} }
/** /**
* Called when a session is establish so we store on database this info. * Called when a session is establish so we store on database this info.
*/ */
public static async onSessionEstablished(device: string) { public static async onSessionEstablished(pubkey: PubKey) {
// remove our existing sent timestamp for that device // remove our existing sent timestamp for that device
return SessionProtocol.updateSentSessionTimestamp(device, undefined); return SessionProtocol.updateSentSessionTimestamp(pubkey.key, undefined);
} }
public static async shouldProcessSessionRequest( public static async shouldProcessSessionRequest(
device: string, pubkey: PubKey,
messageTimestamp: number messageTimestamp: number
): Promise<boolean> { ): Promise<boolean> {
const existingSentTimestamp = const existingSentTimestamp =
(await SessionProtocol.getSentSessionRequest(device)) || 0; (await SessionProtocol.getSentSessionRequest(pubkey.key)) || 0;
const existingProcessedTimestamp = const existingProcessedTimestamp =
(await SessionProtocol.getProcessedSessionRequest(device)) || 0; (await SessionProtocol.getProcessedSessionRequest(pubkey.key)) || 0;
return ( return (
messageTimestamp > existingSentTimestamp && messageTimestamp > existingSentTimestamp &&
@ -153,8 +150,8 @@ export class SessionProtocol {
); );
} }
public static async onSessionRequestProcessed(device: string) { public static async onSessionRequestProcessed(pubkey: PubKey) {
return SessionProtocol.updateProcessedSessionTimestamp(device, Date.now()); return SessionProtocol.updateProcessedSessionTimestamp(pubkey.key, Date.now());
} }
public static reset() { public static reset() {

@ -6,11 +6,13 @@ import { UserUtil } from '../../../util';
import { SessionResetMessage } from '../../../session/messages/outgoing'; import { SessionResetMessage } from '../../../session/messages/outgoing';
import { TextEncoder } from 'util'; import { TextEncoder } from 'util';
import { MessageSender } from '../../../session/sending'; import { MessageSender } from '../../../session/sending';
import { PubKey } from '../../../session/types';
// tslint:disable-next-line: max-func-body-length // tslint:disable-next-line: max-func-body-length
describe('SessionProtocol', () => { describe('SessionProtocol', () => {
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
const ourNumber = 'ourNumber'; const ourNumber = 'ourNumber';
const pubkey = new PubKey('deviceid');
let getItemById: sinon.SinonStub; let getItemById: sinon.SinonStub;
let send: sinon.SinonStub; let send: sinon.SinonStub;
@ -61,17 +63,17 @@ describe('SessionProtocol', () => {
describe('db fetch', () => { describe('db fetch', () => {
it('protocol: should fetch from DB `sentSessionsTimestamp` and `processedSessionsTimestamp`', async () => { it('protocol: should fetch from DB `sentSessionsTimestamp` and `processedSessionsTimestamp`', async () => {
await SessionProtocol.hasSentSessionRequest('test'); await SessionProtocol.hasSentSessionRequest(pubkey);
expect(getItemById.calledWith('sentSessionsTimestamp')); expect(getItemById.calledWith('sentSessionsTimestamp'));
expect(getItemById.calledWith('processedSessionsTimestamp')); expect(getItemById.calledWith('processedSessionsTimestamp'));
expect(getItemById.callCount).to.equal(2); expect(getItemById.callCount).to.equal(2);
}); });
it('protocol: should fetch only once', async () => { it('protocol: should fetch only once', async () => {
await SessionProtocol.hasSentSessionRequest('test'); await SessionProtocol.hasSentSessionRequest(pubkey);
await SessionProtocol.hasSentSessionRequest('test'); await SessionProtocol.hasSentSessionRequest(pubkey);
await SessionProtocol.hasSentSessionRequest('test'); await SessionProtocol.hasSentSessionRequest(pubkey);
await SessionProtocol.hasSentSessionRequest('test'); await SessionProtocol.hasSentSessionRequest(pubkey);
expect(getItemById.calledWith('sentSessionsTimestamp')); expect(getItemById.calledWith('sentSessionsTimestamp'));
expect(getItemById.calledWith('processedSessionsTimestamp')); expect(getItemById.calledWith('processedSessionsTimestamp'));
expect(getItemById.callCount).to.equal(2); expect(getItemById.callCount).to.equal(2);
@ -81,33 +83,33 @@ describe('SessionProtocol', () => {
describe('sendSessionRequest', () => { describe('sendSessionRequest', () => {
beforeEach(async () => { beforeEach(async () => {
// trigger a sessionReset // trigger a sessionReset
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceID'); await SessionProtocol.sendSessionRequest(resetMessage, pubkey);
}); });
it('protocol: sendSessionRequest should add the deviceID to the sentMap', async () => { it('protocol: sendSessionRequest should add the deviceID to the sentMap', async () => {
expect(SessionProtocol.getSentSessionsTimestamp()) expect(SessionProtocol.getSentSessionsTimestamp())
.to.have.property('deviceID') .to.have.property('deviceid')
.to.be.approximately(Date.now(), 100); .to.be.approximately(Date.now(), 100);
}); });
it('protocol: sendSessionRequest should not have pendingSend set after', async () => { it('protocol: sendSessionRequest should not have pendingSend set after', async () => {
expect( expect(
SessionProtocol.getPendingSendSessionTimestamp() SessionProtocol.getPendingSendSessionTimestamp()
).to.not.have.property('deviceID'); ).to.not.have.property('deviceid');
}); });
}); });
describe('onSessionEstablished', () => { describe('onSessionEstablished', () => {
beforeEach(async () => { beforeEach(async () => {
// add an existing entry in the sentMap // add an existing entry in the sentMap
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid'); await SessionProtocol.sendSessionRequest(resetMessage, pubkey);
}); });
it('protocol: onSessionEstablished should remove the device in sentTimestamps', async () => { it('protocol: onSessionEstablished should remove the device in sentTimestamps', async () => {
expect(SessionProtocol.getSentSessionsTimestamp()).to.have.property( expect(SessionProtocol.getSentSessionsTimestamp()).to.have.property(
'deviceid' 'deviceid'
); );
await SessionProtocol.onSessionEstablished('deviceid'); await SessionProtocol.onSessionEstablished(pubkey);
expect(SessionProtocol.getSentSessionsTimestamp()).to.not.have.property( expect(SessionProtocol.getSentSessionsTimestamp()).to.not.have.property(
'deviceid' 'deviceid'
); );
@ -115,7 +117,7 @@ describe('SessionProtocol', () => {
it('protocol: onSessionEstablished should remove the device in sentTimestamps and ONLY that one', async () => { it('protocol: onSessionEstablished should remove the device in sentTimestamps and ONLY that one', async () => {
// add a second item to the map // add a second item to the map
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid2'); await SessionProtocol.sendSessionRequest(resetMessage, new PubKey('deviceid2'));
expect(SessionProtocol.getSentSessionsTimestamp()).to.have.property( expect(SessionProtocol.getSentSessionsTimestamp()).to.have.property(
'deviceid' 'deviceid'
@ -124,7 +126,7 @@ describe('SessionProtocol', () => {
'deviceid2' 'deviceid2'
); );
await SessionProtocol.onSessionEstablished('deviceid'); await SessionProtocol.onSessionEstablished(pubkey);
expect(SessionProtocol.getSentSessionsTimestamp()).to.not.have.property( expect(SessionProtocol.getSentSessionsTimestamp()).to.not.have.property(
'deviceid' 'deviceid'
); );
@ -136,7 +138,7 @@ describe('SessionProtocol', () => {
describe('hasSentSessionRequest', () => { describe('hasSentSessionRequest', () => {
it('protocol: hasSentSessionRequest returns false if a message was not sent to that device', async () => { it('protocol: hasSentSessionRequest returns false if a message was not sent to that device', async () => {
const hasSent = await SessionProtocol.hasSentSessionRequest('deviceid'); const hasSent = await SessionProtocol.hasSentSessionRequest(pubkey);
expect(hasSent).to.be.equal( expect(hasSent).to.be.equal(
false, false,
'hasSent should be false for `deviceid`' 'hasSent should be false for `deviceid`'
@ -145,8 +147,8 @@ describe('SessionProtocol', () => {
it('protocol: hasSentSessionRequest returns true if a message is already sent for that device', async () => { it('protocol: hasSentSessionRequest returns true if a message is already sent for that device', async () => {
// add an existing entry in the sentMap // add an existing entry in the sentMap
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid'); await SessionProtocol.sendSessionRequest(resetMessage, pubkey);
const hasSent = await SessionProtocol.hasSentSessionRequest('deviceid'); const hasSent = await SessionProtocol.hasSentSessionRequest(pubkey);
expect(hasSent).to.be.equal( expect(hasSent).to.be.equal(
true, true,
'hasSent should be true for `deviceid`' 'hasSent should be true for `deviceid`'
@ -159,14 +161,14 @@ describe('SessionProtocol', () => {
describe('sendSessionRequestIfNeeded', () => { describe('sendSessionRequestIfNeeded', () => {
it('protocol: sendSessionRequestIfNeeded should send a new sessionMessage ', async () => { it('protocol: sendSessionRequestIfNeeded should send a new sessionMessage ', async () => {
// not called before, so the message reset sending should be triggered // not called before, so the message reset sending should be triggered
await SessionProtocol.sendSessionRequestIfNeeded('deviceid'); await SessionProtocol.sendSessionRequestIfNeeded(pubkey);
expect(send.callCount).to.be.equal( expect(send.callCount).to.be.equal(
1, 1,
'MessageSender.send() should have been called' 'MessageSender.send() should have been called'
); );
// check that the map is updated with that ID // check that the map is updated with that ID
const hasSent = await SessionProtocol.hasSentSessionRequest('deviceid'); const hasSent = await SessionProtocol.hasSentSessionRequest(pubkey);
expect(hasSent).to.be.equal( expect(hasSent).to.be.equal(
true, true,
'hasSent should be true for `deviceid`' 'hasSent should be true for `deviceid`'
@ -174,14 +176,14 @@ describe('SessionProtocol', () => {
}); });
it('protocol: sendSessionRequestIfNeeded should NOT send a new sessionMessage on second try ', async () => { it('protocol: sendSessionRequestIfNeeded should NOT send a new sessionMessage on second try ', async () => {
await SessionProtocol.sendSessionRequestIfNeeded('deviceid'); await SessionProtocol.sendSessionRequestIfNeeded(pubkey);
expect(send.callCount).to.be.equal( expect(send.callCount).to.be.equal(
1, 1,
'MessageSender.send() should have been called' 'MessageSender.send() should have been called'
); );
// check that the map is updated with that ID // check that the map is updated with that ID
const hasSent = await SessionProtocol.hasSentSessionRequest('deviceid'); const hasSent = await SessionProtocol.hasSentSessionRequest(pubkey);
expect(hasSent).to.be.equal( expect(hasSent).to.be.equal(
true, true,
'hasSent should be true for `deviceid`' 'hasSent should be true for `deviceid`'
@ -189,7 +191,7 @@ describe('SessionProtocol', () => {
send.resetHistory(); send.resetHistory();
// trigger a second call, Message.send().calledCount should still be 1 // trigger a second call, Message.send().calledCount should still be 1
await SessionProtocol.sendSessionRequestIfNeeded('deviceid'); await SessionProtocol.sendSessionRequestIfNeeded(pubkey);
expect(send.callCount).to.be.equal( expect(send.callCount).to.be.equal(
0, 0,
'MessageSender.send() should NOT have been called a second time' 'MessageSender.send() should NOT have been called a second time'
@ -200,7 +202,7 @@ describe('SessionProtocol', () => {
describe('onSessionRequestProcessed', () => { describe('onSessionRequestProcessed', () => {
it('protocol: onSessionRequestProcessed should insert a new item in the processedMap ', async () => { it('protocol: onSessionRequestProcessed should insert a new item in the processedMap ', async () => {
// trigger the requestProcessed and check the map is updated // trigger the requestProcessed and check the map is updated
await SessionProtocol.onSessionRequestProcessed('deviceid'); await SessionProtocol.onSessionRequestProcessed(pubkey);
expect(SessionProtocol.getProcessedSessionsTimestamp()) expect(SessionProtocol.getProcessedSessionsTimestamp())
.to.have.property('deviceid') .to.have.property('deviceid')
.to.be.approximately(Date.now(), 5); .to.be.approximately(Date.now(), 5);
@ -210,14 +212,14 @@ describe('SessionProtocol', () => {
// trigger the requestProcessed and check the map is updated // trigger the requestProcessed and check the map is updated
// then trigger it a second time, and expect a change in the processed timestamp // then trigger it a second time, and expect a change in the processed timestamp
await SessionProtocol.onSessionRequestProcessed('deviceid'); await SessionProtocol.onSessionRequestProcessed(pubkey);
expect(SessionProtocol.getProcessedSessionsTimestamp()) expect(SessionProtocol.getProcessedSessionsTimestamp())
.to.have.property('deviceid') .to.have.property('deviceid')
.to.be.approximately(Date.now(), 5); .to.be.approximately(Date.now(), 5);
await timeout(5); await timeout(5);
const oldTimestamp = SessionProtocol.getProcessedSessionsTimestamp() const oldTimestamp = SessionProtocol.getProcessedSessionsTimestamp()
.deviceid; .deviceid;
await SessionProtocol.onSessionRequestProcessed('deviceid'); await SessionProtocol.onSessionRequestProcessed(pubkey);
expect(SessionProtocol.getProcessedSessionsTimestamp()) expect(SessionProtocol.getProcessedSessionsTimestamp())
.to.have.property('deviceid') .to.have.property('deviceid')
.to.be.approximately(Date.now(), 5) .to.be.approximately(Date.now(), 5)
@ -227,10 +229,10 @@ describe('SessionProtocol', () => {
describe('shouldProcessSessionRequest', () => { describe('shouldProcessSessionRequest', () => {
it('protocol: shouldProcessSessionRequest returns true if timestamp is more recent than processed timestamp', async () => { it('protocol: shouldProcessSessionRequest returns true if timestamp is more recent than processed timestamp', async () => {
await SessionProtocol.onSessionRequestProcessed('deviceid'); // adds a Date.now() entry await SessionProtocol.onSessionRequestProcessed(pubkey); // adds a Date.now() entry
expect( expect(
SessionProtocol.shouldProcessSessionRequest( SessionProtocol.shouldProcessSessionRequest(
'deviceid', pubkey,
Date.now() + 1000 Date.now() + 1000
) )
).to.be.eventually.equal( ).to.be.eventually.equal(
@ -241,7 +243,7 @@ describe('SessionProtocol', () => {
it('protocol: shouldProcessSessionRequest returns true if there is no processed timestamp yet for this device', async () => { it('protocol: shouldProcessSessionRequest returns true if there is no processed timestamp yet for this device', async () => {
expect( expect(
SessionProtocol.shouldProcessSessionRequest('deviceid', 100) SessionProtocol.shouldProcessSessionRequest(pubkey, 100)
).to.be.eventually.equal( ).to.be.eventually.equal(
true, true,
'shouldProcessSessionRequest should return false when existingProcessed is empty for this device' 'shouldProcessSessionRequest should return false when existingProcessed is empty for this device'
@ -249,9 +251,9 @@ describe('SessionProtocol', () => {
}); });
it('protocol: shouldProcessSessionRequest returns false if timestamp is less recent than current processed timestamp', async () => { it('protocol: shouldProcessSessionRequest returns false if timestamp is less recent than current processed timestamp', async () => {
await SessionProtocol.onSessionRequestProcessed('deviceid'); // adds a Date.now() entry await SessionProtocol.onSessionRequestProcessed(pubkey); // adds a Date.now() entry
expect( expect(
SessionProtocol.shouldProcessSessionRequest('deviceid', 100) SessionProtocol.shouldProcessSessionRequest(pubkey, 100)
).to.be.eventually.equal( ).to.be.eventually.equal(
false, false,
'shouldProcessSessionRequest should return false when existingProcessed is more recent' 'shouldProcessSessionRequest should return false when existingProcessed is more recent'
@ -259,9 +261,9 @@ describe('SessionProtocol', () => {
}); });
it('protocol: shouldProcessSessionRequest returns false if timestamp is less recent than current sent timestamp', async () => { it('protocol: shouldProcessSessionRequest returns false if timestamp is less recent than current sent timestamp', async () => {
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid'); // adds a Date.now() entry await SessionProtocol.sendSessionRequest(resetMessage, pubkey); // adds a Date.now() entry
expect( expect(
SessionProtocol.shouldProcessSessionRequest('deviceid', 100) SessionProtocol.shouldProcessSessionRequest(pubkey, 100)
).to.be.eventually.equal( ).to.be.eventually.equal(
false, false,
'shouldProcessSessionRequest should return false when existingSent is more recent' 'shouldProcessSessionRequest should return false when existingSent is more recent'
@ -269,10 +271,10 @@ describe('SessionProtocol', () => {
}); });
it('protocol: shouldProcessSessionRequest returns true if timestamp is more recent than current sent timestamp', async () => { it('protocol: shouldProcessSessionRequest returns true if timestamp is more recent than current sent timestamp', async () => {
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid'); // adds a Date.now() entry await SessionProtocol.sendSessionRequest(resetMessage, pubkey); // adds a Date.now() entry
expect( expect(
SessionProtocol.shouldProcessSessionRequest( SessionProtocol.shouldProcessSessionRequest(
'deviceid', pubkey,
Date.now() + 1000 Date.now() + 1000
) )
).to.be.eventually.equal( ).to.be.eventually.equal(
@ -283,7 +285,7 @@ describe('SessionProtocol', () => {
it('protocol: shouldProcessSessionRequest returns true if there is no sent timestamp', async () => { it('protocol: shouldProcessSessionRequest returns true if there is no sent timestamp', async () => {
expect( expect(
SessionProtocol.shouldProcessSessionRequest('deviceid', 100) SessionProtocol.shouldProcessSessionRequest(pubkey, 100)
).to.be.eventually.equal( ).to.be.eventually.equal(
true, true,
'shouldProcessSessionRequest should return true as there is no sent timestamp' 'shouldProcessSessionRequest should return true as there is no sent timestamp'
@ -291,12 +293,12 @@ describe('SessionProtocol', () => {
}); });
it('protocol: shouldProcessSessionRequest returns false if there is a more recent sent but a less recent processed', async () => { it('protocol: shouldProcessSessionRequest returns false if there is a more recent sent but a less recent processed', async () => {
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid'); // adds a Date.now() entry await SessionProtocol.sendSessionRequest(resetMessage, pubkey); // adds a Date.now() entry
await timeout(100); await timeout(100);
await SessionProtocol.onSessionRequestProcessed('deviceid'); // adds a Date.now() entry 100ms after await SessionProtocol.onSessionRequestProcessed(pubkey); // adds a Date.now() entry 100ms after
expect( expect(
SessionProtocol.shouldProcessSessionRequest('deviceid', Date.now() - 50) SessionProtocol.shouldProcessSessionRequest(pubkey, Date.now() - 50)
).to.be.eventually.equal( ).to.be.eventually.equal(
false, false,
'shouldProcessSessionRequest should return false if there is a more recent sent but a less recent processed' 'shouldProcessSessionRequest should return false if there is a more recent sent but a less recent processed'
@ -304,12 +306,12 @@ describe('SessionProtocol', () => {
}); });
it('protocol: shouldProcessSessionRequest returns false if there is a more recent processed but a less recent sent', async () => { it('protocol: shouldProcessSessionRequest returns false if there is a more recent processed but a less recent sent', async () => {
await SessionProtocol.onSessionRequestProcessed('deviceid'); // adds a Date.now() entry await SessionProtocol.onSessionRequestProcessed(pubkey); // adds a Date.now() entry
await timeout(100); await timeout(100);
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid'); // adds a Date.now() entry 100ms after await SessionProtocol.sendSessionRequest(resetMessage, pubkey); // adds a Date.now() entry 100ms after
expect( expect(
SessionProtocol.shouldProcessSessionRequest('deviceid', Date.now() - 50) SessionProtocol.shouldProcessSessionRequest(pubkey, Date.now() - 50)
).to.be.eventually.equal( ).to.be.eventually.equal(
false, false,
'shouldProcessSessionRequest should return false if there is a more recent processed but a less recent sent' 'shouldProcessSessionRequest should return false if there is a more recent processed but a less recent sent'
@ -317,11 +319,11 @@ describe('SessionProtocol', () => {
}); });
it('protocol: shouldProcessSessionRequest returns true if both sent and processed timestamp are older', async () => { it('protocol: shouldProcessSessionRequest returns true if both sent and processed timestamp are older', async () => {
await SessionProtocol.onSessionRequestProcessed('deviceid'); // adds a Date.now() entry await SessionProtocol.onSessionRequestProcessed(pubkey); // adds a Date.now() entry
await SessionProtocol.sendSessionRequest(resetMessage, 'deviceid'); // adds a Date.now() entry await SessionProtocol.sendSessionRequest(resetMessage, pubkey); // adds a Date.now() entry
expect( expect(
SessionProtocol.shouldProcessSessionRequest( SessionProtocol.shouldProcessSessionRequest(
'deviceid', pubkey,
Date.now() + 1000 Date.now() + 1000
) )
).to.be.eventually.equal( ).to.be.eventually.equal(

Loading…
Cancel
Save