1
0

test_client.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import pytest
  4. import salt.auth
  5. import salt.utils.platform
  6. import salt.wheel
  7. from tests.support.helpers import slowTest
  8. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  9. from tests.support.unit import TestCase, skipIf
  10. @pytest.mark.windows_whitelisted
  11. class WheelModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
  12. eauth_creds = {
  13. "username": "saltdev_auto",
  14. "password": "saltdev",
  15. "eauth": "auto",
  16. }
  17. def setUp(self):
  18. """
  19. Configure an eauth user to test with
  20. """
  21. self.wheel = salt.wheel.Wheel(dict(self.get_config("client_config")))
  22. def tearDown(self):
  23. del self.wheel
  24. @slowTest
  25. def test_master_call(self):
  26. """
  27. Test executing master_call with lowdata
  28. The choice of using key.list_all for this is arbitrary and should be
  29. changed to some mocked function that is more testing friendly.
  30. """
  31. low = {"client": "wheel", "fun": "key.list_all", "print_event": False}
  32. low.update(self.eauth_creds)
  33. self.wheel.master_call(**low)
  34. def test_token(self):
  35. """
  36. Test executing master_call with lowdata
  37. The choice of using key.list_all for this is arbitrary and should be
  38. changed to some mocked function that is more testing friendly.
  39. """
  40. auth = salt.auth.LoadAuth(dict(self.get_config("client_config")))
  41. token = auth.mk_token(self.eauth_creds)
  42. token = auth.mk_token(
  43. {"username": "saltdev_auto", "password": "saltdev", "eauth": "auto"}
  44. )
  45. self.wheel.master_call(
  46. **{
  47. "client": "wheel",
  48. "fun": "key.list_all",
  49. "token": token["token"],
  50. "print_event": False,
  51. }
  52. )
  53. @slowTest
  54. def test_cmd_sync(self):
  55. low = {
  56. "client": "wheel",
  57. "fun": "key.list_all",
  58. "print_event": False,
  59. }
  60. low.update(self.eauth_creds)
  61. self.wheel.cmd_sync(low)
  62. # Remove this skipIf when Issue #39616 is resolved
  63. # https://github.com/saltstack/salt/issues/39616
  64. @skipIf(
  65. salt.utils.platform.is_windows(),
  66. "Causes pickling error on Windows: Issue #39616",
  67. )
  68. def test_cmd_async(self):
  69. low = {
  70. "client": "wheel_async",
  71. "fun": "key.list_all",
  72. "print_event": False,
  73. }
  74. low.update(self.eauth_creds)
  75. self.wheel.cmd_async(low)
  76. @slowTest
  77. def test_cmd_sync_w_arg(self):
  78. low = {
  79. "fun": "key.finger",
  80. "match": "*",
  81. "print_event": False,
  82. }
  83. low.update(self.eauth_creds)
  84. ret = self.wheel.cmd_sync(low)
  85. self.assertIn("return", ret.get("data", {}))
  86. def test_wildcard_auth(self):
  87. low = {
  88. "username": "the_s0und_of_t3ch",
  89. "password": "willrockyou",
  90. "eauth": "auto",
  91. "fun": "key.list_all",
  92. "print_event": False,
  93. }
  94. self.wheel.cmd_sync(low)