-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Ensure Faker::Internet.password
method behavior is consistent with length parameters
#3034
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
base: main
Are you sure you want to change the base?
Conversation
…ngth parameters This change allows to make sure that the password respects the length specified in the parameters (i.e., if both `min_length` and `max_length` are set to 1, then the password should be 1 character long)
Hi @francktrouillez I wanted to say this is in my todo list and should give a review by next week. |
hi @francktrouillez thank you for your patience. I think what we need to do instead is improve the docs. This is expected behaviour, it's just not clear because the examples do not showcase this specific scenario where the values you set are not enough to work with the extra configurations. When setting Faker::Internet.password(min_length: 1, max_length: 2, mix_case: false, special_characters: true) => "3y" # special_characters require max_length: 3,
Faker::Internet.password(min_length: 2, max_length: 2, mix_case: true, special_characters: false) => "1iK"
Faker::Internet.password(min_length: 2, max_length: 3, mix_case: true, special_characters: false)
=> "jB0"
Faker::Internet.password(min_length: 2, max_length: 3, mix_case: false, special_characters: true) => "%i8" When setting https://github.com/faker-ruby/faker/blob/main/lib/faker/default/internet.rb#L135 The docs do mention setting these extra configuration will add at least one more character: https://github.com/faker-ruby/faker/blob/main/lib/faker/default/internet.rb#L107-110 Would you be up for improving the docs to have more examples of these scenarios? We can be more specific on the minimum requirements for these extra configurations to work (i.e, a minimum of 3 max_length to be able to work). If you're up for it, I'd appreciate it. Otherwise, let me know and I can do it. I'm thinking of more examples to focus the combination of arguments: Faker::Internet.password(min_length: 3, max_length: 4, mix_case: true, special_characters: true) => "B4z!"
Faker::Internet.password(min_length: 3, max_length: 3, mix_case: true, special_characters: true) => "!sQ2"
Faker::Internet.password(min_length: 3, max_length: 3, mix_case: false, special_characters: true) => "3^w" Thank you. |
Thanks for the answer @stefannibrasil! No worries for the time, nothing critical here.
I personally feel that besides the documentation, the behavior of the method itself isn't expected. Faker::Internet.password(min_length: 2, max_length: 2) # => "Pa1" => 3 characters while I was expecting 2 I personally would never expect this method call to generate a string of length 3. I could check the documentation afterwards, but even if it said there, I would be confused as to what's the point of having a If you agree with the above, I believe there are two ways to fix this:
I'm happy to implement changes for either of these solutions, but I'm personally not a huge fan of only changing the documentation, as it highlights a mismatch between the method's behavior and the documentation. What do you think? |
Motivation / Background
When using
Faker::Interner.password
, themin_length
andmax_length
options are not always respected.For instance, running the following snippet will give password out of the desired length range:
This can lead to unexpected behavior when using the
Faker::Internet.password
method.Changes proposed in this pull request
This PR fixes the issue by ensuring that the password generated respects the
min_length
andmax_length
options.mix_case
option from theFaker::Internet.password
method, which is to either force-include an uppercase letter AND a lowercase letter if set totrue
, or to only use lowercase letters if set tofalse
(without enforcing the presence of a letter).digits
inFaker::Internet.password
method #3033Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
If you're proposing a new generator or locale:
[ ] Double-check the existing generators documentation to make sure the new generator you want to add doesn't already exist.[ ] You've reviewed and followed the Contributing guidelines.Closing notes
I'm open to any feedback or suggestions on how to improve this PR if this solution makes sense.
Thanks!