Skip to content

Commit 76be134

Browse files
committed
all tests passing with test email
1 parent 41ec7e0 commit 76be134

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

packages/auth/test/helpers/integration/helpers.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { getAuth, connectAuthEmulator } from '../../../'; // Use browser OR node
2323
import { _generateEventId } from '../../../src/core/util/event_id';
2424
import { getAppConfig, getEmulatorUrl } from './settings';
2525
import { getOobCodes, OobCodeSession, resetEmulator } from './emulator_rest_helpers';
26-
import { StartTotpMfaEnrollmentResponse } from '../../../src/api/account_management/mfa';
26+
import * as config from '../../../../../config/project.json';
2727

2828
//import * as otpauth from "https://deno.land/x/[email protected]/dist/otpauth.esm.js";
2929
//// <reference path="helpers.d.ts"/>
@@ -83,9 +83,13 @@ export function getTestInstance(requireEmulator = false): Auth {
8383
return auth;
8484
}
8585

86-
export async function cleanUpTestInstance(auth: Auth): Promise<void> {
86+
export async function cleanUpTestInstance(auth: Auth, tests? : string): Promise<void> {
8787
await auth.signOut();
88-
//await (auth as IntegrationTestAuth).cleanUp();
88+
89+
if(typeof tests === 'undefined') {
90+
await (auth as IntegrationTestAuth).cleanUp();
91+
}
92+
8993
}
9094

9195
function stubConsoleToSilenceEmulatorWarnings(): sinon.SinonStub {
@@ -123,4 +127,6 @@ export function delay(dt:number){
123127
console.log('Delay called');
124128

125129
return new Promise(resolve => setTimeout(resolve, dt));
126-
}
130+
}
131+
132+
export const email = '[email protected]';

packages/auth/test/integration/flows/totp.test.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
getTestInstance,
3030
getTotpCode,
3131
delay,
32-
randomEmail
32+
randomEmail,
33+
verifyEmail,
34+
email
3335
} from '../../helpers/integration/helpers';
3436
import { MultiFactorAssertionImpl } from '../../../src/mfa/mfa_assertion';
3537

@@ -40,6 +42,7 @@ import { async } from '@firebase/util';
4042
import { UserCredentialImpl } from '../../../src/core/user/user_credential_impl';
4143
import { resolve } from 'dns';
4244
import { UserCredentialInternal } from '../../../internal';
45+
import { verify } from 'crypto';
4346

4447

4548

@@ -53,35 +56,28 @@ describe(' Integration tests: Mfa TOTP', () => {
5356
let idToken: string;
5457
let signUpCred: UserCredential;
5558
let totpSecret: TotpSecret;
56-
let email: string;
5759
let assertion: MultiFactorAssertionImpl;
5860
let _request: MFA.StartTotpMfaEnrollmentRequest;
5961
let startMfaResponse: MFA.StartTotpMfaEnrollmentResponse;
6062
let displayName: string;
6163
beforeEach(async () => {
6264
auth = getTestInstance();
63-
email = '[email protected]';
6465
displayName = 'totp-integration-test';
65-
66-
// signUpCred = await createUserWithEmailAndPassword(
67-
68-
// auth,
69-
// email,
70-
// 'password'
71-
// );
72-
// await auth.signOut();
7366
});
7467

7568
afterEach(async () => {
76-
await cleanUpTestInstance(auth);
77-
69+
await cleanUpTestInstance(auth, 'totp');
70+
7871
});
7972

8073
it('should not enroll if incorrect totp supplied', async () => {
8174
let session;
8275
console.log(email);
8376
console.log('session info for: ', getApp().options.projectId);
8477
console.log('auth current User:', auth.currentUser);
78+
79+
await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
80+
8581
const cr = await signInWithEmailAndPassword(auth, email, 'password');
8682

8783
console.log('signed In for totp');
@@ -119,16 +115,9 @@ describe(' Integration tests: Mfa TOTP', () => {
119115
console.log(email);
120116
console.log('session info for: ', getApp().options.projectId);
121117
console.log('auth current User:', auth.currentUser);
118+
await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
122119
const cr = await signInWithEmailAndPassword(auth, email, 'password');
123120

124-
125-
// await sendEmailVerification(cr.user);
126-
127-
// //Apply the email verification code
128-
// await applyActionCode(auth, (await code(email)).oobCode);
129-
// await cr.user.reload();
130-
// expect(cr.user.emailVerified).to.be.true;
131-
132121
console.log('signed In for totp');
133122
const mfaUser = multiFactor(cr.user);
134123

@@ -168,11 +157,6 @@ describe(' Integration tests: Mfa TOTP', () => {
168157

169158
await auth.signOut();
170159

171-
//await expect(signInWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/multi-factor-auth-required');
172-
173-
174-
//await expect().to.be.rejectedWith(FirebaseError);
175-
176160
})
177161

178162
it('should not allow sign-in with incorrect totp', async () => {
@@ -181,8 +165,8 @@ describe(' Integration tests: Mfa TOTP', () => {
181165
let resolver;
182166
console.log(email);
183167
console.log('session info for: ', getApp().options.projectId);
184-
185-
// Added a delay so that getTotpCode() actually generates a new totp code
168+
await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
169+
// Added a delay so that getTotpCode() actually generates a new totp code
186170
await delay(30*1000);
187171
try{
188172

@@ -227,7 +211,8 @@ describe(' Integration tests: Mfa TOTP', () => {
227211

228212
console.log(email);
229213
console.log('session info for: ', getApp().options.projectId);
230-
214+
215+
await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
231216
// Added a delay so that getTotpCode() actually generates a new totp code
232217
await delay(30*1000);
233218
try{
@@ -263,8 +248,9 @@ describe(' Integration tests: Mfa TOTP', () => {
263248
const mfaUser = multiFactor(userCredential.user);
264249

265250
await expect(mfaUser.unenroll(resolver.hints[0].uid)).to.be.fulfilled;
251+
266252
await auth.signOut();
267253

268254
}
269-
}).timeout(31000);
255+
}).timeout(35000);
270256
})

0 commit comments

Comments
 (0)