@@ -60,6 +60,15 @@ describe('core/auth/password_policy_impl', () => {
60
60
allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS ,
61
61
schemaVersion : TEST_SCHEMA_VERSION
62
62
} ;
63
+ const PASSWORD_POLICY_RESPONSE_REQUIRE_NUMERIC : GetPasswordPolicyResponse = {
64
+ customStrengthOptions : {
65
+ minPasswordLength : TEST_MIN_PASSWORD_LENGTH ,
66
+ maxPasswordLength : TEST_MAX_PASSWORD_LENGTH ,
67
+ containsNumericCharacter : TEST_CONTAINS_NUMERIC
68
+ } ,
69
+ allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_CHARS ,
70
+ schemaVersion : TEST_SCHEMA_VERSION
71
+ } ;
63
72
const PASSWORD_POLICY_REQUIRE_ALL : PasswordPolicy = {
64
73
customStrengthOptions : {
65
74
minPasswordLength : TEST_MIN_PASSWORD_LENGTH ,
@@ -78,6 +87,7 @@ describe('core/auth/password_policy_impl', () => {
78
87
} ,
79
88
allowedNonAlphanumericCharacters : TEST_ALLOWED_NON_ALPHANUMERIC_STRING
80
89
} ;
90
+ const TEST_EMPTY_PASSWORD = '' ;
81
91
82
92
context ( '#PasswordPolicyImpl' , ( ) => {
83
93
it ( 'can construct the password policy from the backend response' , ( ) => {
@@ -126,6 +136,9 @@ describe('core/auth/password_policy_impl', () => {
126
136
const PASSWORD_POLICY_IMPL_REQUIRE_LENGTH = new PasswordPolicyImpl (
127
137
PASSWORD_POLICY_RESPONSE_REQUIRE_LENGTH
128
138
) ;
139
+ const PASSWORD_POLICY_IMPL_REQUIRE_NUMERIC = new PasswordPolicyImpl (
140
+ PASSWORD_POLICY_RESPONSE_REQUIRE_NUMERIC
141
+ ) ;
129
142
130
143
it ( 'password that is too short is considered invalid' , async ( ) => {
131
144
const policy = PASSWORD_POLICY_IMPL_REQUIRE_ALL ;
@@ -294,6 +307,38 @@ describe('core/auth/password_policy_impl', () => {
294
307
expect ( status . containsNumericCharacter ) . to . be . undefined ;
295
308
expect ( status . containsNonAlphanumericCharacter ) . to . be . undefined ;
296
309
} ) ;
310
+
311
+ it ( 'should include statuses for requirements included in the policy when the password is an empty string' , async ( ) => {
312
+ let policy = PASSWORD_POLICY_IMPL_REQUIRE_ALL ;
313
+ let expectedValidationStatus : PasswordValidationStatus = {
314
+ isValid : false ,
315
+ meetsMinPasswordLength : false ,
316
+ meetsMaxPasswordLength : true ,
317
+ containsLowercaseLetter : false ,
318
+ containsUppercaseLetter : false ,
319
+ containsNumericCharacter : false ,
320
+ containsNonAlphanumericCharacter : false ,
321
+ passwordPolicy : policy
322
+ } ;
323
+
324
+ let status = policy . validatePassword ( TEST_EMPTY_PASSWORD ) ;
325
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
326
+
327
+ policy = PASSWORD_POLICY_IMPL_REQUIRE_NUMERIC ;
328
+ expectedValidationStatus = {
329
+ isValid : false ,
330
+ meetsMinPasswordLength : false ,
331
+ meetsMaxPasswordLength : true ,
332
+ containsNumericCharacter : false ,
333
+ passwordPolicy : policy
334
+ } ;
335
+
336
+ status = policy . validatePassword ( TEST_EMPTY_PASSWORD ) ;
337
+ expect ( status ) . to . eql ( expectedValidationStatus ) ;
338
+ expect ( status . containsLowercaseLetter ) . to . be . undefined ;
339
+ expect ( status . containsUppercaseLetter ) . to . be . undefined ;
340
+ expect ( status . containsNonAlphanumericCharacter ) . to . be . undefined ;
341
+ } ) ;
297
342
} ) ;
298
343
} ) ;
299
344
} ) ;
0 commit comments