Unverified Commit 862b996d authored by Isis Lovecruft's avatar Isis Lovecruft
Browse files

Merge branch 'fix/12091-dkim-dunno' into fix/9874-automate-email-tests

parents 6fbe6f03 712f1169
......@@ -535,13 +535,26 @@ class SMTPAutoresponderTests(unittest.TestCase):
self.responder.incoming.canonicalFromSMTP = smtpFrom
self.assertFalse(self.responder.runChecks(emailFrom))
def test_SMTPAutoresponder_runChecks_badDKIM(self):
"""runChecks() should catch emails with bad DKIM headers for canonical
domains which we've configured to check DKIM verification results for.
def test_SMTPAutoresponder_runChecks_DKIM_dunno(self):
"""runChecks() should catch emails with bad DKIM headers
(``"X-DKIM-Authentication-Results: dunno"``) for canonical domains
which we're configured to check DKIM verification results for.
"""
emailFrom = Address('dkimlikewat@gmail.com')
emailFrom = Address('dkimlikedunno@gmail.com')
header = "X-DKIM-Authentication-Results: dunno"
self._getIncomingLines(str(emailFrom))
self.message.lines.insert(3, header)
self._setUpResponder()
self.assertFalse(self.responder.runChecks(emailFrom))
def test_SMTPAutoresponder_runChecks_DKIM_bad(self):
"""runChecks() should catch emails with bad DKIM headers
(``"X-DKIM-Authentication-Results: dunno"``) for canonical domains
which we're configured to check DKIM verification results for.
"""
emailFrom = Address('dkimlikewat@gmail.com')
header = "X-DKIM-Authentication-Results: wowie zowie there's a sig here"
self._getIncomingLines(str(emailFrom))
self.message.lines.insert(3, header)
self._setUpResponder()
self.assertFalse(self.responder.runChecks(emailFrom))
......@@ -24,36 +24,63 @@ class CheckDKIMTests(unittest.TestCase):
def setUp(self):
"""Create fake email, distributor, and associated context data."""
self.goodMessage = io.StringIO(unicode("""\
self.goodMessage = """\
From: user@gmail.com
To: bridges@localhost
X-DKIM-Authentication-Results: pass
Subject: testing
get bridges
"""))
self.badMessage = io.StringIO(unicode("""\
"""
self.badMessage = """\
From: user@gmail.com
To: bridges@localhost
Subject: testing
get bridges
"""))
"""
self.domainRules = {
'gmail.com': ["ignore_dots", "dkim"],
'example.com': [],
'localhost': [],
}
def _createMessage(self, messageString):
"""Create an ``rfc822.Message`` from a string."""
messageIO = io.StringIO(unicode(messageString))
return rfc822.Message(messageIO)
def test_checkDKIM_good(self):
message = rfc822.Message(self.goodMessage)
message = self._createMessage(self.goodMessage)
result = dkim.checkDKIM(message,
self.domainRules.get("gmail.com"))
self.assertTrue(result)
def test_checkDKIM_bad(self):
message = rfc822.Message(self.badMessage)
message = self._createMessage(self.badMessage)
result = dkim.checkDKIM(message,
self.domainRules.get("gmail.com"))
self.assertIs(result, False)
def test_checkDKIM_dunno(self):
"""A ``X-DKIM-Authentication-Results: dunno`` header should return
False.
"""
messageList = self.badMessage.split('\n')
messageList[2] = "X-DKIM-Authentication-Results: dunno"
message = self._createMessage('\n'.join(messageList))
result = dkim.checkDKIM(message,
self.domainRules.get("gmail.com"))
self.assertIs(result, False)
def test_checkDKIM_good_dunno(self):
"""A good DKIM verification header, *plus* an
``X-DKIM-Authentication-Results: dunno`` header should return False.
"""
messageList = self.badMessage.split('\n')
messageList.insert(2, "X-DKIM-Authentication-Results: dunno")
message = self._createMessage('\n'.join(messageList))
result = dkim.checkDKIM(message,
self.domainRules.get("gmail.com"))
self.assertIs(result, False)
Supports Markdown
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