1
0

test_key.py 1.8 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.mixins import AdaptedConfigurationTestCaseMixin
  6. from tests.support.unit import TestCase
  7. @pytest.mark.windows_whitelisted
  8. @pytest.mark.usefixtures("salt_sub_minion")
  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. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  15. def test_list_all(self):
  16. ret = self.wheel.cmd("key.list_all", print_event=False)
  17. for host in ["minion", "sub_minion"]:
  18. self.assertIn(host, ret["minions"])
  19. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  20. def test_gen(self):
  21. ret = self.wheel.cmd(
  22. "key.gen", kwarg={"id_": "soundtechniciansrock"}, print_event=False
  23. )
  24. self.assertIn("pub", ret)
  25. self.assertIn("priv", ret)
  26. try:
  27. self.assertTrue(ret.get("pub", "").startswith("-----BEGIN PUBLIC KEY-----"))
  28. except AssertionError:
  29. self.assertTrue(
  30. ret.get("pub", "").startswith("-----BEGIN RSA PUBLIC KEY-----")
  31. )
  32. self.assertTrue(
  33. ret.get("priv", "").startswith("-----BEGIN RSA PRIVATE KEY-----")
  34. )
  35. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  36. def test_master_key_str(self):
  37. ret = self.wheel.cmd("key.master_key_str", print_event=False)
  38. self.assertIn("local", ret)
  39. self.assertIn("master.pub", ret.get("local"))
  40. self.assertTrue(
  41. ret.get("local").get("master.pub").startswith("-----BEGIN PUBLIC KEY-----")
  42. )