test_key.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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, skipIf
  7. @pytest.mark.windows_whitelisted
  8. class KeyWheelModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
  9. def setUp(self):
  10. self.wheel = salt.wheel.Wheel(dict(self.get_config("client_config")))
  11. def tearDown(self):
  12. del self.wheel
  13. @skipIf(True, "SLOWTEST skip")
  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. @skipIf(True, "SLOWTEST skip")
  19. def test_gen(self):
  20. ret = self.wheel.cmd(
  21. "key.gen", kwarg={"id_": "soundtechniciansrock"}, print_event=False
  22. )
  23. self.assertIn("pub", ret)
  24. self.assertIn("priv", ret)
  25. try:
  26. self.assertTrue(ret.get("pub", "").startswith("-----BEGIN PUBLIC KEY-----"))
  27. except AssertionError:
  28. self.assertTrue(
  29. ret.get("pub", "").startswith("-----BEGIN RSA PUBLIC KEY-----")
  30. )
  31. self.assertTrue(
  32. ret.get("priv", "").startswith("-----BEGIN RSA PRIVATE KEY-----")
  33. )
  34. @skipIf(True, "SLOWTEST skip")
  35. def test_master_key_str(self):
  36. ret = self.wheel.cmd("key.master_key_str", print_event=False)
  37. self.assertIn("local", ret)
  38. self.assertIn("master.pub", ret.get("local"))
  39. self.assertTrue(
  40. ret.get("local").get("master.pub").startswith("-----BEGIN PUBLIC KEY-----")
  41. )