@@ -147,14 +147,14 @@ describe("Password Policy: ", () => {
147
147
reconfigureServer ( {
148
148
appName : 'passwordPolicy' ,
149
149
passwordPolicy : {
150
- validatorPattern : "abc" // string is not a valid setting
150
+ validatorPattern : 1234 // number is not a valid setting
151
151
} ,
152
152
publicServerURL : "http://localhost:8378/1"
153
153
} ) . then ( ( ) => {
154
154
fail ( 'passwordPolicy.validatorPattern type test failed' ) ;
155
155
done ( ) ;
156
156
} ) . catch ( err => {
157
- expect ( err ) . toEqual ( 'passwordPolicy.validatorPattern must be a RegExp.' ) ;
157
+ expect ( err ) . toEqual ( 'passwordPolicy.validatorPattern must be a regex string or RegExp object .' ) ;
158
158
done ( ) ;
159
159
} ) ;
160
160
} ) ;
@@ -197,6 +197,28 @@ describe("Password Policy: ", () => {
197
197
} )
198
198
} ) ;
199
199
200
+ it ( 'signup should fail if password does not conform to the policy enforced using validatorPattern string' , ( done ) => {
201
+ const user = new Parse . User ( ) ;
202
+ reconfigureServer ( {
203
+ appName : 'passwordPolicy' ,
204
+ passwordPolicy : {
205
+ validatorPattern : "^.{8,}" // password should contain at least 8 char
206
+ } ,
207
+ publicServerURL : "http://localhost:8378/1"
208
+ } ) . then ( ( ) => {
209
+ user . setUsername ( "user1" ) ;
210
+ user . setPassword ( "less" ) ;
211
+ user . set ( 'email' , '[email protected] ' ) ;
212
+ user . signUp ( ) . then ( ( ) => {
213
+ fail ( 'Should have failed as password does not conform to the policy.' ) ;
214
+ done ( ) ;
215
+ } ) . catch ( ( error ) => {
216
+ expect ( error . code ) . toEqual ( 142 ) ;
217
+ done ( ) ;
218
+ } ) ;
219
+ } )
220
+ } ) ;
221
+
200
222
it ( 'signup should succeed if password conforms to the policy enforced using validatorPattern' , ( done ) => {
201
223
const user = new Parse . User ( ) ;
202
224
reconfigureServer ( {
@@ -231,6 +253,40 @@ describe("Password Policy: ", () => {
231
253
} )
232
254
} ) ;
233
255
256
+ it ( 'signup should succeed if password conforms to the policy enforced using validatorPattern string' , ( done ) => {
257
+ const user = new Parse . User ( ) ;
258
+ reconfigureServer ( {
259
+ appName : 'passwordPolicy' ,
260
+ passwordPolicy : {
261
+ validatorPattern : "[!@#$]+" // password should contain at least one special char
262
+ } ,
263
+ publicServerURL : "http://localhost:8378/1"
264
+ } ) . then ( ( ) => {
265
+ user . setUsername ( "user1" ) ;
266
+ user . setPassword ( "p@sswrod" ) ;
267
+ user . set ( 'email' , '[email protected] ' ) ;
268
+ user . signUp ( ) . then ( ( ) => {
269
+ Parse . User . logOut ( ) . then ( ( ) => {
270
+ Parse . User . logIn ( "user1" , "p@sswrod" ) . then ( function ( ) {
271
+ done ( ) ;
272
+ } ) . catch ( ( err ) => {
273
+ jfail ( err ) ;
274
+ fail ( "Should be able to login" ) ;
275
+ done ( ) ;
276
+ } ) ;
277
+ } ) . catch ( ( error ) => {
278
+ jfail ( error ) ;
279
+ fail ( 'logout should have succeeded' ) ;
280
+ done ( ) ;
281
+ } ) ;
282
+ } ) . catch ( ( error ) => {
283
+ jfail ( error ) ;
284
+ fail ( 'Signup should have succeeded as password conforms to the policy.' ) ;
285
+ done ( ) ;
286
+ } ) ;
287
+ } )
288
+ } ) ;
289
+
234
290
it ( 'signup should fail if password does not conform to the policy enforced using validatorCallback' , ( done ) => {
235
291
const user = new Parse . User ( ) ;
236
292
reconfigureServer ( {
@@ -409,12 +465,12 @@ describe("Password Policy: ", () => {
409
465
fail ( "should login with new password" ) ;
410
466
done ( ) ;
411
467
} ) ;
412
- } ) . catch ( ( error ) => {
468
+ } ) . catch ( ( error ) => {
413
469
jfail ( error ) ;
414
470
fail ( "Failed to POST request password reset" ) ;
415
471
done ( ) ;
416
472
} ) ;
417
- } ) . catch ( ( error ) => {
473
+ } ) . catch ( ( error ) => {
418
474
jfail ( error ) ;
419
475
fail ( "Failed to get the reset link" ) ;
420
476
done ( ) ;
@@ -839,7 +895,7 @@ describe("Password Policy: ", () => {
839
895
reconfigureServer ( {
840
896
appName : 'passwordPolicy' ,
841
897
passwordPolicy : {
842
- maxPasswordAge : 0.5 / ( 24 * 60 * 60 ) // 0.5 sec
898
+ maxPasswordAge : 0.5 / ( 24 * 60 * 60 ) // 0.5 sec
843
899
} ,
844
900
publicServerURL : "http://localhost:8378/1"
845
901
} ) . then ( ( ) => {
@@ -880,7 +936,7 @@ describe("Password Policy: ", () => {
880
936
reconfigureServer ( {
881
937
appName : 'passwordPolicy' ,
882
938
passwordPolicy : {
883
- maxPasswordAge : 0.5 / ( 24 * 60 * 60 ) // 0.5 sec
939
+ maxPasswordAge : 0.5 / ( 24 * 60 * 60 ) // 0.5 sec
884
940
} ,
885
941
publicServerURL : "http://localhost:8378/1"
886
942
} ) . then ( ( ) => {
@@ -979,7 +1035,7 @@ describe("Password Policy: ", () => {
979
1035
appName : 'passwordPolicy' ,
980
1036
emailAdapter : emailAdapter ,
981
1037
passwordPolicy : {
982
- maxPasswordAge : 0.5 / ( 24 * 60 * 60 ) // 0.5 sec
1038
+ maxPasswordAge : 0.5 / ( 24 * 60 * 60 ) // 0.5 sec
983
1039
} ,
984
1040
publicServerURL : "http://localhost:8378/1"
985
1041
} ) . then ( ( ) => {
0 commit comments