Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('encrypt and share with a provisional identity', async () => {
const email = 'alice@tanker-functional-test.io';
const provisionalIdentity = await createProvisionalIdentity(utils.toBase64(args.appHelper.appId), email);
const publicProvisionalIdentity = await getPublicIdentity(provisionalIdentity);
await expect(bobLaptop.encrypt(clearText, { shareWithUsers: [publicProvisionalIdentity] })).to.be.fulfilled;
});
it('fails to attach a provisional identity if the oidc id token contains an email different from the provisional email', async () => {
await bobLaptop.registerIdentity({ passphrase: 'passphrase' });
const aliceIdentity = await args.appHelper.generateIdentity();
const aliceLaptop = args.makeTanker();
await aliceLaptop.start(aliceIdentity);
await aliceLaptop.registerIdentity({ passphrase: 'passphrase' });
const email = 'the-ceo@tanker.io';
const provisionalIdentity = await createProvisionalIdentity(utils.toBase64(args.appHelper.appId), email);
const attachResult = await bobLaptop.attachProvisionalIdentity(provisionalIdentity);
expect(attachResult).to.deep.equal({
status: bobLaptop.constructor.statuses.IDENTITY_VERIFICATION_NEEDED,
verificationMethod: { type: 'email', email },
});
await expect(bobLaptop.verifyProvisionalIdentity({ oidcIdToken: martineIdToken })).to.be.rejectedWith(errors.InvalidArgument);
await aliceLaptop.stop();
});
it('decrypt data shared with an attached provisional identity', async () => {
await bobLaptop.registerIdentity({ passphrase: 'passphrase' });
const aliceIdentity = await args.appHelper.generateIdentity();
const aliceLaptop = args.makeTanker();
await aliceLaptop.start(aliceIdentity);
await aliceLaptop.registerIdentity({ passphrase: 'passphrase' });
const email = oidcSettings.googleAuth.users.martine.email;
const provisionalIdentity = await createProvisionalIdentity(utils.toBase64(args.appHelper.appId), email);
const publicProvisionalIdentity = await getPublicIdentity(provisionalIdentity);
const clearText = 'Rivest Shamir Adleman';
const cipherText = await aliceLaptop.encrypt(clearText, { shareWithUsers: [publicProvisionalIdentity] });
const attachResult = await bobLaptop.attachProvisionalIdentity(provisionalIdentity);
expect(attachResult).to.deep.equal({
status: bobLaptop.constructor.statuses.IDENTITY_VERIFICATION_NEEDED,
verificationMethod: { type: 'email', email },
});
await bobLaptop.verifyProvisionalIdentity({ oidcIdToken: martineIdToken });
const decrypted = await bobLaptop.decrypt(cipherText);
expect(decrypted).to.equal(clearText);
await aliceLaptop.stop();
it('share keys with added provisional group members', async () => {
const provisionalEmail = `${uuid.v4()}@tanker-functional-test.io`;
const provisionalIdentity = await createProvisionalIdentity(utils.toBase64(args.appHelper.appId), provisionalEmail);
const provisionalPublicIdentity = await getPublicIdentity(provisionalIdentity);
const groupId = await bobLaptop.createGroup([bobPublicIdentity]);
await bobLaptop.updateGroupMembers(groupId, { usersToAdd: [provisionalPublicIdentity] });
const encrypted = await bobLaptop.encrypt(message, { shareWithGroups: [groupId] });
const verificationCode = await args.appHelper.getVerificationCode(provisionalEmail);
await aliceLaptop.attachProvisionalIdentity(provisionalIdentity);
await aliceLaptop.verifyProvisionalIdentity({ email: provisionalEmail, verificationCode });
expect(await aliceLaptop.decrypt(encrypted)).to.deep.equal(message);
});
});
beforeEach(async () => {
email = `${uuid.v4()}@tanker-functional-test.io`;
provisionalIdentity = await createProvisionalIdentity(utils.toBase64(args.appHelper.appId), email);
publicProvisionalIdentity = await getPublicIdentity(provisionalIdentity);
const attachResult = await aliceLaptop.attachProvisionalIdentity(provisionalIdentity);
expect(attachResult).to.deep.equal({
status: aliceLaptop.constructor.statuses.IDENTITY_VERIFICATION_NEEDED,
verificationMethod: { type: 'email', email },
});
});
await Promise.all(emails.map(async (email) => {
if (!foundEmails.includes(email)) {
const user = {
id: uuid(),
email,
provisionalIdentity: await createProvisionalIdentity(serverConfig.appId, email),
};
app.storage.save(user);
users.push(user);
}
}));
}
createIdentity(appId, appSecret, userId).then(async identity => {
const provisionalIdentity = await createProvisionalIdentity(appId, email);
const tanker = new Tanker({ appId, url });
const verificationUI = new VerificationUI(tanker);
await verificationUI.start(email, identity, provisionalIdentity);
});