summaryrefslogtreecommitdiff
path: root/tests/mail
diff options
context:
space:
mode:
authorJoachim Jablon <joachim.jablon@people-doc.com>2019-04-29 18:48:20 +0200
committerCarlton Gibson <carlton@noumenal.es>2019-06-13 16:22:15 +0200
commit2628ea95151feb68f43a2a740e6fb0799a94b14b (patch)
tree57489f0baa31dec6567dcc593ed9d1d1b2e14762 /tests/mail
parent0c2ffdd526ff0f0015628821c77fbee15960eaef (diff)
downloaddjango-2628ea95151feb68f43a2a740e6fb0799a94b14b.tar.gz
Fixed #30512 -- Used email.headerregistry.parser for parsing emails in sanitize_address().
Diffstat (limited to 'tests/mail')
-rw-r--r--tests/mail/tests.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index 0a2db39d64..aed4b89928 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -748,10 +748,30 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
'utf-8',
'=?utf-8?q?to=40other=2Ecom?= <to@example.com>',
),
+ (
+ ('To Example', 'to@other.com@example.com'),
+ 'utf-8',
+ '=?utf-8?q?To_Example?= <"to@other.com"@example.com>',
+ ),
):
with self.subTest(email_address=email_address, encoding=encoding):
self.assertEqual(sanitize_address(email_address, encoding), expected_result)
+ def test_sanitize_address_invalid(self):
+ for email_address in (
+ # Invalid address with two @ signs.
+ 'to@other.com@example.com',
+ # Invalid address without the quotes.
+ 'to@other.com <to@example.com>',
+ # Other invalid addresses.
+ '@',
+ 'to@',
+ '@example.com',
+ ):
+ with self.subTest(email_address=email_address):
+ with self.assertRaises(ValueError):
+ sanitize_address(email_address, encoding='utf-8')
+
@requires_tz_support
class MailTimeZoneTests(SimpleTestCase):