Skip to content

Commit 9033b91

Browse files
committed
Add regression checks on email validator.
This is mostly to ensure that it rejects domains (other than "localhost") without dots in them.
1 parent d217015 commit 9033b91

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ exclude_dirs = ["src/django_registration/_backports.py"]
4646
skips = ["B101"]
4747

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

5151
[tool.check-manifest]
5252
ignore-bad-ideas = ["*.mo"]
@@ -114,6 +114,3 @@ disable = [
114114
"missing-module-docstring",
115115
"too-many-ancestors",
116116
]
117-
118-
[dependency-groups]
119-
tests = ["nox"]

src/django_registration/validators.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
r"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
4040
)
4141

42-
4342
# Below we construct a large but non-exhaustive list of names which users probably
4443
# should not be able to register with, due to various risks:
4544
#
@@ -67,7 +66,6 @@
6766
"wpad", # Proxy autodiscovery
6867
]
6968

70-
7169
PROTOCOL_HOSTNAMES = [
7270
# Common protocol hostnames.
7371
"ftp",
@@ -83,7 +81,6 @@
8381
"www",
8482
]
8583

86-
8784
CA_ADDRESSES = [
8885
# Email addresses known used by certificate authorities during
8986
# verification.
@@ -103,7 +100,6 @@
103100
"webmaster",
104101
]
105102

106-
107103
RFC_2142 = [
108104
# RFC-2142-defined names not already covered.
109105
"abuse",
@@ -114,7 +110,6 @@
114110
"support",
115111
]
116112

117-
118113
NOREPLY_ADDRESSES = [
119114
# Common no-reply email addresses.
120115
"mailer-daemon",
@@ -123,7 +118,6 @@
123118
"no-reply",
124119
]
125120

126-
127121
SENSITIVE_FILENAMES = [
128122
# Sensitive filenames.
129123
"clientaccesspolicy.xml", # Silverlight cross-domain policy file.
@@ -136,7 +130,6 @@
136130
".htpasswd",
137131
]
138132

139-
140133
OTHER_SENSITIVE_NAMES = [
141134
# Other names which could be problems depending on URL/subdomain
142135
# structure.
@@ -194,7 +187,6 @@
194187
"xrpc", # Used by Bluesky/AT protocol for domain verification.
195188
]
196189

197-
198190
DEFAULT_RESERVED_NAMES = (
199191
SPECIAL_HOSTNAMES
200192
+ PROTOCOL_HOSTNAMES

tests/test_forms.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,30 @@ def test_email_validation(self):
4949
5050
5151
52+
"test@localhost", # Django's default validator allows this one.
5253
):
53-
user_data = self.valid_data.copy()
54-
user_data["email"] = value
55-
form = forms.RegistrationForm(data=user_data)
56-
assert form.is_valid()
54+
with self.subTest(value=value):
55+
user_data = self.valid_data.copy()
56+
user_data["email"] = value
57+
form = forms.RegistrationForm(data=user_data)
58+
assert form.is_valid()
5759
for value in (
5860
"@@@example.com",
5961
"test:test@[email protected]",
6062
'test"test@example"[email protected]',
63+
"test@example",
64+
"test@1234",
6165
):
62-
user_data = self.valid_data.copy()
63-
user_data["email"] = value
64-
form = forms.RegistrationForm(data=user_data)
65-
assert not form.is_valid()
66-
assert form.has_error(user_model.get_email_field_name())
67-
assert (
68-
str(validators.HTML5EmailValidator.message)
69-
in form.errors[user_model.get_email_field_name()]
70-
)
66+
with self.subTest(value=value):
67+
user_data = self.valid_data.copy()
68+
user_data["email"] = value
69+
form = forms.RegistrationForm(data=user_data)
70+
assert not form.is_valid()
71+
assert form.has_error(user_model.get_email_field_name())
72+
assert (
73+
str(validators.HTML5EmailValidator.message)
74+
in form.errors[user_model.get_email_field_name()]
75+
)
7176

7277
def test_email_validated_once(self):
7378
"""

0 commit comments

Comments
 (0)