Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/auth/auth-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2146,49 +2146,42 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
);
}
}
if (typeof options.constraints.requireUppercase !== undefined &&
if (typeof options.constraints.requireUppercase !== 'undefined' &&
!validator.isBoolean(options.constraints.requireUppercase)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requireUppercase" must be a boolean.',
);
}
if (typeof options.constraints.requireLowercase !== undefined &&
if (typeof options.constraints.requireLowercase !== 'undefined' &&
!validator.isBoolean(options.constraints.requireLowercase)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requireLowercase" must be a boolean.',
);
}
if (typeof options.constraints.requireNonAlphanumeric !== undefined &&
if (typeof options.constraints.requireNonAlphanumeric !== 'undefined' &&
!validator.isBoolean(options.constraints.requireNonAlphanumeric)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requireNonAlphanumeric"' +
' must be a boolean.',
);
}
if (typeof options.constraints.requireNumeric !== undefined &&
if (typeof options.constraints.requireNumeric !== 'undefined' &&
!validator.isBoolean(options.constraints.requireNumeric)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.requireNumeric" must be a boolean.',
);
}
if (!validator.isNumber(options.constraints.minLength)) {
if (typeof options.constraints.minLength === 'undefined') {
options.constraints.minLength = 6;
} else if (!validator.isNumber(options.constraints.minLength)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.minLength" must be a number.',
);
}
if (!validator.isNumber(options.constraints.maxLength)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.maxLength" must be a number.',
);
}
if (options.constraints.minLength === undefined) {
options.constraints.minLength = 6;
} else {
if (!(options.constraints.minLength >= 6
&& options.constraints.minLength <= 30)) {
Expand All @@ -2199,8 +2192,13 @@ export class PasswordPolicyAuthConfig implements PasswordPolicyConfig {
);
}
}
if (options.constraints.maxLength === undefined) {
if (typeof options.constraints.maxLength === 'undefined') {
options.constraints.maxLength = 4096;
} else if (!validator.isNumber(options.constraints.maxLength)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_CONFIG,
'"PasswordPolicyConfig.constraints.maxLength" must be a number.',
);
} else {
if (!(options.constraints.maxLength >= options.constraints.minLength &&
options.constraints.maxLength <= 4096)) {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/auth/auth-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,4 +1297,28 @@ describe('PasswordPolicyAuthConfig',() => {
expect(validConfig.forceUpgradeOnSignin).to.deep.equal(true);
});
});

describe('buildServerRequest()', () => {
it('should return server request with default constraints', () => {
expect(PasswordPolicyAuthConfig.buildServerRequest({
enforcementState: 'ENFORCE',
constraints: {},
})).to.deep.equal({
passwordPolicyEnforcementState: 'ENFORCE',
forceUpgradeOnSignin: false,
passwordPolicyVersions: [
{
customStrengthOptions: {
containsLowercaseCharacter: false,
containsUppercaseCharacter: false,
containsNumericCharacter: false,
containsNonAlphanumericCharacter: false,
minPasswordLength: 6,
maxPasswordLength: 4096,
}
}
]
});
});
});
});