Skip to content

Commit 9b211bd

Browse files
committed
addressed review comments, added totp subdirectory.
1 parent 94198a6 commit 9b211bd

File tree

3 files changed

+0
-656
lines changed

3 files changed

+0
-656
lines changed

packages/auth/src/api/account_management/mfa.test.ts

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -294,139 +294,6 @@ describe('api/account_management/finalizeEnrollTotpMfa', () => {
294294
});
295295
});
296296

297-
describe('api/account_management/startEnrollTotpMfa', () => {
298-
const request = {
299-
idToken: 'id-token',
300-
totpEnrollmentInfo: {}
301-
};
302-
303-
let auth: TestAuth;
304-
305-
beforeEach(async () => {
306-
auth = await testAuth();
307-
mockFetch.setUp();
308-
});
309-
310-
afterEach(mockFetch.tearDown);
311-
312-
it('should POST to the correct endpoint', async () => {
313-
const currentTime = new Date().toISOString();
314-
const mock = mockEndpoint(Endpoint.START_MFA_ENROLLMENT, {
315-
totpSessionInfo: {
316-
sharedSecretKey: 'key123',
317-
verificationCodeLength: 6,
318-
hashingAlgorithm: 'SHA256',
319-
periodSec: 30,
320-
sessionInfo: 'session-info',
321-
finalizeEnrollmentTime: currentTime
322-
}
323-
});
324-
325-
const response = await startEnrollTotpMfa(auth, request);
326-
expect(response.totpSessionInfo.sharedSecretKey).to.eq('key123');
327-
expect(response.totpSessionInfo.verificationCodeLength).to.eq(6);
328-
expect(response.totpSessionInfo.hashingAlgorithm).to.eq('SHA256');
329-
expect(response.totpSessionInfo.periodSec).to.eq(30);
330-
expect(response.totpSessionInfo.sessionInfo).to.eq('session-info');
331-
expect(response.totpSessionInfo.finalizeEnrollmentTime).to.eq(currentTime);
332-
expect(mock.calls[0].request).to.eql(request);
333-
expect(mock.calls[0].method).to.eq('POST');
334-
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
335-
'application/json'
336-
);
337-
expect(mock.calls[0].headers!.get(HttpHeader.X_CLIENT_VERSION)).to.eq(
338-
'testSDK/0.0.0'
339-
);
340-
});
341-
342-
it('should handle errors', async () => {
343-
const mock = mockEndpoint(
344-
Endpoint.START_MFA_ENROLLMENT,
345-
{
346-
error: {
347-
code: 400,
348-
message: ServerError.INVALID_ID_TOKEN,
349-
errors: [
350-
{
351-
message: ServerError.INVALID_ID_TOKEN
352-
}
353-
]
354-
}
355-
},
356-
400
357-
);
358-
359-
await expect(startEnrollTotpMfa(auth, request)).to.be.rejectedWith(
360-
FirebaseError,
361-
"Firebase: This user's credential isn't valid for this project. This can happen if the user's token has been tampered with, or if the user isn't for the project associated with this API key. (auth/invalid-user-token)."
362-
);
363-
expect(mock.calls[0].request).to.eql(request);
364-
});
365-
});
366-
367-
describe('api/account_management/finalizeEnrollTotpMfa', () => {
368-
const request = {
369-
idToken: 'id-token',
370-
displayName: 'my-otp-app',
371-
totpVerificationInfo: {
372-
sessionInfo: 'session-info',
373-
verificationCode: 'code'
374-
}
375-
};
376-
377-
let auth: TestAuth;
378-
379-
beforeEach(async () => {
380-
auth = await testAuth();
381-
mockFetch.setUp();
382-
});
383-
384-
afterEach(mockFetch.tearDown);
385-
386-
it('should POST to the correct endpoint', async () => {
387-
const mock = mockEndpoint(Endpoint.FINALIZE_MFA_ENROLLMENT, {
388-
idToken: 'id-token',
389-
refreshToken: 'refresh-token'
390-
});
391-
392-
const response = await finalizeEnrollTotpMfa(auth, request);
393-
expect(response.idToken).to.eq('id-token');
394-
expect(response.refreshToken).to.eq('refresh-token');
395-
expect(mock.calls[0].request).to.eql(request);
396-
expect(mock.calls[0].method).to.eq('POST');
397-
expect(mock.calls[0].headers!.get(HttpHeader.CONTENT_TYPE)).to.eq(
398-
'application/json'
399-
);
400-
expect(mock.calls[0].headers!.get(HttpHeader.X_CLIENT_VERSION)).to.eq(
401-
'testSDK/0.0.0'
402-
);
403-
});
404-
405-
it('should handle errors', async () => {
406-
const mock = mockEndpoint(
407-
Endpoint.FINALIZE_MFA_ENROLLMENT,
408-
{
409-
error: {
410-
code: 400,
411-
message: ServerError.INVALID_SESSION_INFO,
412-
errors: [
413-
{
414-
message: ServerError.INVALID_SESSION_INFO
415-
}
416-
]
417-
}
418-
},
419-
400
420-
);
421-
422-
await expect(finalizeEnrollTotpMfa(auth, request)).to.be.rejectedWith(
423-
FirebaseError,
424-
'Firebase: The verification ID used to create the phone auth credential is invalid. (auth/invalid-verification-id).'
425-
);
426-
expect(mock.calls[0].request).to.eql(request);
427-
});
428-
});
429-
430297
describe('api/account_management/withdrawMfa', () => {
431298
const request = {
432299
idToken: 'id-token',

0 commit comments

Comments
 (0)