Skip to content

Commit f0acf72

Browse files
committed
Update constant naming and check undefined fields in policy
1 parent a9e4fdd commit f0acf72

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('core/auth/password_policy_impl', () => {
3434
const TEST_CONTAINS_NON_ALPHANUMERIC = true;
3535
const TEST_ALLOWED_NON_ALPHANUMERIC_CHARS = ['!', '(', ')'];
3636
const TEST_SCHEMA_VERSION = 1;
37-
const passwordPolicyResponseRequireAll: GetPasswordPolicyResponse = {
37+
const PASSWORD_POLICY_RESPONSE_REQUIRE_ALL: GetPasswordPolicyResponse = {
3838
customStrengthOptions: {
3939
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
4040
maxPasswordLength: TEST_MAX_PASSWORD_LENGTH,
@@ -46,15 +46,15 @@ describe('core/auth/password_policy_impl', () => {
4646
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS,
4747
schemaVersion: TEST_SCHEMA_VERSION
4848
};
49-
const passwordPolicyResponseRequireLength: GetPasswordPolicyResponse = {
49+
const PASSWORD_POLICY_RESPONSE_REQUIRE_LENGTH: GetPasswordPolicyResponse = {
5050
customStrengthOptions: {
5151
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
5252
maxPasswordLength: TEST_MAX_PASSWORD_LENGTH
5353
},
5454
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS,
5555
schemaVersion: TEST_SCHEMA_VERSION
5656
};
57-
const passwordPolicyRequireAll: PasswordPolicy = {
57+
const PASSWORD_POLICY_REQUIRE_ALL: PasswordPolicy = {
5858
customStrengthOptions: {
5959
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
6060
maxPasswordLength: TEST_MAX_PASSWORD_LENGTH,
@@ -65,7 +65,7 @@ describe('core/auth/password_policy_impl', () => {
6565
},
6666
allowedNonAlphanumericCharacters: TEST_ALLOWED_NON_ALPHANUMERIC_CHARS
6767
};
68-
const passwordPolicyRequireLength: PasswordPolicy = {
68+
const PASSWORD_POLICY_REQUIRE_LENGTH: PasswordPolicy = {
6969
customStrengthOptions: {
7070
minPasswordLength: TEST_MIN_PASSWORD_LENGTH,
7171
maxPasswordLength: TEST_MAX_PASSWORD_LENGTH
@@ -76,28 +76,37 @@ describe('core/auth/password_policy_impl', () => {
7676
context('#PasswordPolicyImpl', () => {
7777
it('can construct the password policy from the backend response', () => {
7878
const policy: PasswordPolicy = new PasswordPolicyImpl(
79-
passwordPolicyResponseRequireAll
79+
PASSWORD_POLICY_RESPONSE_REQUIRE_ALL
8080
);
8181
// The password policy contains the schema version internally, but the public typing does not.
8282
// Only check the fields that are publicly exposed.
8383
expect(policy.customStrengthOptions).to.eql(
84-
passwordPolicyRequireAll.customStrengthOptions
84+
PASSWORD_POLICY_REQUIRE_ALL.customStrengthOptions
8585
);
8686
expect(policy.allowedNonAlphanumericCharacters).to.eql(
87-
passwordPolicyRequireAll.allowedNonAlphanumericCharacters
87+
PASSWORD_POLICY_REQUIRE_ALL.allowedNonAlphanumericCharacters
8888
);
8989
});
9090

9191
it('only includes requirements defined in the response', () => {
9292
const policy: PasswordPolicy = new PasswordPolicyImpl(
93-
passwordPolicyResponseRequireLength
93+
PASSWORD_POLICY_RESPONSE_REQUIRE_LENGTH
9494
);
9595
expect(policy.customStrengthOptions).to.eql(
96-
passwordPolicyRequireLength.customStrengthOptions
96+
PASSWORD_POLICY_REQUIRE_LENGTH.customStrengthOptions
9797
);
9898
expect(policy.allowedNonAlphanumericCharacters).to.eql(
99-
passwordPolicyRequireLength.allowedNonAlphanumericCharacters
99+
PASSWORD_POLICY_REQUIRE_LENGTH.allowedNonAlphanumericCharacters
100100
);
101+
// Requirements that are not in the response should be undefined.
102+
expect(policy.customStrengthOptions.containsLowercaseLetter).to.be
103+
.undefined;
104+
expect(policy.customStrengthOptions.containsUppercaseLetter).to.be
105+
.undefined;
106+
expect(policy.customStrengthOptions.containsNumericCharacter).to.be
107+
.undefined;
108+
expect(policy.customStrengthOptions.containsNonAlphanumericCharacter).to
109+
.be.undefined;
101110
});
102111
});
103112
});

0 commit comments

Comments
 (0)