From f405954ea24dcce7ed01e488a0778be7e441b757 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 16 Jul 2020 10:03:59 +0200 Subject: [PATCH] Refs #31784 -- Added test for preventing header injection in display name of email addresses. --- tests/mail/tests.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 1f8c6b12bf..72c22ad341 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -188,14 +188,22 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): EmailMessage(reply_to='reply_to@example.com') def test_header_injection(self): + msg = "Header values can't contain newlines " email = EmailMessage('Subject\nInjection Test', 'Content', 'from@example.com', ['to@example.com']) - with self.assertRaises(BadHeaderError): + with self.assertRaisesMessage(BadHeaderError, msg): email.message() email = EmailMessage( gettext_lazy('Subject\nInjection Test'), 'Content', 'from@example.com', ['to@example.com'] ) - with self.assertRaises(BadHeaderError): + with self.assertRaisesMessage(BadHeaderError, msg): email.message() + with self.assertRaisesMessage(BadHeaderError, msg): + EmailMessage( + 'Subject', + 'Content', + 'from@example.com', + ['Name\nInjection test '], + ).message() def test_space_continuation(self): """