Ejemplo n.º 1
0
def test_present_perms(reg_vars, clean):
    reg.present(
        name=reg_vars.name,
        vname=reg_vars.vname,
        vdata=reg_vars.vdata,
        win_perms={"Backup Operators": {
            "perms": "full_control"
        }},
        win_deny_perms={"Guest": {
            "perms": "full_control"
        }},
    )
    permissions = win_dacl.get_permissions(obj_name=reg_vars.name,
                                           obj_type="registry")
    expected = {
        "deny": {
            "permissions": "Full Control",
            "applies to": "This key and subkeys"
        }
    }
    assert permissions["Not Inherited"].get("Guest") == expected
    expected = {
        "grant": {
            "permissions": "Full Control",
            "applies to": "This key and subkeys"
        }
    }
    assert permissions["Not Inherited"].get("Backup Operators") == expected
Ejemplo n.º 2
0
def test_present_perms_reset_no_inherit(reg_vars, clean):
    reg.present(
        name=reg_vars.name,
        vname=reg_vars.vname,
        vdata=reg_vars.vdata,
        win_perms={"Everyone": {
            "perms": "full_control"
        }},
        win_deny_perms={"Guest": {
            "perms": "full_control"
        }},
        win_perms_reset=True,
        win_inheritance=False,
    )
    permissions = win_dacl.get_permissions(obj_name=reg_vars.name,
                                           obj_type="registry")
    expected = {
        "Guest": {
            "deny": {
                "permissions": "Full Control",
                "applies to": "This key and subkeys",
            }
        },
        "Everyone": {
            "grant": {
                "permissions": "Full Control",
                "applies to": "This key and subkeys",
            }
        },
    }
    assert permissions["Not Inherited"] == expected
    assert not win_dacl.get_inheritance(obj_name=reg_vars.name,
                                        obj_type="registry")
    assert permissions["Inherited"] == {}
Ejemplo n.º 3
0
    def test_present(self):
        '''
        Test to set a registry entry.
        '''
        name = 'HKEY_CURRENT_USER\\SOFTWARE\\Salt\\version'
        value = '0.15.3'

        ret = {'name': name,
               'changes': {},
               'result': True,
               'comment': '{0} is already configured'.format(name)}

        mock = MagicMock(side_effect=[value, 'a', 'a'])
        mock_t = MagicMock(return_value=True)
        with patch.dict(reg.__salt__, {'reg.read_key': mock,
                                       'reg.set_key': mock_t}):
            self.assertDictEqual(reg.present(name, value), ret)

            with patch.dict(reg.__opts__, {'test': True}):
                ret.update({'comment': '', 'result': None,
                            'changes': {'reg': 'configured to 0.15.3'}})
                self.assertDictEqual(reg.present(name, value), ret)

            with patch.dict(reg.__opts__, {'test': False}):
                ret.update({'result': True})
                self.assertDictEqual(reg.present(name, value), ret)
Ejemplo n.º 4
0
    def test_present(self):
        '''
        Test to set a registry entry.
        '''
        name = 'HKEY_CURRENT_USER\\SOFTWARE\\Salt\\version'
        value = '0.15.3'

        ret = {
            'name': name,
            'changes': {},
            'result': True,
            'comment': '{0} is already configured'.format(name)
        }

        mock = MagicMock(side_effect=[value, 'a', 'a'])
        mock_t = MagicMock(return_value=True)
        with patch.dict(reg.__salt__, {
                'reg.read_key': mock,
                'reg.set_key': mock_t
        }):
            self.assertDictEqual(reg.present(name, value), ret)

            with patch.dict(reg.__opts__, {'test': True}):
                ret.update({
                    'comment': '',
                    'result': None,
                    'changes': {
                        'reg': 'configured to 0.15.3'
                    }
                })
                self.assertDictEqual(reg.present(name, value), ret)

            with patch.dict(reg.__opts__, {'test': False}):
                ret.update({'result': True})
                self.assertDictEqual(reg.present(name, value), ret)
