1
0

test_linux_acl.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. import shutil
  6. import pytest
  7. # Import Salt Testing libs
  8. from tests.support.runtests import RUNTIME_VARS
  9. from tests.support.case import ModuleCase
  10. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  11. # Import salt libs
  12. import salt.utils.files
  13. import salt.utils.user
  14. # Acl package should be installed to test linux_acl module
  15. @pytest.mark.skip_if_binaries_missing(['getfacl'])
  16. # Doesn't work. Why?
  17. # @pytest.mark.requires_salt_modules('acl')
  18. # @pytest.mark.requires_salt_modules('linux_acl')
  19. @pytest.mark.windows_whitelisted
  20. class LinuxAclModuleTest(ModuleCase, AdaptedConfigurationTestCaseMixin):
  21. '''
  22. Validate the linux_acl module
  23. '''
  24. def setUp(self):
  25. # Blindly copied from tests.integration.modules.file; Refactoring?
  26. self.myfile = os.path.join(RUNTIME_VARS.TMP, 'myfile')
  27. with salt.utils.files.fopen(self.myfile, 'w+') as fp:
  28. fp.write('Hello\n')
  29. self.mydir = os.path.join(RUNTIME_VARS.TMP, 'mydir/isawesome')
  30. if not os.path.isdir(self.mydir):
  31. # left behind... Don't fail because of this!
  32. os.makedirs(self.mydir)
  33. self.mysymlink = os.path.join(RUNTIME_VARS.TMP, 'mysymlink')
  34. if os.path.islink(self.mysymlink):
  35. os.remove(self.mysymlink)
  36. os.symlink(self.myfile, self.mysymlink)
  37. self.mybadsymlink = os.path.join(RUNTIME_VARS.TMP, 'mybadsymlink')
  38. if os.path.islink(self.mybadsymlink):
  39. os.remove(self.mybadsymlink)
  40. os.symlink('/nonexistentpath', self.mybadsymlink)
  41. super(LinuxAclModuleTest, self).setUp()
  42. def tearDown(self):
  43. if os.path.isfile(self.myfile):
  44. os.remove(self.myfile)
  45. if os.path.islink(self.mysymlink):
  46. os.remove(self.mysymlink)
  47. if os.path.islink(self.mybadsymlink):
  48. os.remove(self.mybadsymlink)
  49. shutil.rmtree(self.mydir, ignore_errors=True)
  50. super(LinuxAclModuleTest, self).tearDown()
  51. def test_version(self):
  52. self.assertRegex(self.run_function('acl.version'), r'\d+\.\d+\.\d+')
  53. def test_getfacl_w_single_file_without_acl(self):
  54. ret = self.run_function('acl.getfacl', arg=[self.myfile])
  55. user = salt.utils.user.get_user()
  56. group = salt.utils.user.get_default_group(user)
  57. self.maxDiff = None
  58. self.assertEqual(
  59. ret,
  60. {self.myfile: {'other': [{'': {'octal': 4, 'permissions': {'read': True, 'write': False, 'execute': False}}}],
  61. 'user': [{user: {'octal': 6, 'permissions': {'read': True, 'write': True, 'execute': False}}}],
  62. 'group': [{group: {'octal': 4, 'permissions': {'read': True, 'write': False, 'execute': False}}}],
  63. 'comment': {'owner': user, 'group': group, 'file': self.myfile}}}
  64. )