Skip to content

Commit eac5600

Browse files
committed
addressed review comments, added totp subdirectory.
1 parent 0c70e50 commit eac5600

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('api/account_management/startEnrollPhoneMfa', () => {
9191

9292
await expect(startEnrollPhoneMfa(auth, request)).to.be.rejectedWith(
9393
FirebaseError,
94-
"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)."
94+
'auth/invalid-user-token'
9595
);
9696
expect(mock.calls[0].request).to.eql(request);
9797
});
@@ -155,7 +155,7 @@ describe('api/account_management/finalizeEnrollPhoneMfa', () => {
155155

156156
await expect(finalizeEnrollPhoneMfa(auth, request)).to.be.rejectedWith(
157157
FirebaseError,
158-
'Firebase: The verification ID used to create the phone auth credential is invalid. (auth/invalid-verification-id).'
158+
'auth/invalid-verification-id'
159159
);
160160
expect(mock.calls[0].request).to.eql(request);
161161
});
@@ -225,7 +225,7 @@ describe('api/account_management/startEnrollTotpMfa', () => {
225225

226226
await expect(startEnrollTotpMfa(auth, request)).to.be.rejectedWith(
227227
FirebaseError,
228-
"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)."
228+
'auth/invalid-user-token'
229229
);
230230
expect(mock.calls[0].request).to.eql(request);
231231
});

packages/auth/src/mfa/assertions/totp.test.ts renamed to packages/auth/src/mfa/assertions/totp/totp.test.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@
1818
import { expect, use } from 'chai';
1919
import chaiAsPromised from 'chai-as-promised';
2020

21-
import { mockEndpoint } from '../../../test/helpers/api/helper';
22-
import { testAuth, TestAuth, testUser } from '../../../test/helpers/mock_auth';
23-
import * as mockFetch from '../../../test/helpers/mock_fetch';
24-
import { Endpoint } from '../../api';
25-
import { MultiFactorSessionImpl } from '../../mfa/mfa_session';
26-
import { StartTotpMfaEnrollmentResponse } from '../../api/account_management/mfa';
27-
import { FinalizeMfaResponse } from '../../api/authentication/mfa';
21+
import { mockEndpoint } from '../../../../test/helpers/api/helper';
22+
import {
23+
testAuth,
24+
TestAuth,
25+
testUser
26+
} from '../../../../test/helpers/mock_auth';
27+
import * as mockFetch from '../../../../test/helpers/mock_fetch';
28+
import { Endpoint } from '../../../api';
29+
import { MultiFactorSessionImpl } from '../../../mfa/mfa_session';
30+
import { StartTotpMfaEnrollmentResponse } from '../../../api/account_management/mfa';
31+
import { FinalizeMfaResponse } from '../../../api/authentication/mfa';
2832
import {
2933
TotpMultiFactorAssertionImpl,
3034
TotpMultiFactorGenerator,
3135
TotpSecret
3236
} from './totp';
33-
import { FactorId } from '../../model/public_types';
34-
import { AuthErrorCode } from '../../core/errors';
35-
import { AppName } from '../../model/auth';
36-
import { _castAuth } from '../../core/auth/auth_impl';
37+
import { FactorId } from '../../../model/public_types';
38+
import { AuthErrorCode } from '../../../core/errors';
39+
import { AppName } from '../../../model/auth';
40+
import { _castAuth } from '../../../core/auth/auth_impl';
3741

3842
use(chaiAsPromised);
3943

