@@ -232,8 +232,8 @@ def test_password_with_min_length_eq_1_without_mix_case
232
232
end
233
233
234
234
def test_password_with_min_length_and_max_length
235
- min_length = 2
236
- max_length = 5
235
+ min_length = 3
236
+ max_length = 6
237
237
password = @tester . password ( min_length : min_length , max_length : max_length )
238
238
239
239
assert_match ( /\w +/ , password )
@@ -265,34 +265,39 @@ def test_password_without_special_chars
265
265
assert_match ( /[^!@#$%\^ &*]+/ , @tester . password ( min_length : 8 , max_length : 12 , mix_case : true ) )
266
266
end
267
267
268
- def test_password_with_special_chars_and_mixed_case
268
+ def test_password_with_digits
269
+ assert_match ( /[0-9]+/ , @tester . password ( min_length : 8 , max_length : 12 , digits : true ) )
270
+ end
271
+
272
+ def test_password_without_digits
273
+ assert_match ( /^[^0-9]+$/ , @tester . password ( min_length : 8 , max_length : 12 , digits : false ) )
274
+ end
275
+
276
+ def test_password_with_special_chars_and_mixed_case_and_digits
269
277
32 . times do
270
- password = @tester . password ( min_length : 4 , max_length : 6 , mix_case : true , special_characters : true )
278
+ password = @tester . password ( min_length : 4 , max_length : 6 , mix_case : true , special_characters : true , digits : true )
271
279
272
- assert_match ( /[!@#$%\^ &*]+/ , password )
273
- assert_match ( /[A-z]+/ , password )
280
+ assert_match ( /^[A-Za-z0-9!@#$%\^ &*]+$/ , password )
274
281
end
275
282
end
276
283
277
- def test_deterministic_password_with_special_chars_and_mixed_case
278
- deterministically_verify -> { @tester . password ( min_length : 4 , max_length : 6 , mix_case : true , special_characters : true ) } , depth : 4 do |password |
279
- assert_match ( /[!@#$%\^ &*]+/ , password )
280
- assert_match ( /[A-z]+/ , password )
284
+ def test_deterministic_password_with_special_chars_and_mixed_case_and_digits
285
+ deterministically_verify -> { @tester . password ( min_length : 4 , max_length : 6 , mix_case : true , special_characters : true , digits : true ) } , depth : 4 do |password |
286
+ assert_match ( /^[A-Za-z0-9!@#$%\^ &*]+$/ , password )
281
287
end
282
288
end
283
289
284
- def test_password_with_special_chars_and_mixed_case_on_3chars_password
290
+ def test_password_with_special_chars_and_mixed_case_and_digits_on_4chars_password
285
291
16 . times do
286
- password = @tester . password ( min_length : 3 , max_length : 6 , mix_case : true , special_characters : true )
292
+ password = @tester . password ( min_length : 4 , max_length : 6 , mix_case : true , special_characters : true , digits : true )
287
293
288
- assert_match ( /[!@#$%\^ &*]+/ , password )
289
- assert_match ( /[A-z]+/ , password )
294
+ assert_match ( /^[A-Za-z0-9!@#$%\^ &*]+$/ , password )
290
295
end
291
296
end
292
297
293
- def test_password_with_invalid_min_length_for_mix_case_and_special_characters
294
- assert_raise_message 'min_length should be at least 3 to enable mix_case, special_characters configuration' do
295
- @tester . password ( min_length : 1 , mix_case : true , special_characters : true )
298
+ def test_password_with_invalid_min_length_for_mix_case_and_special_characters_and_digits
299
+ assert_raise_message 'min_length should be at least 4 to enable mix_case, special_characters, digits configuration' do
300
+ @tester . password ( min_length : 1 , mix_case : true , special_characters : true , digits : true )
296
301
end
297
302
end
298
303
@@ -306,35 +311,52 @@ def test_password_with_invalid_min_max_length
306
311
307
312
def test_password_with_invalid_min_length_for_special_characters_only
308
313
error = assert_raises ( ArgumentError ) do
309
- @tester . password ( min_length : 0 , mix_case : false , special_characters : true )
314
+ @tester . password ( min_length : 0 , mix_case : false , special_characters : true , digits : false )
310
315
end
311
316
312
317
assert_equal 'min_length and max_length must be greater than or equal to one' , error . message
313
318
end
314
319
315
320
def test_password_with_invalid_min_length_for_mix_case_only
316
321
error = assert_raises ( ArgumentError ) do
317
- @tester . password ( min_length : 1 , mix_case : true )
322
+ @tester . password ( min_length : 1 , mix_case : true , special_characters : false , digits : false )
318
323
end
319
324
320
325
assert_equal 'min_length should be at least 2 to enable mix_case configuration' , error . message
321
326
end
322
327
328
+ def test_password_with_invalid_min_length_for_digits_only
329
+ error = assert_raises ( ArgumentError ) do
330
+ @tester . password ( min_length : 0 , mix_case : false , special_characters : false , digits : true )
331
+ end
332
+
333
+ assert_equal 'min_length and max_length must be greater than or equal to one' , error . message
334
+ end
335
+
323
336
def test_password_with_compatible_min_length_and_requirements
324
337
assert_nothing_raised do
325
- [ false , true ] . each do |value |
326
- min_length = value ? 2 : 1
327
- @tester . password ( min_length : min_length , mix_case : value , special_characters : !value )
338
+ [ false , true ] . each do |mix_case |
339
+ [ false , true ] . each do |special_characters |
340
+ [ false , true ] . each do |digits |
341
+ min_length = [ [ mix_case ? 2 : 0 , special_characters ? 1 : 0 , digits ? 1 : 0 ] . sum , 1 ] . max
342
+
343
+ @tester . password ( min_length : min_length , mix_case : mix_case , special_characters : special_characters , digits : digits )
344
+ end
345
+ end
328
346
end
329
347
end
330
348
end
331
349
332
350
def test_deterministic_password_with_compatible_min_length_and_requirements
333
- [ false , true ] . each do |value |
334
- min_length = value ? 2 : 1
335
-
336
- deterministically_verify -> { @tester . password ( min_length : min_length , mix_case : value , special_characters : !value ) } , depth : 4 do |password |
337
- assert_nothing_raised { password }
351
+ [ false , true ] . each do |mix_case |
352
+ [ false , true ] . each do |special_characters |
353
+ [ false , true ] . each do |digits |
354
+ min_length = [ [ mix_case ? 2 : 0 , special_characters ? 1 : 0 , digits ? 1 : 0 ] . sum , 1 ] . max
355
+
356
+ deterministically_verify -> { @tester . password ( min_length : min_length , mix_case : mix_case , special_characters : special_characters , digits : digits ) } , depth : 4 do |password |
357
+ assert_nothing_raised { password }
358
+ end
359
+ end
338
360
end
339
361
end
340
362
end
0 commit comments