@@ -29,7 +29,6 @@ import {
29
29
cleanUpTestInstance ,
30
30
getTestInstance ,
31
31
getTotpCode ,
32
- delay ,
33
32
email ,
34
33
incorrectTotpCode
35
34
} from '../../helpers/integration/helpers' ;
@@ -46,6 +45,7 @@ describe(' Integration tests: Mfa TOTP', () => {
46
45
let auth : Auth ;
47
46
let totpSecret : TotpSecret ;
48
47
let displayName : string ;
48
+ let totpTimestamp : Date ;
49
49
beforeEach ( async ( ) => {
50
50
auth = getTestInstance ( ) ;
51
51
displayName = 'totp-integration-test' ;
@@ -80,10 +80,13 @@ describe(' Integration tests: Mfa TOTP', () => {
80
80
81
81
totpSecret = await TotpMultiFactorGenerator . generateSecret ( session ) ;
82
82
83
+ totpTimestamp = new Date ( ) ;
84
+
83
85
const totpVerificationCode = getTotpCode (
84
86
totpSecret . secretKey ,
85
87
totpSecret . codeIntervalSeconds ,
86
- totpSecret . codeLength
88
+ totpSecret . codeLength ,
89
+ totpTimestamp
87
90
) ;
88
91
89
92
const multiFactorAssertion =
@@ -122,11 +125,6 @@ describe(' Integration tests: Mfa TOTP', () => {
122
125
123
126
it ( 'should allow sign-in with for correct totp and unenroll successfully' , async ( ) => {
124
127
let resolver ;
125
-
126
- await delay ( 30 * 1000 ) ;
127
- //TODO(bhparijat) generate the otp code for the next time window by passing the appropriate
128
- //timestamp to avoid the 30s delay. The delay is needed because the otp code used for enrollment
129
- //cannot be reused for signing in.
130
128
try {
131
129
await signInWithEmailAndPassword ( auth , email , 'password' ) ;
132
130
@@ -138,11 +136,15 @@ describe(' Integration tests: Mfa TOTP', () => {
138
136
resolver = getMultiFactorResolver ( auth , error as any ) ;
139
137
expect ( resolver . hints ) . to . have . length ( 1 ) ;
140
138
139
+ totpTimestamp . setSeconds ( totpTimestamp . getSeconds ( ) + 30 ) ;
140
+
141
141
const totpVerificationCode = getTotpCode (
142
142
totpSecret . secretKey ,
143
143
totpSecret . codeIntervalSeconds ,
144
- totpSecret . codeLength
144
+ totpSecret . codeLength ,
145
+ totpTimestamp
145
146
) ;
147
+
146
148
const assertion = TotpMultiFactorGenerator . assertionForSignIn (
147
149
resolver . hints [ 0 ] . uid ,
148
150
totpVerificationCode
@@ -153,5 +155,5 @@ describe(' Integration tests: Mfa TOTP', () => {
153
155
154
156
await expect ( mfaUser . unenroll ( resolver . hints [ 0 ] . uid ) ) . to . be . fulfilled ;
155
157
}
156
- } ) . timeout ( 32000 ) ;
158
+ } ) ;
157
159
} ) ;
0 commit comments