Skip to content

Commit

Permalink
Fixes a bug when generating a password with min_length eq 1 (faker-ru…
Browse files Browse the repository at this point in the history
…by#2138)

* Fixes a bug when generating passwords with min_length eq 1

* swap if block for brackets

* Update internet.rb

Oh... that ticks off Rubocop. Nvm. Reverting back to the original version

Co-authored-by: Stephen A. Wilson <stephen-356@hotmail.com>
  • Loading branch information
2 people authored and droznyk committed Oct 23, 2020
1 parent 56dce02 commit 47bc44e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def password(legacy_min_length = NOT_GIVEN, legacy_max_length = NOT_GIVEN, legac
keywords << :special_characters if legacy_special_characters != NOT_GIVEN
end

min_alpha = mix_case ? 2 : 0
min_alpha = mix_case && min_length > 1 ? 2 : 0
temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
diff_length = max_length - min_length

Expand Down
14 changes: 14 additions & 0 deletions test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ def test_password_with_mixed_case
assert downcase_count >= 1
end

def test_password_with_min_length_eq_1
min_length = 1
password = @tester.password(min_length: min_length)
assert password.match(/\w+/)
end

def test_password_with_min_length_and_max_length
min_length = 2
max_length = 5
password = @tester.password(min_length: min_length, max_length: max_length)
assert password.match(/\w+/)
assert (min_length..max_length).include?(password.size), 'Password size is incorrect'
end

def test_password_without_mixed_case
assert @tester.password(min_length: 8, max_length: 12, mix_case: false).match(/[^A-Z]+/)
end
Expand Down

0 comments on commit 47bc44e

Please sign in to comment.