@@ -30,6 +30,11 @@ let session: TestSession;
3030
3131let mainUserId : string | undefined ;
3232
33+ const digitArray : string [ ] = '0123456789' . split ( '' ) ;
34+ const upperArray : string [ ] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . split ( '' ) ;
35+ const lowerArray : string [ ] = 'abcdefghijklmnopqrstuvwxyz' . split ( '' ) ;
36+ const symbolArray : string [ ] = '!@#$|%^&*()[]_-' . split ( '' ) ;
37+
3338describe ( 'verifies all commands run successfully ' , ( ) => {
3439 before ( async ( ) => {
3540 session = await TestSession . create ( {
@@ -133,19 +138,49 @@ describe('verifies all commands run successfully ', () => {
133138 } ) . jsonOutput ?. result ;
134139 // testing default length
135140 expect ( output ?. password ?. length ) . to . equal ( 20 ) ;
136- const complexity5Regex = new RegExp ( '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$|%^&*()[\\]_-])' ) ;
137141 // testing default complexity
138- expect ( complexity5Regex . test ( output ?. password ?? '' ) ) . to . be . true ;
142+ const passwordAsCharArray = ( output ?. password ?? '' ) . split ( '' ) ;
143+ expect ( passwordAsCharArray . some ( ( c ) => digitArray . includes ( c ) ) ) . to . equal (
144+ true ,
145+ 'complexity 5 passwords have digits'
146+ ) ;
147+ expect ( passwordAsCharArray . some ( ( c ) => upperArray . includes ( c ) ) ) . to . equal (
148+ true ,
149+ 'complexity 5 passwords have uppercase chars'
150+ ) ;
151+ expect ( passwordAsCharArray . some ( ( c ) => lowerArray . includes ( c ) ) ) . to . equal (
152+ true ,
153+ 'complexity 5 passwords have lowercase chars'
154+ ) ;
155+ expect ( passwordAsCharArray . some ( ( c ) => symbolArray . includes ( c ) ) ) . to . equal (
156+ true ,
157+ 'complexity 5 passwords have symbols'
158+ ) ;
139159 } ) ;
140160
141161 it ( 'generates new passwords for main user testing length 11 and complexity 5' , ( ) => {
142- const output = execCmd < { username : string ; password : string } > ( 'org:generate:password --json -l 11 -c 3 ' , {
162+ const output = execCmd < { username : string ; password : string } > ( 'org:generate:password --json -l 11 -c 5 ' , {
143163 ensureExitCode : 0 ,
144164 } ) . jsonOutput ?. result ;
145165 // Password length gets overridden to 20
146166 expect ( output ?. password . length ) . to . equal ( 20 ) ;
147- const complexity3Regex = new RegExp ( '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])' ) ;
148- expect ( complexity3Regex . test ( output ?. password ?? '' ) ) ;
167+ const passwordAsCharArray = ( output ?. password ?? '' ) . split ( '' ) ;
168+ expect ( passwordAsCharArray . some ( ( c ) => digitArray . includes ( c ) ) ) . to . equal (
169+ true ,
170+ 'complexity 5 passwords have digits'
171+ ) ;
172+ expect ( passwordAsCharArray . some ( ( c ) => upperArray . includes ( c ) ) ) . to . equal (
173+ true ,
174+ 'complexity 5 passwords have uppercase chars'
175+ ) ;
176+ expect ( passwordAsCharArray . some ( ( c ) => lowerArray . includes ( c ) ) ) . to . equal (
177+ true ,
178+ 'complexity 5 passwords have lowercase chars'
179+ ) ;
180+ expect ( passwordAsCharArray . some ( ( c ) => symbolArray . includes ( c ) ) ) . to . equal (
181+ true ,
182+ 'complexity 5 passwords have symbols'
183+ ) ;
149184 } ) ;
150185
151186 it ( 'generates new password for secondary user (onbehalfof)' , ( ) => {
@@ -160,9 +195,24 @@ describe('verifies all commands run successfully ', () => {
160195
161196 // Password length overridden to 20
162197 expect ( output ?. password . length ) . to . equal ( 20 ) ;
163- const complexity5Regex = new RegExp ( '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$|%^&*()[\\]_-])' ) ;
164198 // testing the default complexity
165- expect ( complexity5Regex . test ( output ?. password ?? '' ) ) ;
199+ const passwordAsCharArray = ( output ?. password ?? '' ) . split ( '' ) ;
200+ expect ( passwordAsCharArray . some ( ( c ) => digitArray . includes ( c ) ) ) . to . equal (
201+ true ,
202+ 'complexity 5 passwords have digits'
203+ ) ;
204+ expect ( passwordAsCharArray . some ( ( c ) => upperArray . includes ( c ) ) ) . to . equal (
205+ true ,
206+ 'complexity 5 passwords have uppercase chars'
207+ ) ;
208+ expect ( passwordAsCharArray . some ( ( c ) => lowerArray . includes ( c ) ) ) . to . equal (
209+ true ,
210+ 'complexity 5 passwords have lowercase chars'
211+ ) ;
212+ expect ( passwordAsCharArray . some ( ( c ) => symbolArray . includes ( c ) ) ) . to . equal (
213+ true ,
214+ 'complexity 5 passwords have symbols'
215+ ) ;
166216 } ) ;
167217
168218 it ( 'generates new password for secondary user (onbehalfof) with complexity 3' , ( ) => {
@@ -171,8 +221,23 @@ describe('verifies all commands run successfully ', () => {
171221 } ) . jsonOutput ?. result ;
172222 // testing default length
173223 expect ( output ?. password . length ) . to . equal ( 20 ) ;
174- const complexity3Regex = new RegExp ( '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])' ) ;
175- expect ( complexity3Regex . test ( output ?. password ?? '' ) ) ;
224+ const passwordAsCharArray = ( output ?. password ?? '' ) . split ( '' ) ;
225+ expect ( passwordAsCharArray . some ( ( c ) => digitArray . includes ( c ) ) ) . to . equal (
226+ true ,
227+ 'complexity 3 passwords have digits'
228+ ) ;
229+ expect ( passwordAsCharArray . some ( ( c ) => upperArray . includes ( c ) ) ) . to . equal (
230+ true ,
231+ 'complexity 3 passwords have uppercase chars'
232+ ) ;
233+ expect ( passwordAsCharArray . some ( ( c ) => lowerArray . includes ( c ) ) ) . to . equal (
234+ true ,
235+ 'complexity 3 passwords have lowercase chars'
236+ ) ;
237+ expect ( passwordAsCharArray . some ( ( c ) => symbolArray . includes ( c ) ) ) . to . equal (
238+ false ,
239+ 'complexity 3 passwords do not have symbols'
240+ ) ;
176241 } ) ;
177242
178243 it ( 'generates new password for secondary user (onbehalfof) with complexity 7 should thrown an error' , ( ) => {
0 commit comments