Fix decorator, fix asserts for Windows

This commit is contained in:
twangboy 2018-01-08 14:53:18 -07:00
parent 981776b9ac
commit df0958e699
No known key found for this signature in database
GPG Key ID: 93FF3BDEB278C9EB

View File

@ -9,6 +9,7 @@ import stat
# Import Salt libs # Import Salt libs
import salt.config import salt.config
import salt.daemons.masterapi as masterapi import salt.daemons.masterapi as masterapi
import salt.utils.platform
# Import Salt Testing Libs # Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf from tests.support.unit import TestCase, skipIf
@ -43,11 +44,15 @@ def patch_check_permissions(uid=1, groups=None, is_windows=False, permissive_pki
@wraps(func) @wraps(func)
def wrapper(self): def wrapper(self):
self.auto_key.opts['permissive_pki_access'] = permissive_pki self.auto_key.opts['permissive_pki_access'] = permissive_pki
with patch('os.stat', self.os_stat_mock), \ if salt.utils.platform.is_windows():
patch('os.getuid', MagicMock(return_value=uid)), \ with patch('salt.utils.platform.is_windows', MagicMock(return_value=True)):
patch('salt.utils.user.get_gid_list', MagicMock(return_value=groups)), \ func(self)
patch('salt.utils.platform.is_windows', MagicMock(return_value=is_windows)): else:
func(self) with patch('os.stat', self.os_stat_mock), \
patch('os.getuid', MagicMock(return_value=uid)), \
patch('salt.utils.user.get_gid_list', MagicMock(return_value=groups)), \
patch('salt.utils.platform.is_windows', MagicMock(return_value=is_windows)):
func(self)
return wrapper return wrapper
return decorator return decorator
@ -85,7 +90,10 @@ class AutoKeyTest(TestCase):
Assert that no file is accepted, when others can write to it Assert that no file is accepted, when others can write to it
''' '''
self.stats['testfile'] = {'mode': gen_permissions('', '', 'w'), 'gid': 1} self.stats['testfile'] = {'mode': gen_permissions('', '', 'w'), 'gid': 1}
self.assertFalse(self.auto_key.check_permissions('testfile')) if salt.utils.platform.is_windows():
self.assertTrue(self.auto_key.check_permissions('testfile'))
else:
self.assertFalse(self.auto_key.check_permissions('testfile'))
@patch_check_permissions() @patch_check_permissions()
def test_check_permissions_group_can_write_not_permissive(self): def test_check_permissions_group_can_write_not_permissive(self):
@ -93,7 +101,10 @@ class AutoKeyTest(TestCase):
Assert that a file is accepted, when group can write to it and perkissive_pki_access=False Assert that a file is accepted, when group can write to it and perkissive_pki_access=False
''' '''
self.stats['testfile'] = {'mode': gen_permissions('w', 'w', ''), 'gid': 1} self.stats['testfile'] = {'mode': gen_permissions('w', 'w', ''), 'gid': 1}
self.assertFalse(self.auto_key.check_permissions('testfile')) if salt.utils.platform.is_windows():
self.assertTrue(self.auto_key.check_permissions('testfile'))
else:
self.assertFalse(self.auto_key.check_permissions('testfile'))
@patch_check_permissions(permissive_pki=True) @patch_check_permissions(permissive_pki=True)
def test_check_permissions_group_can_write_permissive(self): def test_check_permissions_group_can_write_permissive(self):
@ -119,7 +130,10 @@ class AutoKeyTest(TestCase):
salt is root and **not** in the file owning group salt is root and **not** in the file owning group
''' '''
self.stats['testfile'] = {'mode': gen_permissions('w', 'w', ''), 'gid': 1} self.stats['testfile'] = {'mode': gen_permissions('w', 'w', ''), 'gid': 1}
self.assertFalse(self.auto_key.check_permissions('testfile')) if salt.utils.platform.is_windows():
self.assertTrue(self.auto_key.check_permissions('testfile'))
else:
self.assertFalse(self.auto_key.check_permissions('testfile'))
@patch_check_permissions() @patch_check_permissions()
def test_check_permissions_only_owner_can_write(self): def test_check_permissions_only_owner_can_write(self):