Skip to content

Commit 2f51103

Browse files
authored
Fix bug when non-alphanumeric characters is undefined in password policy response (#7485)
* Store an empty string if no non-alphanumeric characters are included in the password policy response
1 parent defdb66 commit 2f51103

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

packages/auth/src/api/password_policy/get_password_policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface GetPasswordPolicyResponse {
4242
containsNumericCharacter?: boolean;
4343
containsNonAlphanumericCharacter?: boolean;
4444
};
45-
allowedNonAlphanumericCharacters: string[];
45+
allowedNonAlphanumericCharacters?: string[];
4646
enforcementState: string;
4747
forceUpgradeOnSignin?: boolean;
4848
schemaVersion: number;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ describe('core/auth/password_policy_impl', () => {
8888
enforcementState: 'ENFORCEMENT_STATE_UNSPECIFIED',
8989
schemaVersion: TEST_SCHEMA_VERSION
9090
};
91+
const PASSWORD_POLICY_RESPONSE_NO_NON_ALPHANUMERIC_CHARS: GetPasswordPolicyResponse =
92+
{
93+
customStrengthOptions: {
94+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
95+
maxPasswordLength: TEST_MAX_PASSWORD_LENGTH
96+
},
97+
enforcementState: TEST_ENFORCEMENT_STATE_ENFORCE,
98+
schemaVersion: TEST_SCHEMA_VERSION
99+
};
91100
const PASSWORD_POLICY_REQUIRE_ALL: PasswordPolicy = {
92101
customStrengthOptions: {
93102
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
@@ -172,6 +181,13 @@ describe('core/auth/password_policy_impl', () => {
172181
expect(policy.forceUpgradeOnSignin).to.be.false;
173182
});
174183

184+
it('assigns an empty string as the allowed non-alphanumeric characters when they are undefined in the response', () => {
185+
const policy: PasswordPolicyInternal = new PasswordPolicyImpl(
186+
PASSWORD_POLICY_RESPONSE_NO_NON_ALPHANUMERIC_CHARS
187+
);
188+
expect(policy.allowedNonAlphanumericCharacters).to.eql('');
189+
});
190+
175191
context('#validatePassword', () => {
176192
const PASSWORD_POLICY_IMPL_REQUIRE_ALL = new PasswordPolicyImpl(
177193
PASSWORD_POLICY_RESPONSE_REQUIRE_ALL

packages/auth/src/core/auth/password_policy_impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ export class PasswordPolicyImpl implements PasswordPolicyInternal {
6969
this.enforcementState = 'OFF';
7070
}
7171

72+
// Use an empty string if no non-alphanumeric characters are specified in the response.
7273
this.allowedNonAlphanumericCharacters =
73-
response.allowedNonAlphanumericCharacters.join('');
74+
response.allowedNonAlphanumericCharacters?.join('') ?? '';
75+
7476
this.forceUpgradeOnSignin = response.forceUpgradeOnSignin ?? false;
7577
this.schemaVersion = response.schemaVersion;
7678
}

0 commit comments

Comments
 (0)