|
|
|
@ -5,6 +5,8 @@ import { stubWindowLog } from '../../../test-utils/utils';
|
|
|
|
|
import {
|
|
|
|
|
ExpireMessageOnSnodeProps,
|
|
|
|
|
buildExpireRequest,
|
|
|
|
|
verifyExpireMsgsResponseSignature,
|
|
|
|
|
verifyExpireMsgsResponseSignatureProps,
|
|
|
|
|
} from '../../../../session/apis/snode_api/expireRequest';
|
|
|
|
|
import { UpdateExpiryOnNodeSubRequest } from '../../../../session/apis/snode_api/SnodeRequestTypes';
|
|
|
|
|
import { UserUtils } from '../../../../session/utils';
|
|
|
|
@ -13,11 +15,11 @@ import { GetNetworkTime } from '../../../../session/apis/snode_api/getNetworkTim
|
|
|
|
|
|
|
|
|
|
chai.use(chaiAsPromised as any);
|
|
|
|
|
|
|
|
|
|
describe('Snode /expire request', () => {
|
|
|
|
|
describe('ExpireRequest', () => {
|
|
|
|
|
stubWindowLog();
|
|
|
|
|
|
|
|
|
|
const getLatestTimestampOffset = 200000;
|
|
|
|
|
const ourNumber = '051234567890acbdef';
|
|
|
|
|
const ourNumber = '37e1631b002de498caf7c5c1712718bde7f257c6dadeed0c21abf5e939e6c309';
|
|
|
|
|
const ourUserEd25516Keypair = {
|
|
|
|
|
pubKey: '37e1631b002de498caf7c5c1712718bde7f257c6dadeed0c21abf5e939e6c309',
|
|
|
|
|
privKey:
|
|
|
|
@ -43,8 +45,6 @@ describe('Snode /expire request', () => {
|
|
|
|
|
it('builds a request with just the messageHash and expireTimer of 1 minute', async () => {
|
|
|
|
|
const request: UpdateExpiryOnNodeSubRequest | null = await buildExpireRequest(props);
|
|
|
|
|
|
|
|
|
|
window.log.debug(`WIP: [unit testing] signature ${request?.params.signature} `);
|
|
|
|
|
|
|
|
|
|
expect(request, 'should not return null').to.not.be.null;
|
|
|
|
|
expect(request, 'should not return undefined').to.not.be.undefined;
|
|
|
|
|
expect(request, "method should be 'expire'").to.have.property('method', 'expire');
|
|
|
|
@ -66,8 +66,6 @@ describe('Snode /expire request', () => {
|
|
|
|
|
extend: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.log.debug(`WIP: [unit testing] signature ${request?.params.signature} `);
|
|
|
|
|
|
|
|
|
|
expect(request, 'should not return null').to.not.be.null;
|
|
|
|
|
expect(request, 'should not return undefined').to.not.be.undefined;
|
|
|
|
|
expect(request, "method should be 'expire'").to.have.property('method', 'expire');
|
|
|
|
@ -89,8 +87,6 @@ describe('Snode /expire request', () => {
|
|
|
|
|
shorten: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.log.debug(`WIP: [unit testing] signature ${request?.params.signature} `);
|
|
|
|
|
|
|
|
|
|
expect(request, 'should not return null').to.not.be.null;
|
|
|
|
|
expect(request, 'should not return undefined').to.not.be.undefined;
|
|
|
|
|
expect(request, "method should be 'expire'").to.have.property('method', 'expire');
|
|
|
|
@ -116,4 +112,39 @@ describe('Snode /expire request', () => {
|
|
|
|
|
expect(request, 'should return null').to.be.null;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('verifyExpireMsgsResponseSignature', () => {
|
|
|
|
|
const props: verifyExpireMsgsResponseSignatureProps = {
|
|
|
|
|
pubkey: '058dc8432a63f9dda4d642bfc3eb5e037838bbd779f73e0a6dfb92b8040a1e7848',
|
|
|
|
|
snodePubkey: 'd9a0fe4581988bdbb3a586f0b254ef60f4e411523be6267b128d1d49bb4585bb',
|
|
|
|
|
messageHashes: ['MVeBDGJz+O1NXcb8f8u9zEjJuwJidwwFYazrgOCqdDg'],
|
|
|
|
|
expiry: 1696913568281,
|
|
|
|
|
signature:
|
|
|
|
|
'8j/1IR3Cnbf0XLL0G+unge6888alheMLAcWehRbQ8zOChqxXwOBHmGu6ZZ99dhvhL8laPg3UAtVcf2iW1CViCQ==',
|
|
|
|
|
updated: ['MVeBDGJz+O1NXcb8f8u9zEjJuwJidwwFYazrgOCqdDg'],
|
|
|
|
|
unchanged: {},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it('returns true if the signature is valid', async () => {
|
|
|
|
|
const isValid = await verifyExpireMsgsResponseSignature(props);
|
|
|
|
|
expect(isValid, 'should return true').to.be.true;
|
|
|
|
|
});
|
|
|
|
|
it('returns false if the signature is invalid', async () => {
|
|
|
|
|
// use a different pubkey to invalidate the signature
|
|
|
|
|
const isValid = await verifyExpireMsgsResponseSignature({ ...props, pubkey: ourNumber });
|
|
|
|
|
expect(isValid, 'should return false').to.be.false;
|
|
|
|
|
});
|
|
|
|
|
it('returns false if response is missing the expiry timestamp', async () => {
|
|
|
|
|
const isValid = await verifyExpireMsgsResponseSignature({ ...props, expiry: 0 });
|
|
|
|
|
expect(isValid, 'should return false').to.be.false;
|
|
|
|
|
});
|
|
|
|
|
it('returns false if response is missing the messageHashes', async () => {
|
|
|
|
|
const isValid = await verifyExpireMsgsResponseSignature({ ...props, messageHashes: [] });
|
|
|
|
|
expect(isValid, 'should return false').to.be.false;
|
|
|
|
|
});
|
|
|
|
|
it('returns false if response is missing the signature', async () => {
|
|
|
|
|
const isValid = await verifyExpireMsgsResponseSignature({ ...props, signature: '' });
|
|
|
|
|
expect(isValid, 'should return false').to.be.false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|