Skip to content

Fix bug when non-alphanumeric characters is undefined #7485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface GetPasswordPolicyResponse {
containsNumericCharacter?: boolean;
containsNonAlphanumericCharacter?: boolean;
};
allowedNonAlphanumericCharacters: string[];
allowedNonAlphanumericCharacters?: string[];
enforcementState: string;
forceUpgradeOnSignin?: boolean;
schemaVersion: number;
Expand Down
16 changes: 16 additions & 0 deletions packages/auth/src/core/auth/password_policy_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ describe('core/auth/password_policy_impl', () => {
enforcementState: 'ENFORCEMENT_STATE_UNSPECIFIED',
schemaVersion: TEST_SCHEMA_VERSION
};
const PASSWORD_POLICY_RESPONSE_NO_NON_ALPHANUMERIC_CHARS: GetPasswordPolicyResponse =
{
customStrengthOptions: {
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
maxPasswordLength: TEST_MAX_PASSWORD_LENGTH
},
enforcementState: TEST_ENFORCEMENT_STATE_ENFORCE,
schemaVersion: TEST_SCHEMA_VERSION
};
const PASSWORD_POLICY_REQUIRE_ALL: PasswordPolicy = {
customStrengthOptions: {
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
Expand Down Expand Up @@ -172,6 +181,13 @@ describe('core/auth/password_policy_impl', () => {
expect(policy.forceUpgradeOnSignin).to.be.false;
});

it('assigns an empty string as the allowed non-alphanumeric characters when they are undefined in the response', () => {
const policy: PasswordPolicyInternal = new PasswordPolicyImpl(
PASSWORD_POLICY_RESPONSE_NO_NON_ALPHANUMERIC_CHARS
);
expect(policy.allowedNonAlphanumericCharacters).to.eql('');
});

context('#validatePassword', () => {
const PASSWORD_POLICY_IMPL_REQUIRE_ALL = new PasswordPolicyImpl(
PASSWORD_POLICY_RESPONSE_REQUIRE_ALL
Expand Down
4 changes: 3 additions & 1 deletion packages/auth/src/core/auth/password_policy_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ export class PasswordPolicyImpl implements PasswordPolicyInternal {
this.enforcementState = 'OFF';
}

// Use an empty string if no non-alphanumeric characters are specified in the response.
this.allowedNonAlphanumericCharacters =
response.allowedNonAlphanumericCharacters.join('');
response.allowedNonAlphanumericCharacters?.join('') ?? '';

this.forceUpgradeOnSignin = response.forceUpgradeOnSignin ?? false;
this.schemaVersion = response.schemaVersion;
}
Expand Down