Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Fixes to password policy validation
  • Loading branch information
kevinthecheung committed Jun 27, 2023
commit bec46531a5ded99953a64c4b882deae8d638efa5
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