test_key.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Rupesh Tare <rupesht@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os.path
  8. # Import Salt Testing Libs
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.unit import TestCase
  11. from tests.support.mock import (
  12. MagicMock,
  13. patch,
  14. )
  15. # Import Salt Libs
  16. import salt.utils.crypt
  17. import salt.modules.key as key
  18. class KeyTestCase(TestCase, LoaderModuleMockMixin):
  19. '''
  20. Test cases for salt.modules.key
  21. '''
  22. def setup_loader_modules(self):
  23. return {key: {}}
  24. def test_finger(self):
  25. '''
  26. Test for finger
  27. '''
  28. with patch.object(os.path, 'join', return_value='A'):
  29. with patch.object(salt.utils.crypt,
  30. 'pem_finger', return_value='A'):
  31. with patch.dict(key.__opts__,
  32. {'pki_dir': MagicMock(return_value='A'), 'hash_type': 'sha256'}):
  33. self.assertEqual(key.finger(), 'A')
  34. def test_finger_master(self):
  35. '''
  36. Test for finger
  37. '''
  38. with patch.object(os.path, 'join', return_value='A'):
  39. with patch.object(salt.utils.crypt,
  40. 'pem_finger', return_value='A'):
  41. with patch.dict(key.__opts__,
  42. {'pki_dir': 'A', 'hash_type': 'sha256'}):
  43. self.assertEqual(key.finger_master(), 'A')