test_key.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # coding: utf-8
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.unit import TestCase
  6. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  7. # Import Salt libs
  8. import salt.wheel
  9. class KeyWheelModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
  10. def setUp(self):
  11. self.wheel = salt.wheel.Wheel(dict(self.get_config('client_config')))
  12. def tearDown(self):
  13. del self.wheel
  14. def test_list_all(self):
  15. ret = self.wheel.cmd('key.list_all', print_event=False)
  16. for host in ['minion', 'sub_minion']:
  17. self.assertIn(host, ret['minions'])
  18. def test_gen(self):
  19. ret = self.wheel.cmd('key.gen', kwarg={'id_': 'soundtechniciansrock'}, print_event=False)
  20. self.assertIn('pub', ret)
  21. self.assertIn('priv', ret)
  22. try:
  23. self.assertTrue(
  24. ret.get('pub', '').startswith('-----BEGIN PUBLIC KEY-----'))
  25. except AssertionError:
  26. self.assertTrue(
  27. ret.get('pub', '').startswith('-----BEGIN RSA PUBLIC KEY-----'))
  28. self.assertTrue(
  29. ret.get('priv', '').startswith('-----BEGIN RSA PRIVATE KEY-----'))