diff options
| -rw-r--r-- | src/mailman/config/schema.cfg | 9 | ||||
| -rw-r--r-- | src/mailman/handlers/tests/test_dmarc.py | 54 | ||||
| -rw-r--r-- | src/mailman/rules/dmarc.py | 2 | ||||
| -rw-r--r-- | src/mailman/rules/tests/test_dmarc.py | 15 |
4 files changed, 48 insertions, 32 deletions
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index 91be0742d..fdf4c2b6f 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -74,12 +74,13 @@ filtered_messages_are_preservable: no # The command should print the converted text to stdout. html_to_plain_text_command: /usr/bin/lynx -dump $filename -# Parameters for DMARC DNS lookups. If you are seeing 'DNSException: -# Unable to query DMARC policy ...' entries in your error log, you may need -# to adjust these. +# Parameters for DMARC DNS lookups. If you are seeing 'DNSException: Unable +# to query DMARC policy ...' entries in your error log, you may need to adjust +# these. +# # The time to wait for a response from a name server before timeout. dmarc_resolver_timeout: 3s -# The total time to spend trying to get an answer to the question. +# The total time to spend trying to get an answer to the DNS question. dmarc_resolver_lifetime: 5s # A URL from which to retrieve the data for the algorithm that computes diff --git a/src/mailman/handlers/tests/test_dmarc.py b/src/mailman/handlers/tests/test_dmarc.py index 4a9375b7f..6fe15bd18 100644 --- a/src/mailman/handlers/tests/test_dmarc.py +++ b/src/mailman/handlers/tests/test_dmarc.py @@ -170,12 +170,18 @@ Content-Transfer-Encoding: 7bit --=====abc==-- """) - def test_action_munge_from_display_name_in_from(self): + def test_action_munge_multiple_froms(self): self._mlist.dmarc_mitigate_action = DMARCMitigateAction.munge_from - msgdata = {'dmarc': True} + msgdata = dict( + dmarc=True, + original_sender='cate@example.com', + ) msg = mfs(self._text) + # Put multiple addresses in the From: header. The msgdata must + # contain a key naming the "original sender" as determined by the + # Message.sender attribute. del msg['from'] - msg['From'] = 'Anne Person <anne@example.com>' + msg['From'] = 'anne@example.com, bart@example.com' dmarc.process(self._mlist, msg, msgdata) self.assertMultiLineEqual(msg.as_string(), """\ To: ant@example.com @@ -186,8 +192,8 @@ 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> +From: cate--- via Ant <ant@example.com> +Reply-To: cate@example.com --=====abc== Content-Type: text/plain; charset="us-ascii" @@ -202,26 +208,24 @@ Content-Transfer-Encoding: 7bit --=====abc==-- """) - def test_action_munge_from_display_name_in_list(self): + def test_action_munge_from_display_name_in_from(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) + 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> +Message-ID: <alpha@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 +From: Anne Person via Ant <ant@example.com> +Reply-To: Anne Person <anne@example.com> --=====abc== Content-Type: text/plain; charset="us-ascii" @@ -236,18 +240,14 @@ Content-Transfer-Encoding: 7bit --=====abc==-- """) - def test_action_munge_multiple_froms(self): + def test_action_munge_from_display_name_in_list(self): self._mlist.dmarc_mitigate_action = DMARCMitigateAction.munge_from - msg = mfs(self._text) - # Put multiple addresses in the From: header. The msgdata must - # contain a key naming the "original sender" as determined by the - # Message.sender attribute. - del msg['from'] - msg['From'] = 'anne@example.com, bart@example.com' - msgdata = dict( - dmarc=True, - original_sender='cate@example.com', + 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 @@ -258,8 +258,8 @@ 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: cate --- via Ant <ant@example.com> -Reply-To: cate@example.com +From: Anna Banana via Ant <ant@example.com> +Reply-To: anne@example.com --=====abc== Content-Type: text/plain; charset="us-ascii" @@ -320,7 +320,7 @@ Content-Transfer-Encoding: 7bit To: ant@example.com Subject: A subject X-Mailman-Version: X.Y -Message-ID: <some-id@example.com> +Message-ID: <alpha@example.com> Date: Fri, 1 Jan 2016 00:00:01 +0000 Another-Header: To test removal in wrapper MIME-Version: 1.0 @@ -419,7 +419,7 @@ Content-Disposition: inline To: ant@example.com Subject: A subject X-Mailman-Version: X.Y -Message-ID: <some-id@example.com> +Message-ID: <alpha@example.com> Date: Fri, 1 Jan 2016 00:00:01 +0000 Another-Header: To test removal in wrapper MIME-Version: 1.0 diff --git a/src/mailman/rules/dmarc.py b/src/mailman/rules/dmarc.py index 90b874e32..890fe9ff2 100644 --- a/src/mailman/rules/dmarc.py +++ b/src/mailman/rules/dmarc.py @@ -48,7 +48,7 @@ def _get_suffixes(url): try: d = request.urlopen(url) except error.URLError as e: - elog.error('Unable to retrieve data from %s: %s', url, e) + elog.error('Unable to retrieve data from %s: %s', url, e.reason) return for line in d.readlines(): line = str(line, encoding='utf-8') diff --git a/src/mailman/rules/tests/test_dmarc.py b/src/mailman/rules/tests/test_dmarc.py index 666375699..16cf947cc 100644 --- a/src/mailman/rules/tests/test_dmarc.py +++ b/src/mailman/rules/tests/test_dmarc.py @@ -21,9 +21,11 @@ organizational domain tests.""" from dns.rdatatype import TXT from dns.resolver import NXDOMAIN, NoAnswer from mailman.rules import dmarc +from mailman.testing.helpers import LogFileMark from mailman.testing.layers import ConfigLayer from public import public from unittest import TestCase, mock +from urllib.error import URLError @public @@ -108,3 +110,16 @@ class TestDMARCRules(TestCase): def test_exception_to_wild_card(self): self.assertEqual( dmarc._get_org_dom('ssub.sub.city.kobe.jp'), 'city.kobe.jp') + + def test_no_publicsuffix_dot_org(self): + mark = LogFileMark('mailman.error') + with mock.patch('mailman.rules.dmarc.request.urlopen', + side_effect=URLError('no internet')): + domain = dmarc._get_org_dom('ssub.sub.city.kobe.jp') + self.assertEqual(domain, 'kobe.jp') + line = mark.readline() + self.assertEqual( + line[-95:], + 'Unable to retrieve data from ' + 'https://publicsuffix.org/list/public_suffix_list.dat: ' + 'no internet\n') |
