1
0

test_venafiapi.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Tests for the salt-run command
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import
  7. import functools
  8. import random
  9. import string
  10. # Import Salt Testing libs
  11. from tests.support.case import ShellCase
  12. from tests.support.helpers import destructiveTest, expensiveTest
  13. from salt.ext.six.moves import range
  14. def _random_name(prefix=''):
  15. ret = prefix
  16. for _ in range(8):
  17. ret += random.choice(string.ascii_lowercase)
  18. return ret
  19. def with_random_name(func):
  20. '''
  21. generate a randomized name for a container
  22. '''
  23. @functools.wraps(func)
  24. def wrapper(self, *args, **kwargs):
  25. name = _random_name(prefix='salt_')
  26. return func(self, _random_name(prefix='salt_test_'), *args, **kwargs)
  27. return wrapper
  28. @destructiveTest
  29. @expensiveTest
  30. class VenafiTest(ShellCase):
  31. '''
  32. Test the venafi runner
  33. '''
  34. @with_random_name
  35. def test_gen_key_password(self, name):
  36. '''
  37. venafi.gen_key
  38. '''
  39. ret = self.run_run_plus(fun='venafi.gen_key',
  40. minion_id='{0}.test.saltstack.com'.format(name),
  41. dns_name='{0}.test.saltstack.com'.format(name),
  42. zone='Internet',
  43. password='SecretSauce')
  44. self.assertEqual(ret['out'][0], '-----BEGIN RSA PRIVATE KEY-----')
  45. self.assertEqual(ret['out'][1], 'Proc-Type: 4,ENCRYPTED')
  46. self.assertEqual(ret['out'][-1], '-----END RSA PRIVATE KEY-----')
  47. @with_random_name
  48. def test_gen_key_without_password(self, name):
  49. '''
  50. venafi.gen_key
  51. '''
  52. ret = self.run_run_plus(fun='venafi.gen_key',
  53. minion_id='{0}.test.saltstack.com'.format(name),
  54. dns_name='{0}.test.saltstack.com'.format(name),
  55. zone='Internet')
  56. self.assertEqual(ret['out'][0], '-----BEGIN RSA PRIVATE KEY-----')
  57. self.assertNotEqual(ret['out'][1], 'Proc-Type: 4,ENCRYPTED')
  58. self.assertEqual(ret['out'][-1], '-----END RSA PRIVATE KEY-----')
  59. @with_random_name
  60. def test_gen_csr(self, name):
  61. '''
  62. venafi.gen_csr
  63. '''
  64. ret = self.run_run_plus(fun='venafi.gen_csr',
  65. minion_id='{0}.test.saltstack.com'.format(name),
  66. dns_name='{0}.test.saltstack.com'.format(name),
  67. country='US', state='Utah', loc='Salt Lake City',
  68. org='Salt Stack Inc.', org_unit='Testing',
  69. zone='Internet', password='SecretSauce')
  70. self.assertEqual(ret['out'][0], '-----BEGIN CERTIFICATE REQUEST-----')
  71. self.assertEqual(ret['out'][-1], '-----END CERTIFICATE REQUEST-----')
  72. @with_random_name
  73. def test_request(self, name):
  74. '''
  75. venafi.request
  76. '''
  77. ret = self.run_run_plus(fun='venafi.request',
  78. minion_id='{0}.example.com'.format(name),
  79. dns_name='{0}.example.com'.format(name),
  80. country='US', state='Utah', loc='Salt Lake City',
  81. org='Salt Stack Inc.', org_unit='Testing',
  82. zone='Internet', password='SecretSauce')
  83. self.assertTrue('request_id' in ret['return'])