test_pam.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. import sys
  8. # Import Salt Testing Libs
  9. from tests.support.unit import TestCase, skipIf
  10. from tests.support.mock import (
  11. patch,
  12. mock_open,
  13. )
  14. # Import Salt Libs
  15. import salt.modules.pam as pam
  16. MOCK_FILE = 'ok ok ignore '
  17. @skipIf(sys.platform.startswith('openbsd'), 'OpenBSD does not use PAM')
  18. class PamTestCase(TestCase):
  19. '''
  20. Test cases for salt.modules.pam
  21. '''
  22. # 'read_file' function tests: 1
  23. def test_read_file(self):
  24. '''
  25. Test if the parsing function works
  26. '''
  27. with patch('os.path.exists', return_value=True), \
  28. patch('salt.utils.files.fopen', mock_open(read_data=MOCK_FILE)):
  29. self.assertListEqual(pam.read_file('/etc/pam.d/login'),
  30. [{'arguments': [], 'control_flag': 'ok',
  31. 'interface': 'ok', 'module': 'ignore'}])