test_key.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # coding: utf-8
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import pytest
  4. import salt.wheel
  5. from tests.support.helpers import slowTest
  6. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  7. from tests.support.unit import TestCase
  8. @pytest.mark.windows_whitelisted
  9. @pytest.mark.usefixtures("salt_sub_minion")
  10. class KeyWheelModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
  11. def setUp(self):
  12. self.wheel = salt.wheel.Wheel(dict(self.get_config("client_config")))
  13. def tearDown(self):
  14. del self.wheel
  15. @slowTest
  16. def test_list_all(self):
  17. ret = self.wheel.cmd("key.list_all", print_event=False)
  18. for host in ["minion", "sub_minion"]:
  19. self.assertIn(host, ret["minions"])
  20. @slowTest
  21. def test_gen(self):
  22. ret = self.wheel.cmd(
  23. "key.gen", kwarg={"id_": "soundtechniciansrock"}, print_event=False
  24. )
  25. self.assertIn("pub", ret)
  26. self.assertIn("priv", ret)
  27. try:
  28. self.assertTrue(ret.get("pub", "").startswith("-----BEGIN PUBLIC KEY-----"))
  29. except AssertionError:
  30. self.assertTrue(
  31. ret.get("pub", "").startswith("-----BEGIN RSA PUBLIC KEY-----")
  32. )
  33. self.assertTrue(
  34. ret.get("priv", "").startswith("-----BEGIN RSA PRIVATE KEY-----")
  35. )
  36. @slowTest
  37. def test_master_key_str(self):
  38. ret = self.wheel.cmd("key.master_key_str", print_event=False)
  39. self.assertIn("local", ret)
  40. self.assertIn("master.pub", ret.get("local"))
  41. self.assertTrue(
  42. ret.get("local").get("master.pub").startswith("-----BEGIN PUBLIC KEY-----")
  43. )