diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/rules/docs/dmarc-mitigation.rst | 14 | ||||
| -rw-r--r-- | src/mailman/rules/tests/test_dmarc.py | 41 |
2 files changed, 25 insertions, 30 deletions
diff --git a/src/mailman/rules/docs/dmarc-mitigation.rst b/src/mailman/rules/docs/dmarc-mitigation.rst index 9a6fa5b9b..c16611a9c 100644 --- a/src/mailman/rules/docs/dmarc-mitigation.rst +++ b/src/mailman/rules/docs/dmarc-mitigation.rst @@ -37,7 +37,7 @@ A message From: a domain without a DMARC policy does not set any flags. ... ... """) >>> msgdata = {} - >>> with patcher as Resolver, patcher2 as urlopen: + >>> with patcher, patcher2: ... rule.check(mlist, msg, msgdata) False >>> msgdata == {} @@ -54,7 +54,7 @@ action is no_mitigation. ... ... """) >>> msgdata = {} - >>> with patcher as Resolver, patcher2 as urlopen: + >>> with patcher, patcher2: ... rule.check(mlist, msg, msgdata) False >>> msgdata == {} @@ -70,7 +70,7 @@ But with a different list setting, the message is flagged. ... ... """) >>> msgdata = {} - >>> with patcher as Resolver, patcher2 as urlopen: + >>> with patcher, patcher2: ... rule.check(mlist, msg, msgdata) False >>> msgdata['dmarc'] @@ -85,7 +85,7 @@ Subdomains which don't have a policy will check the organizational domain. ... ... """) >>> msgdata = {} - >>> with patcher as Resolver, patcher2 as urlopen: + >>> with patcher, patcher2: ... rule.check(mlist, msg, msgdata) False >>> msgdata['dmarc'] @@ -103,7 +103,7 @@ message. ... ... """) >>> msgdata = {} - >>> with patcher as Resolver, patcher2 as urlopen: + >>> with patcher, patcher2: ... rule.check(mlist, msg, msgdata) True >>> msgdata['dmarc'] @@ -122,7 +122,7 @@ We can reject the message with a default reason. ... ... """) >>> msgdata = {} - >>> with patcher as Resolver, patcher2 as urlopen: + >>> with patcher, patcher2: ... rule.check(mlist, msg, msgdata) True >>> msgdata['dmarc'] @@ -143,7 +143,7 @@ And, we can reject with a custom message. ... ... """) >>> msgdata = {} - >>> with patcher as Resolver, patcher2 as urlopen: + >>> with patcher, patcher2: ... rule.check(mlist, msg, msgdata) True >>> msgdata['dmarc'] diff --git a/src/mailman/rules/tests/test_dmarc.py b/src/mailman/rules/tests/test_dmarc.py index 1ff1f0bec..e24fa29d0 100644 --- a/src/mailman/rules/tests/test_dmarc.py +++ b/src/mailman/rules/tests/test_dmarc.py @@ -102,21 +102,15 @@ def get_org_data(): """Create a mock to load the organizational domain data from our local test data. """ - class oururlopen: - def __init__(self): - pass - - def open(url): - datapath = os.path.join( - os.path.split(dmarc.__file__)[0], - 'data', - 'org_domain', - ) - org_data_url = 'file:///{}'.format(datapath) - # Ensure we load the data. - dmarc.s_dict.clear() - return urlopen(org_data_url) - return patch('mailman.rules.dmarc.request.urlopen', oururlopen.open) + def ouropen(url): + datapath = os.path.join( + os.path.split(dmarc.__file__)[0], + 'data', + 'org_domain', + ) + org_data_url = 'file:///{}'.format(datapath) + return urlopen(org_data_url) + return patch('mailman.rules.dmarc.request.urlopen', ouropen) class TestDMARCRules(TestCase): @@ -137,19 +131,19 @@ class TestDMARCRules(TestCase): self.assertEqual(len(self.cache), 0) def test_no_data_for_domain(self): - with get_org_data() as urlopen: # noqa F841 + with get_org_data(): self.assertEqual( dmarc._get_org_dom('sub.dom.example.nxtld'), 'example.nxtld') def test_domain_with_wild_card(self): - with get_org_data() as urlopen: # noqa F841 + with get_org_data(): self.assertEqual( dmarc._get_org_dom('ssub.sub.foo.kobe.jp'), 'sub.foo.kobe.jp') def test_exception_to_wild_card(self): - with get_org_data() as urlopen: # noqa F841 + with get_org_data(): self.assertEqual( dmarc._get_org_dom('ssub.sub.city.kobe.jp'), 'city.kobe.jp') @@ -178,7 +172,8 @@ To: ant@example.com """) rule = dmarc.DMARCMitigation() - self.assertFalse(rule.check(mlist, msg, {})) + with get_dns_resolver(): + self.assertFalse(rule.check(mlist, msg, {})) def test_dmarc_dns_exception(self): mlist = create_list('ant@example.com') @@ -190,12 +185,12 @@ To: ant@example.com """) mark = LogFileMark('mailman.error') + rule = dmarc.DMARCMitigation() with get_dns_resolver(): - rule = dmarc.DMARCMitigation() - self.assertFalse(rule.check(mlist, msg, {})) + self.assertFalse(rule.check(mlist, msg, {})) line = mark.readline() self.assertEqual( - line[-117:], + line[-144:], 'DNSException: Unable to query DMARC policy for ' 'anne@example.info (_dmarc.example.info). ' - 'The DNS operation timed out.\n') + 'Abstract base class shared by all dnspython exceptions.\n') |
