| 1 | n/a | from test import support |
|---|
| 2 | n/a | import unittest |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | crypt = support.import_module('crypt') |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | class CryptTestCase(unittest.TestCase): |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | def test_crypt(self): |
|---|
| 9 | n/a | c = crypt.crypt('mypassword', 'ab') |
|---|
| 10 | n/a | if support.verbose: |
|---|
| 11 | n/a | print('Test encryption: ', c) |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | def test_salt(self): |
|---|
| 14 | n/a | self.assertEqual(len(crypt._saltchars), 64) |
|---|
| 15 | n/a | for method in crypt.methods: |
|---|
| 16 | n/a | salt = crypt.mksalt(method) |
|---|
| 17 | n/a | self.assertEqual(len(salt), |
|---|
| 18 | n/a | method.salt_chars + (3 if method.ident else 0)) |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | def test_saltedcrypt(self): |
|---|
| 21 | n/a | for method in crypt.methods: |
|---|
| 22 | n/a | pw = crypt.crypt('assword', method) |
|---|
| 23 | n/a | self.assertEqual(len(pw), method.total_size) |
|---|
| 24 | n/a | pw = crypt.crypt('assword', crypt.mksalt(method)) |
|---|
| 25 | n/a | self.assertEqual(len(pw), method.total_size) |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | def test_methods(self): |
|---|
| 28 | n/a | # Guarantee that METHOD_CRYPT is the last method in crypt.methods. |
|---|
| 29 | n/a | self.assertTrue(len(crypt.methods) >= 1) |
|---|
| 30 | n/a | self.assertEqual(crypt.METHOD_CRYPT, crypt.methods[-1]) |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | if __name__ == "__main__": |
|---|
| 33 | n/a | unittest.main() |
|---|