pull/1153/head
Mikunj 5 years ago
parent cd58e9b86e
commit 2e02e7d67b

@ -25,10 +25,12 @@ describe('MessageEncrypter', () => {
}, },
}); });
TestUtils.mockData('getItemById', undefined).resolves({ TestUtils.mockData('getItemById', undefined)
id: 'number_id', .withArgs('number_id')
value: 'abc.1', .resolves({
}); id: 'number_id',
value: 'abc.1',
});
}); });
afterEach(() => { afterEach(() => {
@ -40,8 +42,14 @@ describe('MessageEncrypter', () => {
describe('MediumGroup', () => { describe('MediumGroup', () => {
it('should throw an error', async () => { it('should throw an error', async () => {
const data = crypto.randomBytes(10); const data = crypto.randomBytes(10);
const promise = MessageEncrypter.encrypt('1', data, EncryptionType.MediumGroup); const promise = MessageEncrypter.encrypt(
await expect(promise).to.be.rejectedWith('Encryption is not yet supported'); '1',
data,
EncryptionType.MediumGroup
);
await expect(promise).to.be.rejectedWith(
'Encryption is not yet supported'
);
}); });
}); });
@ -62,11 +70,13 @@ describe('MessageEncrypter', () => {
body: 'body', body: 'body',
}); });
await MessageEncrypter.encrypt('1', data, EncryptionType.Signal); await MessageEncrypter.encrypt('1', data, EncryptionType.Signal);
expect(stub.called).to.equal(true, 'SessionCipher.encrypt should be called.'); expect(stub.called).to.equal(
true,
'SessionCipher.encrypt should be called.'
);
}); });
it('should pass the padded message body to encrypt', async () => { it('should pass the padded message body to encrypt', async () => {});
});
}); });
}); });
}); });

@ -8,7 +8,9 @@ export class SessionCipherBasicStub {
this.address = address; this.address = address;
} }
public async encrypt(buffer: ArrayBuffer | Uint8Array): Promise<CipherTextObject> { public async encrypt(
buffer: ArrayBuffer | Uint8Array
): Promise<CipherTextObject> {
throw new Error('Should stub this out'); throw new Error('Should stub this out');
} }
} }

@ -13,6 +13,9 @@ type DataFunction = typeof Shape;
* *
* Note: This uses `ImportMock` so you will have to call `ImportMock.restore()` or `stub.restore()` after each test. * Note: This uses `ImportMock` so you will have to call `ImportMock.restore()` or `stub.restore()` after each test.
*/ */
export function mockData(fn: keyof DataFunction, returns?: any): sinon.SinonStub { export function mockData(
fn: keyof DataFunction,
returns?: any
): sinon.SinonStub {
return ImportMock.mockFunction(Data, fn, returns); return ImportMock.mockFunction(Data, fn, returns);
} }

@ -1,4 +1,3 @@
import { LibsignalProtocol } from './types/libsignal-protocol'; import { LibsignalProtocol } from './types/libsignal-protocol';
import { SignalInterface } from './types/signal'; import { SignalInterface } from './types/signal';
import { LocalizerType } from '../types/Util'; import { LocalizerType } from '../types/Util';
@ -77,7 +76,7 @@ interface WindowInterface extends Window {
// In the case for tests // In the case for tests
// tslint:disable-next-line: no-typeof-undefined // tslint:disable-next-line: no-typeof-undefined
if (typeof(window) === 'undefined') { if (typeof window === 'undefined') {
const globalAny: any = global; const globalAny: any = global;
globalAny.window = {}; globalAny.window = {};
} }

@ -1,7 +1,5 @@
import { SignalService } from '../../protobuf'; import { SignalService } from '../../protobuf';
import { import { CipherTextObject } from './libsignal-protocol';
CipherTextObject,
} from './libsignal-protocol';
export declare class SecretSessionCipher { export declare class SecretSessionCipher {
constructor(storage: any); constructor(storage: any);

@ -10,6 +10,7 @@ export type CipherTextObject = {
export declare class SignalProtocolAddress { export declare class SignalProtocolAddress {
constructor(hexEncodedPublicKey: string, deviceId: number); constructor(hexEncodedPublicKey: string, deviceId: number);
// tslint:disable-next-line: function-name
public static fromString(encodedAddress: string): SignalProtocolAddress; public static fromString(encodedAddress: string): SignalProtocolAddress;
public getName(): string; public getName(): string;
public getDeviceId(): number; public getDeviceId(): number;
@ -26,7 +27,11 @@ interface CurveSync {
generateKeyPair(): KeyPair; generateKeyPair(): KeyPair;
createKeyPair(privKey: ArrayBuffer): KeyPair; createKeyPair(privKey: ArrayBuffer): KeyPair;
calculateAgreement(pubKey: ArrayBuffer, privKey: ArrayBuffer): ArrayBuffer; calculateAgreement(pubKey: ArrayBuffer, privKey: ArrayBuffer): ArrayBuffer;
verifySignature(pubKey: ArrayBuffer, msg: ArrayBuffer, sig: ArrayBuffer): void; verifySignature(
pubKey: ArrayBuffer,
msg: ArrayBuffer,
sig: ArrayBuffer
): void;
calculateSignature(privKey: ArrayBuffer, message: ArrayBuffer): ArrayBuffer; calculateSignature(privKey: ArrayBuffer, message: ArrayBuffer): ArrayBuffer;
validatePubKeyFormat(pubKey: ArrayBuffer): ArrayBuffer; validatePubKeyFormat(pubKey: ArrayBuffer): ArrayBuffer;
} }
@ -103,7 +108,9 @@ export declare class SessionCipher {
public decryptPreKeyWhisperMessage( public decryptPreKeyWhisperMessage(
buffer: ArrayBuffer | Uint8Array buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer>; ): Promise<ArrayBuffer>;
public decryptWhisperMessage(buffer: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>; public decryptWhisperMessage(
buffer: ArrayBuffer | Uint8Array
): Promise<ArrayBuffer>;
public getRecord(encodedNumber: string): Promise<any | undefined>; public getRecord(encodedNumber: string): Promise<any | undefined>;
public getRemoteRegistrationId(): Promise<number>; public getRemoteRegistrationId(): Promise<number>;
public hasOpenSession(): Promise<boolean>; public hasOpenSession(): Promise<boolean>;

Loading…
Cancel
Save