Example #1
0
def test_check_perms_issue_43328(test_file):
    """
    Make sure that a CommandExecutionError is raised if the file does NOT
    exist
    """
    fake_file = test_file.parent / "fake.file"
    with pytest.raises(CommandExecutionError):
        win_file.check_perms(str(fake_file))
Example #2
0
def test_check_perms_deny_test_true(test_file):
    """
    Test setting deny perms on a file with test=True
    """
    expected = {
        "comment": "",
        "changes": {
            "deny_perms": {
                "Users": {
                    "permissions": "read_execute"
                }
            }
        },
        "name": str(test_file),
        "result": None,
    }
    with patch.dict(win_dacl.__opts__, {"test": True}):
        result = win_file.check_perms(
            path=str(test_file),
            deny_perms={"Users": {
                "perms": "read_execute"
            }},
            inheritance=None,
        )
    assert result == expected
Example #3
0
 def test_check_perms_grant_test_true(self):
     """
     Test setting grant perms on a file with test=True
     """
     expected = {
         "comment": "",
         "changes": {
             "perms": {
                 "Users": {
                     "grant": "read_execute"
                 }
             }
         },
         "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"
             }},
             inheritance=None,
         )
         self.assertDictEqual(expected, ret)
Example #4
0
 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)
Example #5
0
    def test_check_perms_set_owner_test_true(self):
        """
        Test setting the owner of a file with test=True
        '''
        with patch.dict(win_file.__opts__, {'test': True}), \
                patch.dict(win_dacl.__opts__, {'test': True}):
            expected = {'comment': '',
                        'changes': {'owner': 'Administrators'},
                        'name': self.temp_file.name,
                        'result': None}
            ret = win_file.check_perms(path=self.temp_file.name,
                                       owner='Administrators',
                                       inheritance=None)
            self.assertDictEqual(expected, ret)

    def test_check_perms_set_owner(self):
        """
        Test setting the owner of a file
        """
        expected = {
            "comment": "",
            "changes": {"owner": "Administrators"},
            "name": self.temp_file,
            "result": True,
        }
        ret = win_file.check_perms(
            path=self.temp_file, owner="Administrators", inheritance=None
        )
        self.assertDictEqual(expected, ret)

    def test_check_perms_deny_test_true(self):
        """
        Test setting deny perms on a file with test=True
        '''
        expected = {'comment': '',
                    'changes': {'perms': {'Users': {'deny': 'read_execute'}}},
                    'name': self.temp_file.name,
                    'result': None}
        with patch.dict(win_dacl.__opts__, {'test': True}):
            ret = win_file.check_perms(
                path=self.temp_file,
                deny_perms={"Users": {"perms": "read_execute"}},
                inheritance=None,
            )
            self.assertDictEqual(expected, ret)

    def test_check_perms_deny(self):
        """
        Test setting deny perms on a file
        '''
        expected = {'comment': '',
                    'changes': {'perms': {'Users': {'deny': 'read_execute'}}},
                    'name': self.temp_file.name,
                    'result': True}
        ret = win_file.check_perms(
            path=self.temp_file,
            deny_perms={"Users": {"perms": "read_execute"}},
            inheritance=None,
        )
        self.assertDictEqual(expected, ret)
Example #6
0
 def test_check_perms_inheritance_true(self):
     """
     Test setting inheritance to true when it's already true (default)
     """
     expected = {
         "comment": "",
         "changes": {},
         "name": self.temp_file,
         "result": True,
     }
     ret = win_file.check_perms(path=self.temp_file, inheritance=True)
     self.assertDictEqual(ret, expected)
Example #7
0
def test_check_perms_inheritance_true(test_file):
    """
    Test setting inheritance to true when it's already true (default)
    """
    expected = {
        "comment": "",
        "changes": {},
        "name": str(test_file),
        "result": True,
    }
    result = win_file.check_perms(path=str(test_file), inheritance=True)
    assert result == expected
Example #8
0
 def test_check_perms_inheritance_false(self):
     """
     Test setting inheritance to False
     """
     expected = {
         "comment": "",
         "changes": {"inheritance": False},
         "name": self.temp_file,
         "result": True,
     }
     ret = win_file.check_perms(path=self.temp_file, inheritance=False)
     self.assertDictEqual(ret, expected)
