Code

Ticket #7773: mail-regression-test.diff

File mail-regression-test.diff, 1.3 KB (added by serialx, 6 years ago)

A yet simple mail regression test to confirm correct EmailMessage operation plus a test for header injection.

Line 
1Index: django_trunk/tests/regressiontests/mail/tests.py
2===================================================================
3--- /dev/null   1970-01-01 00:00:00.000000000 +0000
4+++ django_trunk/tests/regressiontests/mail/tests.py    2008-07-16 10:40:12.221037224 +0900
5@@ -0,0 +1,28 @@
6+# coding: utf-8
7+r"""
8+# Tests for the django.core.mail.
9+
10+>>> from django.core.mail import EmailMessage
11+
12+# Test normal ascii character case:
13+
14+>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'])
15+>>> message = email.message()
16+>>> str(message['Subject'])
17+'Subject'
18+>>> str(message.get_payload())
19+'Content'
20+>>> str(message['From'])
21+'from@example.com'
22+>>> str(message['To'])
23+'to@example.com'
24+
25+# Test for header injection
26+
27+>>> email = EmailMessage('Subject\nInjection Test', 'Content', 'from@example.com', ['to@example.com'])
28+>>> message = email.message()
29+Traceback (most recent call last):
30+    ...
31+BadHeaderError: Header values can't contain newlines (got 'Subject\nInjection Test' for header 'Subject')
32+
33+"""
34Index: django_trunk/tests/regressiontests/mail/__init__.py
35===================================================================
36--- /dev/null   1970-01-01 00:00:00.000000000 +0000
37+++ django_trunk/tests/regressiontests/mail/__init__.py 2008-07-16 10:41:11.985037906 +0900
38@@ -0,0 +1,2 @@
39+
40+