1
0

test_sanitizers.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. from salt.ext.six import text_type as text
  5. # Import Salt Libs
  6. from salt.utils.sanitizers import clean, mask_args_value
  7. # Import Salt Testing Libs
  8. from tests.support.unit import TestCase, skipIf
  9. from tests.support.mock import NO_MOCK, NO_MOCK_REASON
  10. @skipIf(NO_MOCK, NO_MOCK_REASON)
  11. class SanitizersTestCase(TestCase):
  12. '''
  13. TestCase for sanitizers
  14. '''
  15. def test_sanitized_trim(self):
  16. '''
  17. Test sanitized input for trimming
  18. '''
  19. value = ' sample '
  20. response = clean.trim(value)
  21. assert response == 'sample'
  22. assert type(response) == text
  23. def test_sanitized_filename(self):
  24. '''
  25. Test sanitized input for filename
  26. '''
  27. value = '/absolute/path/to/the/file.txt'
  28. response = clean.filename(value)
  29. assert response == 'file.txt'
  30. value = '../relative/path/to/the/file.txt'
  31. response = clean.filename(value)
  32. assert response == 'file.txt'
  33. def test_sanitized_hostname(self):
  34. '''
  35. Test sanitized input for hostname (id)
  36. '''
  37. value = ' ../ ../some/dubious/hostname '
  38. response = clean.hostname(value)
  39. assert response == 'somedubioushostname'
  40. test_sanitized_id = test_sanitized_hostname
  41. def test_value_masked(self):
  42. '''
  43. Test if the values are masked.
  44. :return:
  45. '''
  46. out = mask_args_value('quantum: fluctuations', 'quant*')
  47. assert out == 'quantum: ** hidden **'
  48. def test_value_not_masked(self):
  49. '''
  50. Test if the values are not masked.
  51. :return:
  52. '''
  53. out = mask_args_value('quantum fluctuations', 'quant*')
  54. assert out == 'quantum fluctuations'