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

Faker::Internet.password method doesn't add numbers anymore #2704

Closed
isabel-anastasiadis-boost opened this issue Feb 9, 2023 · 3 comments
Closed

Comments

@isabel-anastasiadis-boost

Describe the bug

The docs and comments suggest numbers are included, but looking at the source code it only includes lowercase, uppercase, and symbols.

To Reproduce

Describe a way to reproduce your bug. To get the Faker version, run Faker::VERSION.

Use the reproduction script below to reproduce the issue:

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main'
  gem "minitest"
end

require "minitest/autorun"

class BugTest < Minitest::Test
  def test_faker

    result = Faker::Internet.password(min_length: 8, mix_case: true)

    assert result.match(/[0-9]+/)  # returns nil if no matches
  end
end

Expected behavior

I would expect that you are guaranteed to have a number for all permutations, or that there is an extra parameter to ensure numbers are included

@stefannibrasil
Copy link
Contributor

hi @isabel-anastasiadis-boost thanks for reporting this bug! You're right, the generator should include numbers.

Is this happening only if specifying min_length: 8, mix_case: true arguments, or other specific arguments, or even without any arguments?

@isabel-anastasiadis-boost
Copy link
Author

You're welcome! Oh yes, sorry, it happens without any arguments too. Those were just the arguments I was trying to use.

@stefannibrasil
Copy link
Contributor

One way to help with this generator is to improve the tests. They don't seem to be exercising the code as I was expecting.

For example, if you simply change the expectation here:

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

to expect any number, the test pass.

Ideally, beyond reinforcing the expected behavior by preventing bugs to be added, and documenting the code, the tests give us clarity about:

  • how the generator behaves with no arguments, with arguments
  • edge cases

I have some ideas into how improve them, which would basically means not relying only regexes to test it. For example, I changed some tests here #2733

I'm going to close this for now and help with improving the tests are welcomed! Thanks for reporting the bug and for the help

cc @wyattroyc @MicBruz @DeepakRaj228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants