1
0

test_nacl.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt libs
  5. import salt.renderers.nacl as nacl
  6. # Import Salt Testing libs
  7. from tests.support.mixins import LoaderModuleMockMixin
  8. from tests.support.mock import MagicMock, patch
  9. from tests.support.unit import TestCase
  10. class NaclTestCase(TestCase, LoaderModuleMockMixin):
  11. """
  12. unit test NaCl renderer
  13. """
  14. def setup_loader_modules(self):
  15. return {nacl: {}}
  16. def test__decrypt_object(self):
  17. """
  18. test _decrypt_object
  19. """
  20. secret = "Use more salt."
  21. crypted = "NACL[MRN3cc+fmdxyQbz6WMF+jq1hKdU5X5BBI7OjK+atvHo1ll+w1gZ7XyWtZVfq9gK9rQaMfkDxmidJKwE0Mw==]"
  22. secret_map = {"secret": secret}
  23. crypted_map = {"secret": crypted}
  24. secret_list = [secret]
  25. crypted_list = [crypted]
  26. with patch.dict(nacl.__salt__, {"nacl.dec": MagicMock(return_value=secret)}):
  27. self.assertEqual(nacl._decrypt_object(secret), secret)
  28. self.assertEqual(nacl._decrypt_object(crypted), secret)
  29. self.assertEqual(nacl._decrypt_object(crypted_map), secret_map)
  30. self.assertEqual(nacl._decrypt_object(crypted_list), secret_list)
  31. self.assertEqual(nacl._decrypt_object(None), None)
  32. def test_render(self):
  33. """
  34. test render
  35. """
  36. secret = "Use more salt."
  37. crypted = "NACL[MRN3cc+fmdxyQbz6WMF+jq1hKdU5X5BBI7OjK+atvHo1ll+w1gZ7XyWtZVfq9gK9rQaMfkDxmidJKwE0Mw==]"
  38. with patch.dict(nacl.__salt__, {"nacl.dec": MagicMock(return_value=secret)}):
  39. self.assertEqual(nacl.render(crypted), secret)