Skip to content

Commit

Permalink
feat(2FA): make 2FA work with phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
francisco-tanker committed Apr 20, 2022
1 parent 492378a commit 1dc81ec
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions example/src/test_tanker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
IdentityAlreadyAttached,
} from '@tanker/errors';
import { createTanker, clearTankerDataDirs } from './tests';
import base64 from 'react-native-base64';

export const tankerTests = () => {
describe('Tanker tests', () => {
Expand Down Expand Up @@ -262,6 +263,57 @@ export const tankerTests = () => {
await secondDevice.stop();
});

it('can request a session token with VerificationOptions', async () => {
await tanker.start(identity);
const token = await tanker.registerIdentity(
{ passphrase: 'foo' },
{ withSessionToken: true }
);
expect(tanker.status).eq(Tanker.statuses.READY);
expect(token).is.not.empty;
// @ts-ignore is.not.empty checks that the token is not undefined
const tokenData = base64.decode(token);
expect(tokenData).length.greaterThanOrEqual(32);
});

it('can use setVerificationMethod with email to get a session token', async () => {
await tanker.start(identity);
await tanker.registerIdentity({
passphrase: 'Space and time are not what you think',
});

const email = '[email protected]';
const verificationCode = await getVerificationCode(email);
const token = await tanker.setVerificationMethod(
{ email, verificationCode },
{ withSessionToken: true }
);

expect(token).is.not.empty;
// @ts-ignore is.not.empty checks that the token is not undefined
const tokenData = base64.decode(token);
expect(tokenData).length.greaterThanOrEqual(32);
});

it('can use setVerificationMethod with phone number to get a session token', async () => {
await tanker.start(identity);
await tanker.registerIdentity({
passphrase: 'Space and time are not what you think',
});

const phoneNumber = '+33639982233';
const verificationCode = await getSMSVerificationCode(phoneNumber);
const token = await tanker.setVerificationMethod(
{ phoneNumber, verificationCode },
{ withSessionToken: true }
);

expect(token).is.not.empty;
// @ts-ignore is.not.empty checks that the token is not undefined
const tokenData = base64.decode(token);
expect(tokenData).length.greaterThanOrEqual(32);
});

it('can use a verificationKey', async () => {
await tanker.start(identity);
const verifKey = await tanker.generateVerificationKey();
Expand Down

0 comments on commit 1dc81ec

Please sign in to comment.