예제 #1
0
 def test_rm_permissions(self):
     """
     Test the rm_permissions function
     """
     self.assertTrue(
         win_dacl.set_permissions(
             obj_name=self.obj_name,
             principal="Backup Operators",
             permissions="full_control",
             access_mode="grant",
             obj_type=self.obj_type,
             reset_perms=False,
             protected=None,
         ))
     self.assertTrue(
         win_dacl.rm_permissions(
             obj_name=self.obj_name,
             principal="Backup Operators",
             obj_type=self.obj_type,
         ))
     self.assertEqual(
         win_dacl.get_permissions(
             obj_name=self.obj_name,
             principal="Backup Operators",
             obj_type=self.obj_type,
         ),
         {},
     )
예제 #2
0
 def test_get_permissions(self):
     """
     Test the get_permissions function
     """
     self.assertTrue(
         win_dacl.set_permissions(
             obj_name=self.obj_name,
             principal="Backup Operators",
             permissions="full_control",
             access_mode="grant",
             obj_type=self.obj_type,
             reset_perms=False,
             protected=None,
         ))
     expected = {
         "Not Inherited": {
             "Backup Operators": {
                 "grant": {
                     "applies to": "Not Inherited (file)",
                     "permissions": "Full control",
                 }
             }
         }
     }
     self.assertEqual(
         win_dacl.get_permissions(
             obj_name=self.obj_name,
             principal="Backup Operators",
             obj_type=self.obj_type,
         ),
         expected,
     )
예제 #3
0
    def test_check_perms_test_true(self):
        """
        Test the check_perms function
        """
        with patch.dict(win_dacl.__opts__, {"test": True}):
            result = win_dacl.check_perms(
                obj_name=self.obj_name,
                obj_type=self.obj_type,
                ret=None,
                owner="Users",
                grant_perms={"Backup Operators": {
                    "perms": "read"
                }},
                deny_perms={
                    "NETWORK SERVICE": {
                        "perms":
                        ["delete", "set_value", "write_dac", "write_owner"]
                    },
                    "Backup Operators": {
                        "perms": ["delete"]
                    },
                },
                inheritance=True,
                reset=False,
            )

        expected = {
            "changes": {
                "owner": "Users",
                "perms": {
                    "Backup Operators": {
                        "grant": "read",
                        "deny": ["delete"]
                    },
                    "NETWORK SERVICE": {
                        "deny":
                        ["delete", "set_value", "write_dac", "write_owner"]
                    },
                },
            },
            "comment": "",
            "name": self.obj_name,
            "result": None,
        }
        self.assertDictEqual(result, expected)

        self.assertNotEqual(
            win_dacl.get_owner(obj_name=self.obj_name, obj_type=self.obj_type),
            "Users")

        self.assertEqual(
            win_dacl.get_permissions(
                obj_name=self.obj_name,
                principal="Backup Operators",
                obj_type=self.obj_type,
            ),
            {},
        )
예제 #4
0
    def test_check_perms(self):
        """
        Test the check_perms function
        """
        with patch.dict(win_dacl.__opts__, {"test": False}):
            result = win_dacl.check_perms(
                obj_name=self.obj_name,
                obj_type=self.obj_type,
                ret={},
                owner="Users",
                grant_perms={"Backup Operators": {
                    "perms": "read"
                }},
                deny_perms={
                    "Backup Operators": {
                        "perms": ["delete"]
                    },
                    "NETWORK SERVICE": {
                        "perms": [
                            "delete",
                            "change_permissions",
                            "write_attributes",
                            "write_data",
                        ]
                    },
                },
                inheritance=True,
                reset=False,
            )

        expected = {
            "changes": {
                "owner": "Users",
                "perms": {
                    "Backup Operators": {
                        "grant": "read",
                        "deny": ["delete"]
                    },
                    "NETWORK SERVICE": {
                        "deny": [
                            "delete",
                            "change_permissions",
                            "write_attributes",
                            "write_data",
                        ]
                    },
                },
            },
            "comment": "",
            "name": self.obj_name,
            "result": True,
        }
        self.assertDictEqual(result, expected)

        expected = {
            "Not Inherited": {
                "Backup Operators": {
                    "grant": {
                        "applies to": "Not Inherited (file)",
                        "permissions": "Read",
                    },
                    "deny": {
                        "applies to": "Not Inherited (file)",
                        "permissions": ["Delete"],
                    },
                }
            }
        }
        self.assertDictEqual(
            win_dacl.get_permissions(
                obj_name=self.obj_name,
                principal="Backup Operators",
                obj_type=self.obj_type,
            ),
            expected,
        )

        expected = {
            "Not Inherited": {
                "NETWORK SERVICE": {
                    "deny": {
                        "applies to":
                        "Not Inherited (file)",
                        "permissions": [
                            "Change permissions",
                            "Create files / write data",
                            "Delete",
                            "Write attributes",
                        ],
                    }
                }
            }
        }
        self.assertDictEqual(
            win_dacl.get_permissions(
                obj_name=self.obj_name,
                principal="NETWORK SERVICE",
                obj_type=self.obj_type,
            ),
            expected,
        )

        self.assertEqual(
            win_dacl.get_owner(obj_name=self.obj_name, obj_type=self.obj_type),
            "Users")