Ejemplo n.º 5
0
def test_present_perms_no_inherit(reg_vars, clean):
    reg.present(
        name=reg_vars.name,
        vname=reg_vars.vname,
        vdata=reg_vars.vdata,
        win_inheritance=False,
    )
    assert not win_dacl.get_inheritance(obj_name=reg_vars.name,
                                        obj_type="registry")
    permissions = win_dacl.get_permissions(obj_name=reg_vars.name,
                                           obj_type="registry")
    assert permissions["Inherited"] == {}
Ejemplo n.º 6
0
def test_present_set_owner(reg_vars, clean):
    """
    Test reg.present
    """
    reg.present(
        name=reg_vars.name,
        vname=reg_vars.vname,
        vdata=reg_vars.vdata,
        win_owner=reg_vars.current_user,
    )
    assert (win_dacl.get_owner(obj_name=reg_vars.name,
                               obj_type="registry") == reg_vars.current_user)
Ejemplo n.º 7
0
def test_present_string_dword(reg_vars, clean):
    """
    Test to set a registry entry.
    """
    vname = "dword_data"
    vdata = "00000001"
    vtype = "REG_DWORD"
    expected_vdata = 1
    expected = {
        "comment": "Added {} to {}".format(vname, reg_vars.name),
        "changes": {
            "reg": {
                "Added": {
                    "Inheritance": True,
                    "Perms": {
                        "Deny": None,
                        "Grant": None
                    },
                    "Value": expected_vdata,
                    "Key": reg_vars.name,
                    "Owner": None,
                    "Entry": vname,
                }
            }
        },
        "name": reg_vars.name,
        "result": True,
    }
    assert (reg.present(name=reg_vars.name,
                        vname=vname,
                        vdata=vdata,
                        vtype=vtype) == expected)
Ejemplo n.º 8
0
 def test_present_string_dword(self):
     """
     Test to set a registry entry.
     """
     vname = "dword_data"
     vdata = "00000001"
     vtype = "REG_DWORD"
     expected_vdata = 1
     expected = {
         "comment": "Added {0} to {1}".format(vname, self.name),
         "pchanges": {},
         "changes": {
             "reg": {
                 "Added": {
                     "Inheritance": True,
                     "Perms": {
                         "Deny": None,
                         "Grant": None
                     },
                     "Value": expected_vdata,
                     "Key": self.name,
                     "Owner": None,
                     "Entry": vname,
                 }
             }
         },
         "name": self.name,
         "result": True,
     }
     ret = reg.present(self.name, vname=vname, vdata=vdata, vtype=vtype)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 9
0
 def test_present_string_dword(self):
     '''
     Test to set a registry entry.
     '''
     vname = 'dword_data'
     vdata = '00000001'
     vtype = 'REG_DWORD'
     expected_vdata = 1
     expected = {
         'comment': 'Added {0} to {1}'.format(vname, self.name),
         'pchanges': {},
         'changes': {
             'reg': {
                 'Added': {
                     'Inheritance': True,
                     'Perms': {
                         'Deny': None,
                         'Grant': None
                     },
                     'Value': expected_vdata,
                     'Key': self.name,
                     'Owner': None,
                     'Entry': vname
                 }
             }
         },
         'name': self.name,
         'result': True
     }
     ret = reg.present(self.name, vname=vname, vdata=vdata, vtype=vtype)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 10
0
def test_present(reg_vars):
    """
    Test reg.present
    """
    expected = {
        "comment": "Added {} to {}".format(reg_vars.vname, reg_vars.name),
        "changes": {
            "reg": {
                "Added": {
                    "Inheritance": True,
                    "Perms": {
                        "Deny": None,
                        "Grant": None
                    },
                    "Value": reg_vars.vdata,
                    "Key": reg_vars.name,
                    "Owner": None,
                    "Entry": reg_vars.vname,
                }
            }
        },
        "name": reg_vars.name,
        "result": True,
    }
    assert (reg.present(name=reg_vars.name,
                        vname=reg_vars.vname,
                        vdata=reg_vars.vdata) == expected)
    permissions = win_dacl.get_permissions(obj_name=reg_vars.name,
                                           obj_type="registry")
    assert permissions["Not Inherited"] == {}
Ejemplo n.º 11
0
def test_present_test_true(reg_vars, clean):
    expected = {
        "comment": "",
        "changes": {
            "reg": {
                "Will add": {
                    "Inheritance": True,
                    "Perms": {
                        "Deny": None,
                        "Grant": None
                    },
                    "Value": reg_vars.vdata,
                    "Key": reg_vars.name,
                    "Owner": None,
                    "Entry": "version",
                }
            }
        },
        "name": reg_vars.name,
        "result": None,
    }
    with patch.dict(reg.__opts__, {"test": True}):
        ret = reg.present(reg_vars.name,
                          vname=reg_vars.vname,
                          vdata=reg_vars.vdata)
    assert ret == expected
Ejemplo n.º 12
0
 def test_present_test_true(self):
     expected = {
         'comment': '',
         'pchanges': {},
         'changes': {
             'reg': {
                 'Will add': {
                     'Inheritance': True,
                     'Perms': {
                         'Deny': None,
                         'Grant': None
                     },
                     'Value': self.vdata,
                     'Key': self.name,
                     'Owner': None,
                     'Entry': 'version'
                 }
             }
         },
         'name': self.name,
         'result': None
     }
     with patch.dict(reg.__opts__, {'test': True}):
         ret = reg.present(self.name, vname=self.vname, vdata=self.vdata)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 13
0
 def test_present(self):
     '''
     Test to set a registry entry.
     '''
     expected = {
         'comment': 'Added {0} to {1}'.format(self.vname, self.name),
         'pchanges': {},
         'changes': {
             'reg': {
                 'Added': {
                     'Inheritance': True,
                     'Perms': {
                         'Deny': None,
                         'Grant': None
                     },
                     'Value': self.vdata,
                     'Key': self.name,
                     'Owner': None,
                     'Entry': self.vname
                 }
             }
         },
         'name': self.name,
         'result': True
     }
     ret = reg.present(self.name, vname=self.vname, vdata=self.vdata)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 14
0
 def test_present_test_true(self):
     expected = {
         "comment": "",
         "pchanges": {},
         "changes": {
             "reg": {
                 "Will add": {
                     "Inheritance": True,
                     "Perms": {
                         "Deny": None,
                         "Grant": None
                     },
                     "Value": self.vdata,
                     "Key": self.name,
                     "Owner": None,
                     "Entry": "version",
                 }
             }
         },
         "name": self.name,
         "result": None,
     }
     with patch.dict(reg.__opts__, {"test": True}):
         ret = reg.present(self.name, vname=self.vname, vdata=self.vdata)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 15
0
 def test_present(self):
     """
     Test to set a registry entry.
     """
     expected = {
         "comment": "Added {0} to {1}".format(self.vname, self.name),
         "pchanges": {},
         "changes": {
             "reg": {
                 "Added": {
                     "Inheritance": True,
                     "Perms": {
                         "Deny": None,
                         "Grant": None
                     },
                     "Value": self.vdata,
                     "Key": self.name,
                     "Owner": None,
                     "Entry": self.vname,
                 }
             }
         },
         "name": self.name,
         "result": True,
     }
     ret = reg.present(self.name, vname=self.vname, vdata=self.vdata)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 16
0
 def test_present_string_dword_existing(self):
     """
     Test to set a registry entry.
     """
     vname = "dword_data"
     vdata = "0000001"
     vtype = "REG_DWORD"
     # Set it first
     reg.present(self.name, vname=vname, vdata=vdata, vtype=vtype)
     expected = {
         "comment": "{} in {} is already present".format(vname, self.name),
         "changes": {},
         "name": self.name,
         "result": True,
     }
     ret = reg.present(self.name, vname=vname, vdata=vdata, vtype=vtype)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 17
