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

add digits to password #2705

Merged
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
4 changes: 4 additions & 0 deletions lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def password(min_length: 8, max_length: 16, mix_case: true, special_characters:
password << lower_chars[rand(lower_chars.count - 1)]
character_bag += lower_chars

digits = ('1'..'9').to_a
password << digits[rand(digits.count - 1)]
character_bag += digits

if character_types.include?(:mix_case)
upper_chars = ('A'..'Z').to_a
password << upper_chars[rand(upper_chars.count - 1)]
Expand Down
7 changes: 6 additions & 1 deletion test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ def test_username_with_range_and_separators
end

def test_password
assert_match(/\w{3}/, @tester.password)
password = @tester.password

assert_match(/\w{3}/, password)
assert_match(/\d/, password)
assert_match(/[a-z]/, password)
assert_match(/[A-Z]/, password)
Comment on lines +124 to +125
Copy link
Contributor

@MicBruz MicBruz Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that might be already covered by the test test_password_with_mixed_case in the line 153 (148 on the main).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to have it here as well because this is testing the case of when there is no mix case argument.

end

def test_password_with_integer_arg
Expand Down