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

Explicit support for special-use domains. #3567

Closed
jenstroeger opened this issue Feb 4, 2023 · 1 comment · Fixed by #3572
Closed

Explicit support for special-use domains. #3567

jenstroeger opened this issue Feb 4, 2023 · 1 comment · Fixed by #3572
Labels
enhancement it's not broken, but we want it to be better

Comments

@jenstroeger
Copy link
Contributor

Hypothesis’ emails() strategy generated an email address 0@a.arpa which was rejected by the email-validator package:

>>> import email_validator
>>> email_validator.validate_email('0@a.arpa')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../.venv/lib/python3.9/site-packages/email_validator/__init__.py", line 319, in validate_email
    domain_part_info = validate_email_domain_part(parts[1], test_environment=test_environment, globally_deliverable=globally_deliverable)
  File "/.../.venv/lib/python3.9/site-packages/email_validator/__init__.py", line 580, in validate_email_domain_part
    raise EmailSyntaxError("The domain name %s is a special-use or reserved name that cannot be used with email." % domain_i18n)
email_validator.EmailSyntaxError: The domain name a.arpa is a special-use or reserved name that cannot be used with email.

The email-validator package defines “special-use or reserved names” here.

Now, Hypothesis builds email addresses using the internal domains() strategy:

return builds("{}@{}".format, local_part, domains()).filter(
lambda addr: len(addr) <= 254
)

which doesn’t have explicit support to filter out or use these special-use domain names.

I think adding an optional kwarg allow_special_use=True to the emails() strategy which then propagates to the DomainNameStrategy class would be useful. Happy to supply a PR?

@Zac-HD Zac-HD added the enhancement it's not broken, but we want it to be better label Feb 4, 2023
@Zac-HD
Copy link
Member

Zac-HD commented Feb 4, 2023

A PR would be great, thanks! Let's add allow_special_use: bool = True to provisional.domains(), and *, domains: st.SearchStrategy[str] = domains() to st.emails()1 - that way people can also pass e.g. domains=st.just("employer.com"), so it's a more general upgrade 🙂

Footnotes

  1. My reading of RFC-5322 is that special domains are fine according to the standard so IMO Hypothesis should include them by default, and the email-validator docs describes how to enable them in testing, noting that they're off by default as an anti-footgun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement it's not broken, but we want it to be better
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants