Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug when generating a password with min_length eq 1 #2138

Merged
merged 3 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Zeragamba marked this conversation as resolved.
Show resolved Hide resolved
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