[tor-commits] [bridgedb/develop] Add unittests for bridgedb.email.server.checkDKIM().

isis at torproject.org isis at torproject.org
Wed May 14 03:42:27 UTC 2014


commit a2fda186970113855a8ac9844069a7054ec4395e
Author: Isis Lovecruft <isis at torproject.org>
Date:   Tue May 6 12:21:46 2014 +0000

    Add unittests for bridgedb.email.server.checkDKIM().
---
 lib/bridgedb/test/test_email_server.py |   34 ++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/lib/bridgedb/test/test_email_server.py b/lib/bridgedb/test/test_email_server.py
index a308056..b9677e2 100644
--- a/lib/bridgedb/test/test_email_server.py
+++ b/lib/bridgedb/test/test_email_server.py
@@ -100,6 +100,40 @@ class DummyEmailDistributor(object):
         pass
 
 
+class CheckDKIMTests(unittest.TestCase):
+    """Tests for :func:`email.server.checkDKIM`."""
+
+    def setUp(self):
+        """Create fake email, distributor, and associated context data."""
+        self.goodMessage = io.StringIO(unicode("""\
+From: user at gmail.com
+To: bridges at localhost
+X-DKIM-Authentication-Results: pass
+Subject: testing
+
+get bridges
+"""))
+        self.badMessage = io.StringIO(unicode("""\
+From: user at gmail.com
+To: bridges at localhost
+Subject: testing
+
+get bridges
+"""))
+        self.config = _createConfig()
+        self.domainRules = self.config.EMAIL_DOMAIN_RULES
+
+    def test_checkDKIM_good(self):
+        message = server.smtp.rfc822.Message(self.goodMessage)
+        self.assertTrue(server.checkDKIM(message,
+                                         self.domainRules.get("gmail.com")))
+
+    def test_checkDKIM_bad(self):
+        message = server.smtp.rfc822.Message(self.badMessage)
+        result = server.checkDKIM(message, self.domainRules.get("gmail.com"))
+        self.assertIs(result, False)
+
+
 class CreateResponseBodyTests(unittest.TestCase):
     """Tests for :func:`bridgedb.email.server.createResponseBody`."""
 





More information about the tor-commits mailing list