0
 def test_present_string_dword_existing(self):
     '''
     Test to set a registry entry.
     '''
     vname = 'dword_data'
     vdata = '0000001'
     vtype = 'REG_DWORD'
     # Set it first
     reg.present(self.name, vname=vname, vdata=vdata, vtype=vtype)
     expected = {
         'comment':
         '{0} in {1} is already present'.format(vname, self.name),
         'pchanges': {},
         'changes': {},
         'name': self.name,
         'result': True
     }
     ret = reg.present(self.name, vname=vname, vdata=vdata, vtype=vtype)
     self.assertDictEqual(ret, expected)
Ejemplo n.º 18
0
    def test_present(self):
        '''
        Test to set a registry entry.
        '''
        name = 'HKEY_CURRENT_USER\\SOFTWARE\\Salt'
        vname = 'version'
        vdata = '0.15.3'

        ret = {'name': name,
               'changes': {},
               'result': True,
               'comment': '{0} in {1} is already configured'.format(vname, name)}

        mock_read = MagicMock(side_effect=[{'vdata': vdata, 'success': True},
                                           {'vdata': 'a', 'success': True},
                                           {'vdata': 'a', 'success': True}])
        mock_t = MagicMock(return_value=True)
        with patch.dict(reg.__salt__, {'reg.read_value': mock_read,
                                       'reg.set_value': mock_t}):
            self.assertDictEqual(reg.present(name,
                                             vname=vname,
                                             vdata=vdata), ret)

            with patch.dict(reg.__opts__, {'test': True}):
                ret.update({'comment': '', 'result': None,
                            'changes': {'reg': {'Will add': {'Key': name,
                                                             'Entry': vname,
                                                             'Value': vdata}}}})
                self.assertDictEqual(reg.present(name,
                                                 vname=vname,
                                                 vdata=vdata), ret)

            with patch.dict(reg.__opts__, {'test': False}):
                ret.update({'comment': 'Added {0} to {0}'.format(name),
                            'result': True,
                            'changes': {'reg': {'Added': {'Key': name,
                                                          'Entry': vname,
                                                          'Value': vdata}}}})
                self.assertDictEqual(reg.present(name,
                                                 vname=vname,
                                                 vdata=vdata), ret)
Ejemplo n.º 19
0
    def test_present(self):
        '''
        Test to set a registry entry.
        '''
        name = 'HKEY_CURRENT_USER\\SOFTWARE\\Salt'
        vname = 'version'
        vdata = '0.15.3'

        ret = {'name': name,
               'changes': {},
               'result': True,
               'comment': '{0} in {1} is already configured'.format(vname, name)}

        mock_read = MagicMock(side_effect=[{'vdata': vdata, 'success': True},
                                           {'vdata': 'a', 'success': True},
                                           {'vdata': 'a', 'success': True}])
        mock_t = MagicMock(return_value=True)
        with patch.dict(reg.__salt__, {'reg.read_value': mock_read,
                                       'reg.set_value': mock_t}):
            self.assertDictEqual(reg.present(name,
                                             vname=vname,
                                             vdata=vdata), ret)

            with patch.dict(reg.__opts__, {'test': True}):
                ret.update({'comment': '', 'result': None,
                            'changes': {'reg': {'Will add': {'Key': name,
                                                             'Entry': vname,
                                                             'Value': vdata}}}})
                self.assertDictEqual(reg.present(name,
                                                 vname=vname,
                                                 vdata=vdata), ret)

            with patch.dict(reg.__opts__, {'test': False}):
                ret.update({'comment': 'Added {0} to {0}'.format(name),
                            'result': True,
                            'changes': {'reg': {'Added': {'Key': name,
                                                          'Entry': vname,
                                                          'Value': vdata}}}})
                self.assertDictEqual(reg.present(name,
                                                 vname=vname,
                                                 vdata=vdata), ret)
Ejemplo n.º 20
0
def test_present_existing(reg_vars, reset):
    expected = {
        "comment":
        "{} in {} is already present".format(reg_vars.vname, reg_vars.name),
        "changes": {},
        "name":
        reg_vars.name,
        "result":
        True,
    }
    assert (reg.present(name=reg_vars.name,
                        vname=reg_vars.vname,
                        vdata=reg_vars.vdata) == expected)
