Skip to content

Commit

Permalink
Add regression checks on email validator.
Browse files Browse the repository at this point in the history
This is mostly to ensure that it rejects domains (other than
"localhost") without dots in them.
  • Loading branch information
ubernostrum committed Nov 9, 2024
1 parent d217015 commit 9033b91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exclude_dirs = ["src/django_registration/_backports.py"]
skips = ["B101"]

[tool.black]
target-version = ["py38", "py39", "py310", "py311", "py312"]
target-version = ["py39", "py310", "py311", "py312", "py313"]

[tool.check-manifest]
ignore-bad-ideas = ["*.mo"]
Expand Down Expand Up @@ -114,6 +114,3 @@ disable = [
"missing-module-docstring",
"too-many-ancestors",
]

[dependency-groups]
tests = ["nox"]
8 changes: 0 additions & 8 deletions src/django_registration/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
r"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
)


# Below we construct a large but non-exhaustive list of names which users probably
# should not be able to register with, due to various risks:
#
Expand Down Expand Up @@ -67,7 +66,6 @@
"wpad", # Proxy autodiscovery
]


PROTOCOL_HOSTNAMES = [
# Common protocol hostnames.
"ftp",
Expand All @@ -83,7 +81,6 @@
"www",
]


CA_ADDRESSES = [
# Email addresses known used by certificate authorities during
# verification.
Expand All @@ -103,7 +100,6 @@
"webmaster",
]


RFC_2142 = [
# RFC-2142-defined names not already covered.
"abuse",
Expand All @@ -114,7 +110,6 @@
"support",
]


NOREPLY_ADDRESSES = [
# Common no-reply email addresses.
"mailer-daemon",
Expand All @@ -123,7 +118,6 @@
"no-reply",
]


SENSITIVE_FILENAMES = [
# Sensitive filenames.
"clientaccesspolicy.xml", # Silverlight cross-domain policy file.
Expand All @@ -136,7 +130,6 @@
".htpasswd",
]


OTHER_SENSITIVE_NAMES = [
# Other names which could be problems depending on URL/subdomain
# structure.
Expand Down Expand Up @@ -194,7 +187,6 @@
"xrpc", # Used by Bluesky/AT protocol for domain verification.
]


DEFAULT_RESERVED_NAMES = (
SPECIAL_HOSTNAMES
+ PROTOCOL_HOSTNAMES
Expand Down
31 changes: 18 additions & 13 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,30 @@ def test_email_validation(self):
"[email protected]",
"[email protected]",
"[email protected]",
"test@localhost", # Django's default validator allows this one.
):
user_data = self.valid_data.copy()
user_data["email"] = value
form = forms.RegistrationForm(data=user_data)
assert form.is_valid()
with self.subTest(value=value):
user_data = self.valid_data.copy()
user_data["email"] = value
form = forms.RegistrationForm(data=user_data)
assert form.is_valid()
for value in (
"@@@example.com",
"test:test@[email protected]",
'test"test@example"[email protected]',
"test@example",
"test@1234",
):
user_data = self.valid_data.copy()
user_data["email"] = value
form = forms.RegistrationForm(data=user_data)
assert not form.is_valid()
assert form.has_error(user_model.get_email_field_name())
assert (
str(validators.HTML5EmailValidator.message)
in form.errors[user_model.get_email_field_name()]
)
with self.subTest(value=value):
user_data = self.valid_data.copy()
user_data["email"] = value
form = forms.RegistrationForm(data=user_data)
assert not form.is_valid()
assert form.has_error(user_model.get_email_field_name())
assert (
str(validators.HTML5EmailValidator.message)
in form.errors[user_model.get_email_field_name()]
)

def test_email_validated_once(self):
"""
Expand Down

0 comments on commit 9033b91

Please sign in to comment.