Skip to content

Commit

Permalink
reduce email validation strictness (#6013)
Browse files Browse the repository at this point in the history
* reduce email validation strictness

* add unit test for exotic email validation
  • Loading branch information
robindboer authored and ewdurbin committed Jun 14, 2019
1 parent bebd092 commit 74bfb6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/unit/accounts/test_forms.py
Expand Up @@ -308,6 +308,18 @@ def test_invalid_email_error(self):
assert not form.validate()
assert form.email.errors.pop() == "The email address isn't valid. Try again."

def test_exotic_email_success(self):
form = forms.RegistrationForm(
data={"email": "foo@n--tree.net"},
user_service=pretend.stub(
find_userid_by_email=pretend.call_recorder(lambda _: None)
),
breach_service=pretend.stub(check_password=lambda pw, tags=None: False),
)

form.validate()
assert len(form.email.errors) == 0

def test_email_exists_error(self):
form = forms.RegistrationForm(
data={"email": "foo@bar.com"},
Expand Down
4 changes: 2 additions & 2 deletions warehouse/accounts/forms.py
Expand Up @@ -147,8 +147,8 @@ class NewEmailMixin:
email = wtforms.fields.html5.EmailField(
validators=[
wtforms.validators.DataRequired(),
wtforms.validators.Email(
message=("The email address isn't valid. Try again.")
wtforms.validators.Regexp(
r".+@.+\..+", message=("The email address isn't valid. Try again.")
),
]
)
Expand Down

0 comments on commit 74bfb6b

Please sign in to comment.