blob: cb4234b5e59dc20cf2942bf632cf3e6e207b114a [file] [log] [blame]
Benjamin Petersonee8712c2008-05-20 21:35:26 +00001from test import support
Christian Heimesdd15f6c2008-03-16 00:07:10 +00002import unittest
R. David Murraya21e4ca2009-03-31 23:16:50 +00003
4crypt = support.import_module('crypt')
Roger E. Massefab8ab81996-12-20 22:36:52 +00005
Christian Heimesdd15f6c2008-03-16 00:07:10 +00006class CryptTestCase(unittest.TestCase):
7
8 def test_crypt(self):
9 c = crypt.crypt('mypassword', 'ab')
Benjamin Petersonee8712c2008-05-20 21:35:26 +000010 if support.verbose:
Christian Heimesdd15f6c2008-03-16 00:07:10 +000011 print('Test encryption: ', c)
12
Sean Reifscheidere2dfefb2011-02-22 10:55:44 +000013 def test_salt(self):
14 self.assertEqual(len(crypt.saltchars), 64)
15 for method in crypt.methods():
16 salt = crypt.mksalt(method)
17 self.assertEqual(len(salt),
18 method.salt_chars + (3 if method.ident else 0))
19
20 def test_saltedcrypt(self):
21 for method in crypt.methods():
22 pw = crypt.crypt('assword', method)
23 self.assertEqual(len(pw), method.total_size)
24 pw = crypt.crypt('assword', crypt.mksalt(method))
25 self.assertEqual(len(pw), method.total_size)
26
27 def test_methods(self):
28 self.assertTrue(len(crypt.methods()) > 1)
29
Christian Heimesdd15f6c2008-03-16 00:07:10 +000030def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000031 support.run_unittest(CryptTestCase)
Christian Heimesdd15f6c2008-03-16 00:07:10 +000032
33if __name__ == "__main__":
34 test_main()