summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJulien Phalip <jphalip@gmail.com>2012-02-11 09:31:18 +0000
committerJulien Phalip <jphalip@gmail.com>2012-02-11 09:31:18 +0000
commit995f7a16a8bf539caf076a7744441a383e9a38b2 (patch)
tree8181ab890022da6db89795cd6d22ebd2b5813801 /tests
parenta77679dfaa963361b6daad6de0d7de1b53d4f104 (diff)
Fixed #17281 -- Prevented `AdminErrorHandler` from silently failing if the log message contains newlines. Thanks to Russell Keith-Magee for the report and to Bartolome Sanchez Salado and Marcin Wróbel for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17501 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/logging_tests/tests.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py
index a2c178c3b7..8eba44bf77 100644
--- a/tests/regressiontests/logging_tests/tests.py
+++ b/tests/regressiontests/logging_tests/tests.py
@@ -160,3 +160,50 @@ class AdminEmailHandlerTest(TestCase):
# Restore original filters
admin_email_handler.filters = orig_filters
+
+ @override_settings(
+ ADMINS=(('admin', 'admin@example.com'),),
+ EMAIL_SUBJECT_PREFIX='',
+ DEBUG=False,
+ )
+ def test_subject_accepts_newlines(self):
+ """
+ Ensure that newlines in email reports' subjects are escaped to avoid
+ AdminErrorHandler to fail.
+ Refs #17281.
+ """
+ message = u'Message \r\n with newlines'
+ expected_subject = u'ERROR: Message \\r\\n with newlines'
+
+ self.assertEqual(len(mail.outbox), 0)
+
+ logger = getLogger('django.request')
+ logger.error(message)
+
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertFalse('\n' in mail.outbox[0].subject)
+ self.assertFalse('\r' in mail.outbox[0].subject)
+ self.assertEqual(mail.outbox[0].subject, expected_subject)
+
+ @override_settings(
+ ADMINS=(('admin', 'admin@example.com'),),
+ EMAIL_SUBJECT_PREFIX='',
+ DEBUG=False,
+ )
+ def test_truncate_subject(self):
+ """
+ RFC 2822's hard limit is 998 characters per line.
+ So, minus "Subject: ", the actual subject must be no longer than 989
+ characters.
+ Refs #17281.
+ """
+ message = 'a' * 1000
+ expected_subject = 'ERROR: aa' + 'a' * 980
+
+ self.assertEqual(len(mail.outbox), 0)
+
+ logger = getLogger('django.request')
+ logger.error(message)
+
+ self.assertEqual(len(mail.outbox), 1)
+ self.assertEqual(mail.outbox[0].subject, expected_subject)