Example #9
0
def test_check_perms_inheritance_false(test_file):
    """
    Test setting inheritance to False
    """
    expected = {
        "comment": "",
        "changes": {"inheritance": False},
        "name": str(test_file),
        "result": True,
    }
    result = win_file.check_perms(path=str(test_file), inheritance=False)
    assert result == expected
Example #10
0
 def test_check_perms_inheritance_true(self):
     '''
     Test setting inheritance to true when it's already true (default)
     '''
     expected = {
         'comment': '',
         'changes': {},
         'name': self.temp_file,
         'result': True
     }
     ret = win_file.check_perms(path=self.temp_file, inheritance=True)
     self.assertDictEqual(expected, ret)
Example #11
0
 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)
Example #12
0
def test_check_perms_inheritance_false_test_true(test_file):
    """
    Test setting inheritance to False with test=True
    """
    expected = {
        "comment": "",
        "changes": {"inheritance": False},
        "name": str(test_file),
        "result": None,
    }
    with patch.dict(win_dacl.__opts__, {"test": True}):
        result = win_file.check_perms(path=str(test_file), inheritance=False)
    assert result == expected
Example #13
0
 def test_check_perms_inheritance_false_test_true(self):
     """
     Test setting inheritance to False with test=True
     """
     expected = {
         "comment": "",
         "changes": {"inheritance": False},
         "name": self.temp_file,
         "result": None,
     }
     with patch.dict(win_dacl.__opts__, {"test": True}):
         ret = win_file.check_perms(path=self.temp_file, inheritance=False)
         self.assertDictEqual(ret, expected)
Example #14
0
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
Example #15
0
 def test_check_perms_inheritance_false(self):
     '''
     Test setting inheritance to False
     '''
     expected = {
         'comment': '',
         'changes': {
             'inheritance': False
         },
         'name': self.temp_file,
         'result': True
     }
     ret = win_file.check_perms(path=self.temp_file, inheritance=False)
     self.assertDictEqual(expected, ret)
Example #16
0
 def test_check_perms_set_owner(self):
     """
     Test setting the owner of a file
     """
     expected = {
         "comment": "",
         "changes": {"owner": "Administrators"},
         "name": self.temp_file,
         "result": True,
     }
     ret = win_file.check_perms(
         path=self.temp_file, owner="Administrators", inheritance=None
     )
     self.assertDictEqual(ret, expected)
Example #17
0
def test_check_perms_set_owner(test_file):
    """
    Test setting the owner of a file
    """
    expected = {
        "comment": "",
        "changes": {"owner": "Backup Operators"},
        "name": str(test_file),
        "result": True,
    }
    result = win_file.check_perms(
        path=str(test_file), owner="Backup Operators", inheritance=None
    )
    assert result == expected
Example #18
0
 def test_check_perms_inheritance_false_test_true(self):
     '''
     Test setting inheritance to False with test=True
     '''
     expected = {
         'comment': '',
         'changes': {
             'inheritance': False
         },
         'name': self.temp_file,
         'result': None
     }
     with patch.dict(win_dacl.__opts__, {'test': True}):
         ret = win_file.check_perms(path=self.temp_file, inheritance=False)
         self.assertDictEqual(expected, ret)
Example #19
0
 def test_check_perms_set_owner_test_true(self):
     """
     Test setting the owner of a file with test=True
     """
     expected = {
         "comment": "",
         "changes": {"owner": "Administrators"},
         "name": self.temp_file,
         "result": None,
     }
     with patch.dict(win_dacl.__opts__, {"test": True}):
         ret = win_file.check_perms(
             path=self.temp_file, owner="Administrators", inheritance=None
         )
         self.assertDictEqual(ret, expected)
Example #20
0
def test_check_perms_set_owner_test_true(test_file):
    """
    Test setting the owner of a file with test=True
    """
    expected = {
        "comment": "",
        "changes": {"owner": "Backup Operators"},
        "name": str(test_file),
        "result": None,
    }
    with patch.dict(win_dacl.__opts__, {"test": True}):
        result = win_file.check_perms(
            path=str(test_file), owner="Backup Operators", inheritance=None
        )
        assert result == expected
Example #21
0
 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)
