Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 1 | from test import support |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 2 | import unittest |
R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame] | 3 | |
| 4 | crypt = support.import_module('crypt') |
Roger E. Masse | fab8ab8 | 1996-12-20 22:36:52 +0000 | [diff] [blame] | 5 | |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 6 | class CryptTestCase(unittest.TestCase): |
| 7 | |
| 8 | def test_crypt(self): |
| 9 | c = crypt.crypt('mypassword', 'ab') |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 10 | if support.verbose: |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 11 | print('Test encryption: ', c) |
| 12 | |
Sean Reifscheider | e2dfefb | 2011-02-22 10:55:44 +0000 | [diff] [blame^] | 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 | self.assertTrue(len(crypt.methods()) > 1) |
| 29 | |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 30 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 31 | support.run_unittest(CryptTestCase) |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 32 | |
| 33 | if __name__ == "__main__": |
| 34 | test_main() |