Skip to content

Commit 295f533

Browse files
authored
Merge 62f2b77 into 57ed176
2 parents 57ed176 + 62f2b77 commit 295f533

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ describe('core/auth/auth_impl', () => {
821821
};
822822
const PASSWORD_POLICY_RESPONSE_UNSUPPORTED_SCHEMA_VERSION = {
823823
customStrengthOptions: {
824-
maxPasswordLength: TEST_MIN_PASSWORD_LENGTH,
824+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
825825
unsupportedPasswordPolicyProperty: 10
826826
},
827827
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS,
@@ -850,7 +850,7 @@ describe('core/auth/auth_impl', () => {
850850
};
851851
const CACHED_PASSWORD_POLICY_UNSUPPORTED_SCHEMA_VERSION = {
852852
customStrengthOptions: {
853-
maxPasswordLength: TEST_MIN_PASSWORD_LENGTH
853+
minPasswordLength: TEST_MIN_PASSWORD_LENGTH
854854
},
855855
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_STRING,
856856
enforcementState: TEST_ENFORCEMENT_STATE_ENFORCE,

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ describe('core/auth/password_policy_impl', () => {
9797
enforcementState: TEST_ENFORCEMENT_STATE_ENFORCE,
9898
schemaVersion: TEST_SCHEMA_VERSION
9999
};
100+
const PASSWORD_POLICY_RESPONSE_NO_MIN_LENGTH: GetPasswordPolicyResponse = {
101+
customStrengthOptions: {},
102+
enforcementState: TEST_ENFORCEMENT_STATE_ENFORCE,
103+
schemaVersion: TEST_SCHEMA_VERSION
104+
};
100105
const PASSWORD_POLICY_REQUIRE_ALL: PasswordPolicy = {
101106
customStrengthOptions: {
102107
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
@@ -188,6 +193,13 @@ describe('core/auth/password_policy_impl', () => {
188193
expect(policy.allowedNonAlphanumericCharacters).to.eql('');
189194
});
190195

196+
it('assigns a default minimum length if it is undefined in the response', () => {
197+
const policy: PasswordPolicyInternal = new PasswordPolicyImpl(
198+
PASSWORD_POLICY_RESPONSE_NO_MIN_LENGTH
199+
);
200+
expect(policy.customStrengthOptions.minPasswordLength).to.eql(6);
201+
});
202+
191203
context('#validatePassword', () => {
192204
const PASSWORD_POLICY_IMPL_REQUIRE_ALL = new PasswordPolicyImpl(
193205
PASSWORD_POLICY_RESPONSE_REQUIRE_ALL

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import {
2323
} from '../../model/password_policy';
2424
import { PasswordValidationStatus } from '../../model/public_types';
2525

26+
// Minimum password length enforced by the backend, even if no minimum length is set.
27+
const MINIMUM_MIN_PASSWORD_LENGTH = 6;
28+
2629
/**
2730
* Stores password policy requirements and provides password validation against the policy.
2831
*
@@ -39,10 +42,9 @@ export class PasswordPolicyImpl implements PasswordPolicyInternal {
3942
// Only include custom strength options defined in the response.
4043
const responseOptions = response.customStrengthOptions;
4144
this.customStrengthOptions = {};
42-
if (responseOptions.minPasswordLength) {
43-
this.customStrengthOptions.minPasswordLength =
44-
responseOptions.minPasswordLength;
45-
}
45+
// TODO: Remove once the backend is updated to include the minimum min password length instead of undefined when there is no minimum length set.
46+
this.customStrengthOptions.minPasswordLength =
47+
responseOptions.minPasswordLength ?? MINIMUM_MIN_PASSWORD_LENGTH;
4648
if (responseOptions.maxPasswordLength) {
4749
this.customStrengthOptions.maxPasswordLength =
4850
responseOptions.maxPasswordLength;

0 commit comments

Comments
 (0)