1
0

test_sanitizers.py 1.7 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
  9. class SanitizersTestCase(TestCase):
  10. """
  11. TestCase for sanitizers
  12. """
  13. def test_sanitized_trim(self):
  14. """
  15. Test sanitized input for trimming
  16. """
  17. value = " sample "
  18. response = clean.trim(value)
  19. assert response == "sample"
  20. assert type(response) == text
  21. def test_sanitized_filename(self):
  22. """
  23. Test sanitized input for filename
  24. """
  25. value = "/absolute/path/to/the/file.txt"
  26. response = clean.filename(value)
  27. assert response == "file.txt"
  28. value = "../relative/path/to/the/file.txt"
  29. response = clean.filename(value)
  30. assert response == "file.txt"
  31. def test_sanitized_hostname(self):
  32. """
  33. Test sanitized input for hostname (id)
  34. """
  35. value = " ../ ../some/dubious/hostname "
  36. response = clean.hostname(value)
  37. assert response == "somedubioushostname"
  38. test_sanitized_id = test_sanitized_hostname
  39. def test_value_masked(self):
  40. """
  41. Test if the values are masked.
  42. :return:
  43. """
  44. out = mask_args_value("quantum: fluctuations", "quant*")
  45. assert out == "quantum: ** hidden **"
  46. def test_value_not_masked(self):
  47. """
  48. Test if the values are not masked.
  49. :return:
  50. """
  51. out = mask_args_value("quantum fluctuations", "quant*")
  52. assert out == "quantum fluctuations"