Skip to content

Commit de7987a

Browse files
committed
Use a default minimum password length of 6
1 parent 57ed176 commit de7987a

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ export class PasswordPolicyImpl implements PasswordPolicyInternal {
3939
// Only include custom strength options defined in the response.
4040
const responseOptions = response.customStrengthOptions;
4141
this.customStrengthOptions = {};
42-
if (responseOptions.minPasswordLength) {
43-
this.customStrengthOptions.minPasswordLength =
44-
responseOptions.minPasswordLength;
45-
}
42+
// A minimum length of 6 will be enforced by the backend if no minimum length is set.
43+
this.customStrengthOptions.minPasswordLength =
44+
responseOptions.minPasswordLength ?? 6;
4645
if (responseOptions.maxPasswordLength) {
4746
this.customStrengthOptions.maxPasswordLength =
4847
responseOptions.maxPasswordLength;

0 commit comments

Comments
 (0)