Commit 9ecad5a6 authored by Mark Sapiro's avatar Mark Sapiro

Merge branch 'fix_726' into 'master'

Fix dmarc rule case sensitivity.

Closes #726

See merge request !654
parents 69e48ac6 0efc831a
Pipeline #150669595 passed with stage
in 17 minutes and 10 seconds
......@@ -21,6 +21,8 @@ Bugs
* Bounce probes are now encoded in the correct charset. (Closes #712)
* We now unfold address containing headers before parsing in avoid_duplicates.
(Closes #725)
* The ``dmarc`` rule no longer misses if DNS returns a name containing upper
case. (Closes #726)
REST
......
......@@ -216,7 +216,8 @@ def is_reject_or_quarantine(mlist, email, dmarc_domain, org=False):
str(record, encoding='utf-8')
for record in txt_rec.items[0].strings)
name = txt_rec.name.to_text()
results_by_name.setdefault(name, []).append(result)
# Don't be fooled by an answer with uppercase in the name.
results_by_name.setdefault(name.lower(), []).append(result)
expands = list(want_names)
seen = set(expands)
while expands:
......
......@@ -50,7 +50,8 @@ def get_dns_resolver(
rmult=False,
cmult=False,
cloop=False,
cmiss=False):
cmiss=False,
ucase=False):
"""Create a dns.resolver.Resolver mock.
This is used to return a predictable response to a _dmarc query. It
......@@ -140,6 +141,8 @@ def get_dns_resolver(
]
elif rmult:
self.answer = [Ans_e(), Ans_e(rdata=b'v=DMARC1; p=none;')]
elif ucase:
self.answer = [Ans_e(name='_dmarc.EXAMPLE.biz.')]
else:
self.answer = [Ans_e()]
......@@ -206,6 +209,21 @@ class TestDMARCRules(TestCase):
dmarc.get_organizational_domain('ssub.sub.city.kobe.jp'),
'city.kobe.jp')
def test_uppercase_in_returned_domain(self):
# Test that we can recognize an answer with case mismatch in the
# domain.
mlist = create_list('[email protected]')
# Use action reject. The rule only hits on reject and discard.
mlist.dmarc_mitigate_action = DMARCMitigateAction.reject
msg = mfs("""\
From: [email protected]
To: [email protected]
""")
rule = dmarc.DMARCMitigation()
with get_dns_resolver(ucase=True):
self.assertTrue(rule.check(mlist, msg, {}))
def test_no_at_sign_in_from_address(self):
# If there's no @ sign in the From: address, the rule can't hit.
mlist = create_list('[email protected]')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment