• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from test import support
2import unittest
3
4crypt = support.import_module('crypt')
5
6class CryptTestCase(unittest.TestCase):
7
8    def test_crypt(self):
9        c = crypt.crypt('mypassword', 'ab')
10        if support.verbose:
11            print('Test encryption: ', c)
12
13    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        # Guarantee that METHOD_CRYPT is the last method in crypt.methods.
29        self.assertTrue(len(crypt.methods) >= 1)
30        self.assertEqual(crypt.METHOD_CRYPT, crypt.methods[-1])
31
32if __name__ == "__main__":
33    unittest.main()
34