test_crypto_engine.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import unittest
  2. import pwman.util.config as config
  3. import os
  4. from pwman.util.crypto_engine import (write_password, save_a_secret_message,
  5. read_a_secret_message,
  6. CryptoEngine)
  7. # set cls_timout to negative number (e.g. -1) to disable
  8. default_config = {'Global': {'umask': '0100', 'colors': 'yes',
  9. 'cls_timeout': '5'
  10. },
  11. 'Database': {'type': 'SQLite',
  12. 'filename': os.path.join("tests", "pwman.db")},
  13. 'Encryption': {'algorithm': 'AES'},
  14. 'Readline': {'history': os.path.join("tests",
  15. "history")}
  16. }
  17. config.set_defaults(default_config)
  18. give_key = lambda msg: "verysecretkey"
  19. class CryptoEngineTest(unittest.TestCase):
  20. def test_a_write_password(self):
  21. write_password(reader=give_key)
  22. def test_b_save_secret(self):
  23. save_a_secret_message(reader=give_key)
  24. def test_c_read_secret(self):
  25. read_a_secret_message(reader=give_key)
  26. def test_d_get_crypto(self):
  27. ce = CryptoEngine.get()
  28. secret2 = ce.changepassword(reader=give_key)
  29. secret1 = ce.changepassword(reader=give_key)
  30. # althouth the same secret key is used,
  31. # the secret hash is not the same, because a
  32. # different random seed is used when calling
  33. # CryptoEngine._get_digest
  34. self.assertNotEqual(secret1, secret2)