Ejemplo n.º 21
0
def test_present_existing_key_only(reg_vars, clean):
    """
    Test setting only a key with no value name
    """
    # Create the reg key for testing
    reg_util.set_value(hive=reg_vars.hive, key=reg_vars.key)

    expected = {
        "comment": "(Default) in {} is already present".format(reg_vars.name),
        "changes": {},
        "name": reg_vars.name,
        "result": True,
    }
    assert reg.present(reg_vars.name) == expected
Ejemplo n.º 22
0
def test_present_existing_test_true(reg_vars, reset):
    expected = {
        "comment":
        "{} in {} is already present".format(reg_vars.vname, reg_vars.name),
        "changes": {},
        "name":
        reg_vars.name,
        "result":
        True,
    }
    with patch.dict(reg.__opts__, {"test": True}):
        ret = reg.present(name=reg_vars.name,
                          vname=reg_vars.vname,
                          vdata=reg_vars.vdata)
    assert ret == expected
Ejemplo n.º 23
0
    def test_present_existing_key_only(self):
        """
        Test setting only a key with no value name
        """
        # Create the reg key for testing
        salt.utils.win_reg.set_value(hive=self.hive, key=self.key)

        expected = {
            "comment": "(Default) in {0} is already present".format(self.name),
            "changes": {},
            "name": self.name,
            "result": True,
        }
        ret = reg.present(self.name)
        self.assertDictEqual(ret, expected)
Ejemplo n.º 24
0
    def test_present_existing(self):
        # Create the reg key for testing
        salt.utils.win_reg.set_value(hive=self.hive,
                                     key=self.key,
                                     vname=self.vname,
                                     vdata=self.vdata)

        expected = {
            "comment":
            "{} in {} is already present".format(self.vname, self.name),
            "changes": {},
            "name": self.name,
            "result": True,
        }
        ret = reg.present(self.name, vname=self.vname, vdata=self.vdata)
        self.assertDictEqual(ret, expected)
Ejemplo n.º 25
0
    def test_present_existing(self):
        # Create the reg key for testing
        salt.utils.win_reg.set_value(hive=self.hive,
                                     key=self.key,
                                     vname=self.vname,
                                     vdata=self.vdata)

        expected = {
            'comment':
            '{0} in {1} is already present'.format(self.vname, self.name),
            'changes': {},
            'name':
            self.name,
            'result':
            True
        }
        ret = reg.present(self.name, vname=self.vname, vdata=self.vdata)
        self.assertDictEqual(ret, expected)
Ejemplo n.º 26
0
    def test_present_existing_test_true(self):
        # Create the reg key for testing
        salt.utils.win_reg.set_value(hive=self.hive,
                                     key=self.key,
                                     vname=self.vname,
                                     vdata=self.vdata)

        expected = {
            "comment":
            "{0} in {1} is already present".format(self.vname, self.name),
            "pchanges": {},
            "changes": {},
            "name":
            self.name,
            "result":
            True,
        }
        with patch.dict(reg.__opts__, {"test": True}):
            ret = reg.present(self.name, vname=self.vname, vdata=self.vdata)
        self.assertDictEqual(ret, expected)
Ejemplo n.º 27
0
def test_present_string_dword_existing(reg_vars, clean):
    """
    Test to set a registry entry.
    """
    vname = "dword_data"
    vdata = "0000001"
    vtype = "REG_DWORD"
    # Set it first
    reg_util.set_value(hive=reg_vars.hive,
                       key=reg_vars.key,
                       vname=vname,
                       vdata=vdata,
                       vtype=vtype)
    expected = {
        "comment": "{} in {} is already present".format(vname, reg_vars.name),
        "changes": {},
        "name": reg_vars.name,
        "result": True,
    }
    assert (reg.present(name=reg_vars.name,
                        vname=vname,
                        vdata=vdata,
                        vtype=vtype) == expected)