diff options
| author | Mark Sapiro | 2016-12-30 11:37:49 -0800 |
|---|---|---|
| committer | Mark Sapiro | 2016-12-30 11:37:49 -0800 |
| commit | af4f25a593c006c27321d9618c2ae2658777446b (patch) | |
| tree | 1bfcd7f07d2ddc6f93faec4bab96e428b563920b /src/mailman/handlers | |
| parent | eba4d0767aa141dc631e433ac01a86302da233b5 (diff) | |
| download | mailman-af4f25a593c006c27321d9618c2ae2658777446b.tar.gz mailman-af4f25a593c006c27321d9618c2ae2658777446b.tar.zst mailman-af4f25a593c006c27321d9618c2ae2658777446b.zip | |
Diffstat (limited to 'src/mailman/handlers')
| -rw-r--r-- | src/mailman/handlers/tests/test_dmarc.py | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/mailman/handlers/tests/test_dmarc.py b/src/mailman/handlers/tests/test_dmarc.py index a90fb3618..3d60b6d02 100644 --- a/src/mailman/handlers/tests/test_dmarc.py +++ b/src/mailman/handlers/tests/test_dmarc.py @@ -20,8 +20,10 @@ import unittest from mailman.app.lifecycle import create_list +from mailman.app.membership import add_member from mailman.handlers import dmarc from mailman.interfaces.mailinglist import DMARCMitigateAction, ReplyToMunging +from mailman.interfaces.subscriptions import RequestRecord from mailman.testing.helpers import specialized_message_from_string as mfs from mailman.testing.layers import ConfigLayer @@ -77,6 +79,32 @@ Content-Transfer-Encoding: 7bit dmarc.process(self._mlist, msg, msgdata) self.assertMultiLineEqual(msg.as_string(), self._text) + def test_no_mitigation_no_change_1(self): + msg = mfs(self._text) + self._mlist.dmarc_mitigate_unconditionally = True + dmarc.process(self._mlist, msg, {}) + self.assertMultiLineEqual(msg.as_string(), self._text) + + def test_no_mitigation_no_change_2(self): + msg = mfs(self._text) + msgdata = {'dmarc': True} + dmarc.process(self._mlist, msg, msgdata) + self.assertMultiLineEqual(msg.as_string(), self._text) + + def test_action_reject_mitigate_unconditionally(self): + msg = mfs(self._text) + self._mlist.dmarc_mitigate_unconditionally = True + self._mlist.dmarc_mitigate_action = DMARCMitigateAction.reject + dmarc.process(self._mlist, msg, {}) + self.assertMultiLineEqual(msg.as_string(), self._text) + + def test_action_discard_mitigate_unconditionally(self): + msg = mfs(self._text) + self._mlist.dmarc_mitigate_unconditionally = True + self._mlist.dmarc_mitigate_action = DMARCMitigateAction.discard + dmarc.process(self._mlist, msg, {}) + self.assertMultiLineEqual(msg.as_string(), self._text) + def test_action_munge_from(self): self._mlist.dmarc_mitigate_action = DMARCMitigateAction.munge_from msgdata = {'dmarc': True} @@ -107,6 +135,106 @@ Content-Transfer-Encoding: 7bit --=====abc==-- """) + def test_action_munge_from_no_from(self): + self._mlist.dmarc_mitigate_action = DMARCMitigateAction.munge_from + msgdata = dict( + dmarc=True, + original_sender='anne@example.com', + ) + msg = mfs(self._text) + del msg['from'] + dmarc.process(self._mlist, msg, msgdata) + self.assertMultiLineEqual(msg.as_string(), """\ +To: ant@example.com +Subject: A subject +X-Mailman-Version: X.Y +Message-ID: <some-id@example.com> +Date: Fri, 1 Jan 2016 00:00:01 +0000 +Another-Header: To test removal in wrapper +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="=====abc==" +From: anne--- via Ant <ant@example.com> +Reply-To: anne@example.com + +--=====abc== +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Some things to say. +--=====abc== +Content-Type: text/html; charset="us-ascii" +Content-Transfer-Encoding: 7bit + +<html><head></head><body>Some things to say.</body></html> +--=====abc==-- +""") + + def test_action_munge_from_display_name_in_from(self): + self._mlist.dmarc_mitigate_action = DMARCMitigateAction.munge_from + msgdata = {'dmarc': True} + msg = mfs(self._text) + del msg['from'] + msg['From'] = 'Anne Person <anne@example.com>' + dmarc.process(self._mlist, msg, msgdata) + self.assertMultiLineEqual(msg.as_string(), """\ +To: ant@example.com +Subject: A subject +X-Mailman-Version: X.Y +Message-ID: <some-id@example.com> +Date: Fri, 1 Jan 2016 00:00:01 +0000 +Another-Header: To test removal in wrapper +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="=====abc==" +From: Anne Person via Ant <ant@example.com> +Reply-To: Anne Person <anne@example.com> + +--=====abc== +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Some things to say. +--=====abc== +Content-Type: text/html; charset="us-ascii" +Content-Transfer-Encoding: 7bit + +<html><head></head><body>Some things to say.</body></html> +--=====abc==-- +""") + + def test_action_munge_from_display_name_in_list(self): + self._mlist.dmarc_mitigate_action = DMARCMitigateAction.munge_from + add_member( + self._mlist, + RequestRecord('anne@example.com', 'Anna Banana') + ) + msgdata = {'dmarc': True} + msg = mfs(self._text) + dmarc.process(self._mlist, msg, msgdata) + self.assertMultiLineEqual(msg.as_string(), """\ +To: ant@example.com +Subject: A subject +X-Mailman-Version: X.Y +Message-ID: <some-id@example.com> +Date: Fri, 1 Jan 2016 00:00:01 +0000 +Another-Header: To test removal in wrapper +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="=====abc==" +From: Anna Banana via Ant <ant@example.com> +Reply-To: anne@example.com + +--=====abc== +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: 7bit + +Some things to say. +--=====abc== +Content-Type: text/html; charset="us-ascii" +Content-Transfer-Encoding: 7bit + +<html><head></head><body>Some things to say.</body></html> +--=====abc==-- +""") + def test_no_action_without_msgdata(self): self._mlist.dmarc_mitigate_action = DMARCMitigateAction.munge_from msg = mfs(self._text) |
