1
0

test_client.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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, skipIf
  6. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  7. # Import Salt libs
  8. import salt.auth
  9. import salt.wheel
  10. import salt.utils.platform
  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. def test_master_call(self):
  25. '''
  26. Test executing master_call with lowdata
  27. The choice of using key.list_all for this is arbitrary and should be
  28. changed to some mocked function that is more testing friendly.
  29. '''
  30. low = {
  31. 'client': 'wheel',
  32. 'fun': 'key.list_all',
  33. 'print_event': False
  34. }
  35. low.update(self.eauth_creds)
  36. self.wheel.master_call(**low)
  37. def test_token(self):
  38. '''
  39. Test executing master_call with lowdata
  40. The choice of using key.list_all for this is arbitrary and should be
  41. changed to some mocked function that is more testing friendly.
  42. '''
  43. auth = salt.auth.LoadAuth(dict(self.get_config('client_config')))
  44. token = auth.mk_token(self.eauth_creds)
  45. token = auth.mk_token({
  46. 'username': 'saltdev_auto',
  47. 'password': 'saltdev',
  48. 'eauth': 'auto',
  49. })
  50. self.wheel.master_call(**{
  51. 'client': 'wheel',
  52. 'fun': 'key.list_all',
  53. 'token': token['token'],
  54. 'print_event': False,
  55. })
  56. def test_cmd_sync(self):
  57. low = {
  58. 'client': 'wheel',
  59. 'fun': 'key.list_all',
  60. 'print_event': False,
  61. }
  62. low.update(self.eauth_creds)
  63. self.wheel.cmd_sync(low)
  64. # Remove this skipIf when Issue #39616 is resolved
  65. # https://github.com/saltstack/salt/issues/39616
  66. @skipIf(salt.utils.platform.is_windows(),
  67. 'Causes pickling error on Windows: Issue #39616')
  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. def test_cmd_sync_w_arg(self):
  77. low = {
  78. 'fun': 'key.finger',
  79. 'match': '*',
  80. 'print_event': False,
  81. }
  82. low.update(self.eauth_creds)
  83. ret = self.wheel.cmd_sync(low)
  84. self.assertIn('return', ret.get('data', {}))
  85. def test_wildcard_auth(self):
  86. low = {
  87. 'username': 'the_s0und_of_t3ch',
  88. 'password': 'willrockyou',
  89. 'eauth': 'auto',
  90. 'fun': 'key.list_all',
  91. 'print_event': False,
  92. }
  93. self.wheel.cmd_sync(low)