Example #22
0
 def test_check_perms_set_owner(self):
     '''
     Test setting the owner of a file
     '''
     expected = {
         'comment': '',
         'changes': {
             'owner': 'Administrators'
         },
         'name': self.temp_file,
         'result': True
     }
     ret = win_file.check_perms(path=self.temp_file,
                                owner='Administrators',
                                inheritance=None)
     self.assertDictEqual(expected, ret)
Example #23
0
def test_check_perms_deny(test_file):
    """
    Test setting deny perms on a file
    """
    expected = {
        "comment": "",
        "changes": {"deny_perms": {"Users": {"permissions": "read_execute"}}},
        "name": str(test_file),
        "result": True,
    }
    result = win_file.check_perms(
        path=str(test_file),
        deny_perms={"Users": {"perms": "read_execute"}},
        inheritance=None,
    )
    assert result == expected
Example #24
0
 def test_check_perms_grant(self):
     """
     Test setting grant perms on a file
     """
     expected = {
         "comment": "",
         "changes": {"grant_perms": {"Users": {"permissions": "read_execute"}}},
         "name": self.temp_file,
         "result": True,
     }
     ret = win_file.check_perms(
         path=self.temp_file,
         grant_perms={"Users": {"perms": "read_execute"}},
         inheritance=None,
     )
     self.assertDictEqual(ret, expected)
Example #25
0
 def test_check_perms_set_owner_test_true(self):
     '''
     Test setting the owner of a file with test=True
     '''
     expected = {
         'comment': '',
         'changes': {
             'owner': 'Administrators'
         },
         'name': self.temp_file,
         'result': None
     }
     with patch.dict(win_dacl.__opts__, {'test': True}):
         ret = win_file.check_perms(path=self.temp_file,
                                    owner='Administrators',
                                    inheritance=None)
         self.assertDictEqual(expected, ret)
Example #26
0
    def test_check_perms_grant_test_true(self):
        """
        Test setting grant perms on a file with test=True
        '''
        expected = {'comment': '',
                    'changes': {'perms': {'Users': {'grant': 'read_execute'}}},
                    'name': self.temp_file.name,
                    '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"}},
                inheritance=None,
            )
            self.assertDictEqual(expected, ret)

    def test_check_perms_grant(self):
        """
        Test setting grant perms on a file
        '''
        expected = {'comment': '',
                    'changes': {'perms': {'Users': {'grant': 'read_execute'}}},
                    'name': self.temp_file.name,
                    'result': True}
        ret = win_file.check_perms(
            path=self.temp_file,
            grant_perms={"Users": {"perms": "read_execute"}},
            inheritance=None,
        )
        self.assertDictEqual(expected, ret)

    def test_check_perms_inheritance_false_test_true(self):
        """
        Test setting inheritance to False with test=True
        '''
        expected = {'comment': '',
                    'changes': {'inheritance': False},
                    'name': self.temp_file.name,
                    'result': None}
        with patch.dict(win_dacl.__opts__, {'test': True}):
            ret = win_file.check_perms(path=self.temp_file.name,
                                       inheritance=False)
            self.assertDictEqual(expected, ret)
Example #27
0
 def test_check_perms_grant(self):
     '''
     Test setting grant perms on a file
     '''
     expected = {
         'comment': '',
         'changes': {
             'perms': {
                 'Users': {
                     'grant': 'read_execute'
                 }
             }
         },
         'name': self.temp_file,
         'result': True
     }
     ret = win_file.check_perms(
         path=self.temp_file,
         grant_perms={'Users': {
             'perms': 'read_execute'
         }},
         inheritance=None)
     self.assertDictEqual(expected, ret)
Example #28
0
 def test_check_perms_grant_test_true(self):
     '''
     Test setting grant perms on a file with test=True
     '''
     expected = {
         'comment': '',
         'changes': {
             'perms': {
                 'Users': {
                     'grant': 'read_execute'
                 }
             }
         },
         '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'
             }},
             inheritance=None)
         self.assertDictEqual(expected, ret)
Example #29
0
 def test_check_perms_deny(self):
     """
     Test setting deny perms on a file
     """
     expected = {
         "comment": "",
         "changes": {
             "perms": {
                 "Users": {
                     "deny": "read_execute"
                 }
             }
         },
         "name": self.temp_file,
         "result": True,
     }
     ret = win_file.check_perms(
         path=self.temp_file,
         deny_perms={"Users": {
             "perms": "read_execute"
         }},
         inheritance=None,
     )
     self.assertDictEqual(expected, ret)