def setUp(self): self.temp_file = temp.file(parent=RUNTIME_VARS.TMP) win_dacl.set_owner(obj_name=self.temp_file, principal=self.current_user) win_dacl.set_inheritance(obj_name=self.temp_file, enabled=True) self.assertEqual(win_dacl.get_owner(obj_name=self.temp_file), self.current_user)
def test_inheritance(self): """ Test the set_inheritance function Test the get_inheritance function """ self.assertTrue( win_dacl.set_inheritance( obj_name=self.obj_name, enabled=True, obj_type=self.obj_type, clear=False, ) ) self.assertTrue( win_dacl.get_inheritance(obj_name=self.obj_name, obj_type=self.obj_type) ) self.assertTrue( win_dacl.set_inheritance( obj_name=self.obj_name, enabled=False, obj_type=self.obj_type, clear=False, ) ) self.assertFalse( win_dacl.get_inheritance(obj_name=self.obj_name, obj_type=self.obj_type) )
def test_check_perms_reset(self): """ Test resetting perms on a File """ # Turn off inheritance win_dacl.set_inheritance(obj_name=self.temp_file.name, enabled=False, clear=True) # Set some permissions win_dacl.set_permissions(obj_name=self.temp_file.name, principal='Administrator', permissions='full_control') expected = {'comment': '', 'changes': { 'perms': { 'Administrators': {'grant': 'full_control'}, 'Users': {'grant': 'read_execute'}}, 'remove_perms': { 'Administrator': { 'grant': {'applies to': 'Not Inherited (file)', 'permissions': 'Full control'}}}}, 'name': self.temp_file.name, 'result': True} ret = win_file.check_perms( path=self.temp_file, grant_perms={ "Users": {"perms": "read_execute"}, "Administrators": {"perms": "full_control"}, }, inheritance=False, reset=True, ) self.assertDictEqual(expected, ret)
def setUp(self): self.temp_file = tempfile.NamedTemporaryFile(delete=False) self.temp_file.close() win_dacl.set_owner(obj_name=self.temp_file.name, principal=self.current_user) win_dacl.set_inheritance(obj_name=self.temp_file.name, enabled=True) self.assertEqual(win_dacl.get_owner(obj_name=self.temp_file.name), self.current_user)
def test_check_perms_reset_test_true(self): """ Test resetting perms with test=True. This shows minimal changes """ # Turn off inheritance win_dacl.set_inheritance(obj_name=self.temp_file, enabled=False, clear=True) # Set some permissions win_dacl.set_permissions( obj_name=self.temp_file, principal="Administrator", permissions="full_control", ) expected = { "comment": "", "changes": { "perms": { "Administrators": { "grant": "full_control" }, "Users": { "grant": "read_execute" }, }, "remove_perms": { "Administrator": { "grant": { "applies to": "Not Inherited (file)", "permissions": "Full control", } } }, }, "name": self.temp_file, "result": None, } with patch.dict(win_dacl.__opts__, {"test": True}): ret = win_file.check_perms( path=self.temp_file, grant_perms={ "Users": { "perms": "read_execute" }, "Administrators": { "perms": "full_control" }, }, inheritance=False, reset=True, ) self.assertDictEqual(expected, ret)
def test_check_perms_reset(test_file): """ Test resetting perms on a File """ # Turn off inheritance win_dacl.set_inheritance(obj_name=str(test_file), enabled=False, clear=True) # Set some permissions win_dacl.set_permissions( obj_name=str(test_file), principal="Administrator", permissions="full_control", ) expected = { "comment": "", "changes": { "grant_perms": { "Administrators": { "permissions": "full_control" }, "Users": { "permissions": "read_execute" }, }, "remove_perms": { "Administrator": { "grant": { "applies to": "This folder only", "permissions": "Full control", } } }, }, "name": str(test_file), "result": True, } result = win_file.check_perms( path=str(test_file), grant_perms={ "Users": { "perms": "read_execute" }, "Administrators": { "perms": "full_control" }, }, inheritance=False, reset=True, ) assert result == expected
def test_check_perms_reset_test_true(self): ''' Test resetting perms with test=True. This shows minimal changes ''' # Turn off inheritance win_dacl.set_inheritance(obj_name=self.temp_file, enabled=False, clear=True) # Set some permissions win_dacl.set_permissions(obj_name=self.temp_file, principal='Administrator', permissions='full_control') expected = { 'comment': '', 'changes': { 'perms': { 'Administrators': { 'grant': 'full_control' }, 'Users': { 'grant': 'read_execute' } }, 'remove_perms': { 'Administrator': { 'grant': { 'applies to': 'Not Inherited (file)', 'permissions': 'Full control' } } } }, 'name': self.temp_file, 'result': None } with patch.dict(win_dacl.__opts__, {'test': True}): ret = win_file.check_perms(path=self.temp_file, grant_perms={ 'Users': { 'perms': 'read_execute' }, 'Administrators': { 'perms': 'full_control' } }, inheritance=False, reset=True) self.assertDictEqual(expected, ret)
def test_get_set_inheritance(test_file): result = win_dacl.set_inheritance( obj_name=str(test_file), enabled=True, obj_type="file", clear=False, ) assert result is True result = win_dacl.get_inheritance(obj_name=str(test_file), obj_type="file") assert result is True result = win_dacl.set_inheritance( obj_name=str(test_file), enabled=False, obj_type="file", clear=False, ) assert result is True result = win_dacl.get_inheritance(obj_name=str(test_file), obj_type="file") assert result is False
def test_get_set_inheritance(reg_key): result = win_dacl.set_inheritance( obj_name=reg_key, enabled=True, obj_type="registry", clear=False, ) assert result is True result = win_dacl.get_inheritance(obj_name=reg_key, obj_type="registry") assert result is True result = win_dacl.set_inheritance( obj_name=reg_key, enabled=False, obj_type="registry", clear=False, ) assert result is True result = win_dacl.get_inheritance(obj_name=reg_key, obj_type="registry") assert result is False