Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('throws InvalidVerification when using a corrupt verification key', async () => {
const badKeys = [
corruptVerificationKey(verificationKey, 'privateSignatureKey', 4), // corrupt private part
corruptVerificationKey(verificationKey, 'privateSignatureKey', 60), // corrupt public part
corruptVerificationKey(verificationKey, 'privateEncryptionKey', 4), // does not match the one used at registration
];
for (let i = 0; i < badKeys.length; i++) {
const badKey = badKeys[i];
await expect(bobPhone.verifyIdentity({ verificationKey: badKey }), `bad verification key #${i}`).to.be.rejectedWith(errors.InvalidVerification);
}
});
});
it('fails to verify without having registered a passphrase', async () => {
const verificationCode = await appHelper.getVerificationCode('john@doe.com');
await bobLaptop.registerIdentity({ email: 'john@doe.com', verificationCode });
await expect(expectVerification(bobPhone, bobIdentity, { passphrase: 'my pass' })).to.be.rejectedWith(errors.PreconditionFailed);
});
it('fails to verify without having registered an email address', async () => {
await bobLaptop.registerIdentity({ passphrase: 'passphrase' });
const verificationCode = await appHelper.getVerificationCode('john@doe.com');
await expect(expectVerification(bobPhone, bobIdentity, { email: 'john@doe.com', verificationCode })).to.be.rejectedWith(errors.PreconditionFailed);
});
});
it('throws when registering before having started a session', async () => {
await expect(bobLaptop.registerIdentity({ passphrase: 'passphrase' })).to.be.rejectedWith(errors.PreconditionFailed);
});
it('should throw when using a session in an invalid state', async () => {
await bobLaptop.stop();
await expect(bobLaptop.getDeviceList()).to.be.rejectedWith(errors.PreconditionFailed);
});
it('throws when decrypting using a session in an invalid state', async () => {
await expect(bobLaptop.decrypt(utils.fromString('test'))).to.be.rejectedWith(errors.PreconditionFailed);
});
});
it('throws when using a session in an invalid state', async () => {
await expect(bobLaptop.encrypt(clearText)).to.be.rejectedWith(errors.PreconditionFailed);
});
it('throws when verifying provisional identity with wrong verification code', async () => {
await expect(aliceLaptop.verifyProvisionalIdentity({ email, verificationCode: 'wrongCode' })).to.be.rejectedWith(errors.InvalidVerification);
});
it('should fail to register an email verification method if the verification code is wrong', async () => {
const verificationCode = await appHelper.getWrongVerificationCode('john@doe.com');
await expect(bobLaptop.registerIdentity({ email: 'elton@doe.com', verificationCode })).to.be.rejectedWith(errors.InvalidVerification);
});
it('Alice can share with Bob who has a revoked device', async () => {
const aliceIdentity = await args.appHelper.generateIdentity();
const aliceLaptop = args.makeTanker();
await aliceLaptop.start(aliceIdentity);
await aliceLaptop.registerIdentity({ passphrase: 'passphrase' });
await bobLaptop.revokeDevice(bobPhone.deviceId);
const message = 'I love you';
const encrypted = await aliceLaptop.encrypt(message, { shareWithUsers: [bobPublicIdentity] });
const clear = await bobLaptop.decrypt(encrypted);
expect(clear).to.eq(message);
await expect(bobPhone.decrypt(encrypted)).to.be.rejectedWith(errors.DeviceRevoked);
await aliceLaptop.stop();
});
});