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

Generate safe email and domain_name by default (RFC 2606) #2733

Merged

Conversation

stefannibrasil
Copy link
Contributor

@stefannibrasil stefannibrasil commented Mar 21, 2023

Summary

Fixes #2431

faker-ruby is transitioning to no longer generating potentially real email and url addresses.

The migration plan is:

First step:

  • change email and domain_name to be RFC 2606 compliant. Both now generate safe values by default using the Reserved Top Level DNS Names: example and test. To maintain backwards compatibility and give users the option to use non-safe domains at their own risk, custom domains are allowed.
  • add deprecation message for free_email and safe_email to use email instead.

Second step (after October 2023):

  • remove deprecated generators and locales.

To give users time, once the first step is released, users will have until October 2023 to make the necessary changes.

Other Information

  • Disabling # rubocop:disable Style/IfUnlessModifier because inline conditionals are hard to read and therefore to refactor. With the explicit conditionals, it's easier to extract them to a method, etc.
  • Unfortunately, the locale tests are only asserting that the results are strings. There is an opportunity to improve them. Help is welcomed!

faker-ruby is transitioning to no longer generating potentially
real email and url addresses.

The migration plan is:
First step:
- change `email` and `domain_name` to be RFC 2606 compliant.
 Both now generate safe values by default using the Reserved Top Level
 DNS Names: `example` and `test`.
  To maintain backwards compatibility and give users the option to
  use non-safe domains at their own risk, custom domains are allowed.
  Documentation and tests have been updated.
- add deprecation message for `free_email` and `safe_email` to use
`email` instead.

Second step:
- remove deprecated generators and locales.

Co-authored-by: Thiago Araujo <thd.araujo@gmail.com>
Comment on lines +70 to +72
# Keyword arguments: safe ('example' and 'test' suffixes)
Faker::Internet.domain_suffix #=> "info"
Faker::Internet.domain_suffix(safe: true) #=> "example"
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (minor): since we're making breaking changes here, it may be good to also rename this to #tld

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you clarify more why you think this is a breaking change? If the argument is not provided, the generator still works 🤔

I like the idea of using tld. Maybe we can introduce an alias in another PR? This one is already getting too big 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me know what you think and I will merge this once I hear back from you :) Thanks for the review @Zeragamba

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about this PR being a breaking change or not. The way this PR handles the problem is by maintaining backwards compatibility for those who want to use unsafe domains. What is going to change is the behavior: the results will be safe by default. It doesn't seem like a breaking change to me. What am I missing?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you, Stefanni.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vbrazo did you mean to approve this PR? Just checking because I see your comments but not an approval 🍡 Thank you!

@@ -1,6 +1,7 @@
# frozen_string_literal: true

module Faker
# rubocop:disable Style/IfUnlessModifier
Copy link
Contributor

Choose a reason for hiding this comment

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

question: should this also be disabled in the project's rubocop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind disabling it for the project! I wasn't sure this was what we wanted so I only added it here.

I will push a commit once I figure out how to fix my ssh keys to be able to push again ><

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it in 4a46759

Faker::Internet.email(name: 'Nancy') #=> "nancy@terry.test"
Faker::Internet.email(name: 'Janelle Santiago', separators: ['+']) #=> "janelle+santiago@becker.example"
Faker::Internet.email(domain: 'gmail.com') #=> "foo@gmail.com"
Faker::Internet.email(name: 'sam smith', separators: ['-'], domain: 'test') #=> "sam-smith@test.test"
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding more examples and completing the Internet doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯

@thdaraujo thdaraujo merged commit 82d7a86 into faker-ruby:main Apr 5, 2023
@thdaraujo thdaraujo deleted the safe-email-and-domains-by-default branch April 5, 2023 01:46
ariccio added a commit to ariccio/COVID-CO2-tracker that referenced this pull request Oct 17, 2023
Faker now does the right thing by default, awesome!
faker-ruby/faker#2733
aaronskiba added a commit to DMPRoadmap/roadmap that referenced this pull request Jan 31, 2024
Prior to this commit, the following deprecation warning was appearing in the terminal:
NOTE: Faker::Internet.safe_email is deprecated; use email instead. It will be removed on or after 2023-10.

More here: faker-ruby/faker#2733
aaronskiba added a commit to DMPRoadmap/roadmap that referenced this pull request Feb 1, 2024
Prior to this commit, the following deprecation warning was appearing in the terminal:
NOTE: Faker::Internet.safe_email is deprecated; use email instead. It will be removed on or after 2023-10.

More here: faker-ruby/faker#2733
toshimaru added a commit to toshimaru/RailsTwitterClone that referenced this pull request May 15, 2024
toshimaru added a commit to toshimaru/RailsTwitterClone that referenced this pull request May 15, 2024
* build(deps-dev): Bump faker from 3.2.3 to 3.3.1

Bumps [faker](https://github.com/faker-ruby/faker) from 3.2.3 to 3.3.1.
- [Release notes](https://github.com/faker-ruby/faker/releases)
- [Changelog](https://github.com/faker-ruby/faker/blob/main/CHANGELOG.md)
- [Commits](faker-ruby/faker@v3.2.3...v3.3.1)

---
updated-dependencies:
- dependency-name: faker
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: Use `Faker::Internet.email` instead of `free_email`

## Related PR

- faker-ruby/faker#2733
- faker-ruby/faker#2841

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Toshimaru <me@toshimaru.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faker is unsafe to use in automated tests - real urls and email addresses are generated
4 participants