@@ -53,7 +57,7 @@ describe('core/mfa/assertions/totp/TotpMultiFactorGenerator', () => {
5357
describe('assertionForEnrollment', () => {
5458
it('should generate a valid TOTP assertion for enrollment', async () => {
5559
auth = await testAuth();
56-
const secret = TotpSecret.fromStartTotpMfaEnrollmentResponse(
60+
const secret = TotpSecret._fromStartTotpMfaEnrollmentResponse(
5761
startEnrollmentResponse,
5862
auth
5963
);
@@ -149,7 +153,7 @@ describe('core/mfa/totp/assertions/TotpMultiFactorAssertionImpl', () => {
149153
beforeEach(async () => {
150154
mockFetch.setUp();
151155
auth = await testAuth();
152-
secret = TotpSecret.fromStartTotpMfaEnrollmentResponse(
156+
secret = TotpSecret._fromStartTotpMfaEnrollmentResponse(
153157
startEnrollmentResponse,
154158
auth
155159
);
@@ -223,7 +227,7 @@ describe('core/mfa/assertions/totp/TotpSecret', async () => {
223227
const fakeAppName: AppName = 'test-app';
224228
const fakeEmail: string = 'user@email';
225229
const auth = await testAuth();
226-
const secret = TotpSecret.fromStartTotpMfaEnrollmentResponse(
230+
const secret = TotpSecret._fromStartTotpMfaEnrollmentResponse(
227231
serverResponse,
228232
auth
229233
);

packages/auth/src/mfa/assertions/totp.ts renamed to packages/auth/src/mfa/assertions/totp/totp.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ import {
1818
TotpMultiFactorAssertion,
1919
MultiFactorSession,
2020
FactorId
21-
} from '../../model/public_types';
22-
import { AuthInternal } from '../../model/auth';
21+
} from '../../../model/public_types';
22+
import { AuthInternal } from '../../../model/auth';
2323
import {
2424
finalizeEnrollTotpMfa,
2525
startEnrollTotpMfa,
2626
StartTotpMfaEnrollmentResponse,
2727
TotpVerificationInfo
28-
} from '../../api/account_management/mfa';
29-
import { FinalizeMfaResponse } from '../../api/authentication/mfa';
30-
import { MultiFactorAssertionImpl } from '../../mfa/mfa_assertion';
31-
import { MultiFactorSessionImpl } from '../mfa_session';
32-
import { AuthErrorCode } from '../../core/errors';
33-
import { _assert } from '../../core/util/assert';
28+
} from '../../../api/account_management/mfa';
29+
import { FinalizeMfaResponse } from '../../../api/authentication/mfa';
30+
import { MultiFactorAssertionImpl } from '../../../mfa/mfa_assertion';
31+
import { MultiFactorSessionImpl } from '../../mfa_session';
32+
import { AuthErrorCode } from '../../../core/errors';
33+
import { _assert } from '../../../core/util/assert';
3434

3535
/**
3636
* Provider for generating a {@link TotpMultiFactorAssertion}.
@@ -95,7 +95,7 @@ export class TotpMultiFactorGenerator {
9595
idToken: mfaSession.credential,
9696
totpEnrollmentInfo: {}
9797
});
98-
return TotpSecret.fromStartTotpMfaEnrollmentResponse(
98+
return TotpSecret._fromStartTotpMfaEnrollmentResponse(
9999
response,
100100
mfaSession.auth
101101
);
@@ -119,25 +119,20 @@ export class TotpMultiFactorAssertionImpl
119119
super(FactorId.TOTP);
120120
}
121121

122+
/** @internal */
122123
static _fromSecret(
123124
secret: TotpSecret,
124125
otp: string
125126
): TotpMultiFactorAssertionImpl {
126-
return new TotpMultiFactorAssertionImpl(
127-
(otp = otp),
128-
undefined,
129-
(secret = secret)
130-
);
127+
return new TotpMultiFactorAssertionImpl(otp, undefined, secret);
131128
}
132129

130+
/** @internal */
133131
static _fromEnrollmentId(
134132
enrollmentId: string,
135133
otp: string
136134
): TotpMultiFactorAssertionImpl {
137-
return new TotpMultiFactorAssertionImpl(
138-
(otp = otp),
139-
(enrollmentId = enrollmentId)
140-
);
135+
return new TotpMultiFactorAssertionImpl(otp, enrollmentId);
141136
}
142137

143138
/** @internal */
@@ -154,7 +149,7 @@ export class TotpMultiFactorAssertionImpl
154149
return finalizeEnrollTotpMfa(auth, {
155150
idToken,
156151
displayName,
157-
totpVerificationInfo: this.secret.makeTotpVerificationInfo(this.otp)
152+
totpVerificationInfo: this.secret._makeTotpVerificationInfo(this.otp)
158153
});
159154
}
160155

@@ -194,7 +189,8 @@ export class TotpSecret {
194189
private readonly auth: AuthInternal
195190
) {}
196191

197-
static fromStartTotpMfaEnrollmentResponse(
192+
/** @internal */
193+
static _fromStartTotpMfaEnrollmentResponse(
198194
response: StartTotpMfaEnrollmentResponse,
199195
auth: AuthInternal
200196
): TotpSecret {
@@ -209,7 +205,8 @@ export class TotpSecret {
209205
);
210206
}
211207

212-
makeTotpVerificationInfo(otp: string): TotpVerificationInfo {
208+
/** @internal */
209+
_makeTotpVerificationInfo(otp: string): TotpVerificationInfo {
213210
return { sessionInfo: this.sessionInfo, verificationCode: otp };
214211
}
215212

@@ -240,6 +237,7 @@ export class TotpSecret {
240237
}
241238
}
242239

240+
/** @internal */
243241
function _isEmptyString(input?: string): boolean {
244242
return typeof input === 'undefined' || input?.length === 0;
245243
}

0 commit comments

Comments
 (0)