[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/develop] Add unittests for bridgedb.email.dkim module.



commit ac36d66d7e25bbc0aa4dcef2ce364ca7aca841ea
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Mon Jun 2 21:08:35 2014 +0000

    Add unittests for bridgedb.email.dkim module.
---
 lib/bridgedb/test/test_email_dkim.py |   59 ++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/lib/bridgedb/test/test_email_dkim.py b/lib/bridgedb/test/test_email_dkim.py
new file mode 100644
index 0000000..3350d19
--- /dev/null
+++ b/lib/bridgedb/test/test_email_dkim.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of BridgeDB, a Tor bridge distribution system.
+#
+# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis@xxxxxxxxxxxxxx>
+#           please also see AUTHORS file
+# :copyright: (c) 2013, Isis Lovecruft
+#             (c) 2007-2013, The Tor Project, Inc.
+#             (c) 2007-2013, all entities within the AUTHORS file
+# :license: 3-Clause BSD, see LICENSE for licensing information
+
+"""Unittests for the :mod:`bridgedb.email.dkim` module."""
+
+import io
+
+from twisted.mail.smtp import rfc822
+from twisted.trial import unittest
+
+from bridgedb.email import dkim
+
+
+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@xxxxxxxxx
+To: bridges@localhost
+X-DKIM-Authentication-Results: pass
+Subject: testing
+
+get bridges
+"""))
+        self.badMessage = io.StringIO(unicode("""\
+From: user@xxxxxxxxx
+To: bridges@localhost
+Subject: testing
+
+get bridges
+"""))
+        self.domainRules = {
+            'gmail.com': ["ignore_dots", "dkim"],
+            'example.com': [],
+            'localhost': [],
+        }
+
+    def test_checkDKIM_good(self):
+        message = rfc822.Message(self.goodMessage)
+        result = dkim.checkDKIM(message,
+                                self.domainRules.get("gmail.com"))
+        self.assertTrue(result)
+                                         
+
+    def test_checkDKIM_bad(self):
+        message = rfc822.Message(self.badMessage)
+        result = dkim.checkDKIM(message,
+                                self.domainRules.get("gmail.com"))
+        self.assertIs(result, False)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits