summaryrefslogtreecommitdiff
path: root/lib/thandy/tests.py
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-10-14 05:10:30 +0000
committerNick Mathewson <nickm@torproject.org>2008-10-14 05:10:30 +0000
commitd90990ee3ecd09a2725b8051759a900ebd488b8c (patch)
treefbe68d0c4b698d45bfdcb6c91a43ea2e60c21329 /lib/thandy/tests.py
parentfb5a6115a6f3ea0216e3ca0645ba1eb31fb02876 (diff)
Rename glider to thandy, based on discussions on #nottor. Please let me know ASAP if there is another program Thandy, or if it means something rude, or whatever.
git-svn-id: file:///home/or/svnrepo/updater/trunk@17085 55e972cd-5a19-0410-ae62-a4d7a52db4cd
Diffstat (limited to 'lib/thandy/tests.py')
-rw-r--r--lib/thandy/tests.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/thandy/tests.py b/lib/thandy/tests.py
new file mode 100644
index 0000000..8b967a5
--- /dev/null
+++ b/lib/thandy/tests.py
@@ -0,0 +1,64 @@
+
+import unittest
+import doctest
+import os
+import tempfile
+
+import thandy.keys
+import thandy.formats
+import thandy.repository
+import thandy.checkJson
+
+import thandy.tests
+
+class CanonicalEncodingTest(unittest.TestCase):
+ def test_encode(self):
+ enc = thandy.formats.encodeCanonical
+ self.assertEquals(enc(''), '""')
+ self.assertEquals(enc('"'), '"\\""')
+ self.assertEquals(enc('\t\\\n"\r'),
+ '"\t\\\\\n\\"\r"')
+
+class CryptoTests(unittest.TestCase):
+ def test_encrypt(self):
+ s = "The Secret words are marzipan habidashery zeugma."
+ password = "the password is swordfish."
+ encrypted = thandy.keys.encryptSecret(s, password)
+ self.assertNotEquals(encrypted, s)
+ self.assert_(encrypted.startswith("GKEY1"))
+ self.assertEquals(s, thandy.keys.decryptSecret(encrypted, password))
+ self.assertRaises(thandy.BadPassword, thandy.keys.decryptSecret,
+ encrypted, "password")
+ self.assertRaises(thandy.UnknownFormat, thandy.keys.decryptSecret,
+ "foobar", password)
+
+ def test_keystore(self):
+ passwd = "umfitty noonah"
+ fname = tempfile.mktemp()
+ ks = thandy.keys.KeyStore(fname)
+ key1 = thandy.keys.RSAKey.generate(512)
+ key2 = thandy.keys.RSAKey.generate(512)
+ ks.addKey(key1)
+ ks.addKey(key2)
+ ks.save(passwd)
+
+ ks2 = thandy.keys.KeyStore(fname)
+ ks2.load(passwd)
+ self.assertEquals(key1.key.n, ks2.getKey(key1.getKeyID()).key.n)
+
+def suite():
+ suite = unittest.TestSuite()
+
+ suite.addTest(doctest.DocTestSuite(thandy.formats))
+ suite.addTest(doctest.DocTestSuite(thandy.keys))
+ suite.addTest(doctest.DocTestSuite(thandy.checkJson))
+
+ loader = unittest.TestLoader()
+ suite.addTest(loader.loadTestsFromModule(thandy.tests))
+
+ return suite
+
+
+if __name__ == '__main__':
+
+ unittest.TextTestRunner(verbosity=1).run(suite())