Skip to content

Commit 173d9ca

Browse files
committed
Clean up test cases and rename policy schema version error
1 parent 6798cb3 commit 173d9ca

File tree

3 files changed

+41
-46
lines changed

3 files changed

+41
-46
lines changed

packages/auth/src/core/auth/auth_impl.test.ts

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -788,44 +788,67 @@ describe('core/auth/auth_impl', () => {
788788
});
789789

790790
context('passwordPolicy', () => {
791+
const TEST_ALLOWED_NON_ALPHANUMERIC_CHARS = ['!', '(', ')'];
792+
const TEST_MIN_PASSWORD_LENGTH = 6;
793+
791794
const passwordPolicyResponse = {
792795
customStrengthOptions: {
793-
minPasswordLength: 6
796+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH
794797
},
795-
allowedNonAlphanumericCharacters: ['!', '(', ')'],
798+
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS,
796799
schemaVersion: 1
797800
};
798801
const passwordPolicyResponseRequireNumeric = {
799802
customStrengthOptions: {
800-
minPasswordLength: 6,
803+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
801804
containsNumericCharacter: true
802805
},
803-
allowedNonAlphanumericCharacters: ['!', '(', ')'],
806+
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS,
804807
schemaVersion: 1
805808
};
806809
const passwordPolicyResponseUnsupportedVersion = {
807810
customStrengthOptions: {
808-
maxPasswordLength: 9
811+
maxPasswordLength: TEST_MIN_PASSWORD_LENGTH,
812+
unsupportedPasswordPolicyProperty: 10
809813
},
810-
allowedNonAlphanumericCharacters: ['!'],
814+
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS,
811815
schemaVersion: 0
812816
};
813817
const cachedPasswordPolicy = {
814818
customStrengthOptions: {
815-
minPasswordLength: 6
819+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH
816820
},
817-
allowedNonAlphanumericCharacters: ['!', '(', ')']
821+
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS
818822
};
819823
const cachedPasswordPolicyRequireNumeric = {
820824
customStrengthOptions: {
821-
minPasswordLength: 6,
825+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
822826
containsNumericCharacter: true
823827
},
824-
allowedNonAlphanumericCharacters: ['!', '(', ')']
828+
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS
825829
};
826830

827831
beforeEach(async () => {
828832
mockFetch.setUp();
833+
mockEndpointWithParams(
834+
Endpoint.GET_PASSWORD_POLICY,
835+
{},
836+
passwordPolicyResponse
837+
);
838+
mockEndpointWithParams(
839+
Endpoint.GET_PASSWORD_POLICY,
840+
{
841+
tenantId: 'tenant-id'
842+
},
843+
passwordPolicyResponseRequireNumeric
844+
);
845+
mockEndpointWithParams(
846+
Endpoint.GET_PASSWORD_POLICY,
847+
{
848+
tenantId: 'tenant-id-with-unsupported-policy-version'
849+
},
850+
passwordPolicyResponseUnsupportedVersion
851+
);
829852
});
830853

831854
afterEach(() => {
@@ -835,11 +858,6 @@ describe('core/auth/auth_impl', () => {
835858
it('password policy should be set for project if tenant ID is null', async () => {
836859
auth = await testAuth();
837860
auth.tenantId = null;
838-
mockEndpointWithParams(
839-
Endpoint.GET_PASSWORD_POLICY,
840-
{},
841-
passwordPolicyResponse
842-
);
843861
await auth._updatePasswordPolicy();
844862

845863
expect(auth._getPasswordPolicy()).to.eql(cachedPasswordPolicy);
@@ -848,13 +866,6 @@ describe('core/auth/auth_impl', () => {
848866
it('password policy should be set for tenant if tenant ID is not null', async () => {
849867
auth = await testAuth();
850868
auth.tenantId = 'tenant-id';
851-
mockEndpointWithParams(
852-
Endpoint.GET_PASSWORD_POLICY,
853-
{
854-
tenantId: 'tenant-id'
855-
},
856-
passwordPolicyResponseRequireNumeric
857-
);
858869
await auth._updatePasswordPolicy();
859870

860871
expect(auth._getPasswordPolicy()).to.eql(
@@ -865,20 +876,9 @@ describe('core/auth/auth_impl', () => {
865876
it('password policy should dynamically switch if tenant ID switches.', async () => {
866877
auth = await testAuth();
867878
auth.tenantId = null;
868-
mockEndpointWithParams(
869-
Endpoint.GET_PASSWORD_POLICY,
870-
{},
871-
passwordPolicyResponse
872-
);
873879
await auth._updatePasswordPolicy();
880+
874881
auth.tenantId = 'tenant-id';
875-
mockEndpointWithParams(
876-
Endpoint.GET_PASSWORD_POLICY,
877-
{
878-
tenantId: 'tenant-id'
879-
},
880-
passwordPolicyResponseRequireNumeric
881-
);
882882
await auth._updatePasswordPolicy();
883883

884884
auth.tenantId = null;
@@ -893,17 +893,12 @@ describe('core/auth/auth_impl', () => {
893893

894894
it('password policy should not be set when the schema version is not supported', async () => {
895895
auth = await testAuth();
896-
auth.tenantId = null;
897-
mockEndpointWithParams(
898-
Endpoint.GET_PASSWORD_POLICY,
899-
{},
900-
passwordPolicyResponseUnsupportedVersion
901-
);
896+
auth.tenantId = 'tenant-id-with-unsupported-policy-version';
902897
await expect(auth._updatePasswordPolicy()).to.be.rejectedWith(
903-
AuthErrorCode.PASSWORD_POLICY_VERSION_MISMATCH
898+
AuthErrorCode.UNSUPPORTED_PASSWORD_POLICY_SCHEMA_VERSION
904899
);
905900

906-
expect(auth._getPasswordPolicy()).to.be.null;
901+
expect(auth._getPasswordPolicy()).to.be.undefined;
907902
});
908903
});
909904
});

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
444444
) {
445445
return Promise.reject(
446446
this._errorFactory.create(
447-
AuthErrorCode.PASSWORD_POLICY_VERSION_MISMATCH,
447+
AuthErrorCode.UNSUPPORTED_PASSWORD_POLICY_SCHEMA_VERSION,
448448
{}
449449
)
450450
);

packages/auth/src/core/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const enum AuthErrorCode {
133133
MISSING_RECAPTCHA_VERSION = 'missing-recaptcha-version',
134134
INVALID_RECAPTCHA_VERSION = 'invalid-recaptcha-version',
135135
INVALID_REQ_TYPE = 'invalid-req-type',
136-
PASSWORD_POLICY_VERSION_MISMATCH = 'password-policy-version-mismatch'
136+
UNSUPPORTED_PASSWORD_POLICY_SCHEMA_VERSION = 'unsupported-password-policy-schema-version'
137137
}
138138

139139
function _debugErrorMap(): ErrorMap<AuthErrorCode> {
@@ -383,8 +383,8 @@ function _debugErrorMap(): ErrorMap<AuthErrorCode> {
383383
[AuthErrorCode.INVALID_REQ_TYPE]: 'Invalid request parameters.',
384384
[AuthErrorCode.INVALID_RECAPTCHA_VERSION]:
385385
'The reCAPTCHA version is invalid when sending request to the backend.',
386-
[AuthErrorCode.PASSWORD_POLICY_VERSION_MISMATCH]:
387-
'The password policy received from the backend has a schema version that is not supported by this version of the Firebase SDK.'
386+
[AuthErrorCode.UNSUPPORTED_PASSWORD_POLICY_SCHEMA_VERSION]:
387+
'The password policy received from the backend uses a schema version that is not supported by this version of the Firebase SDK.'
388388
};
389389
}
390390

0 commit comments

Comments
 (0)