Esempio n. 1
0
    def test_members(self):
        '''
        Test if it remove a user to a group
        '''
        comment = ['Failure accessing group dc=foo.  C']
        ret = {
            'name': 'dc=foo',
            'result': False,
            'comment': comment,
            'changes': {
                'Users Added': [],
                'Users Removed': []
            }
        }

        with patch(win_groupadd.win32.client, 'flag', 2):
            self.assertDictEqual(
                win_groupadd.members('dc=foo',
                                     'dc=\\user1,dc=\\user2,dc=\\user3'), ret)

        with patch(win_groupadd.win32.client, 'flag', 1):
            comment = [
                'Failed to add dc=\\user2 to dc=foo.  C',
                'Failed to remove dc=\\user1 from dc=foo.  C'
            ]
            ret.update({'comment': comment, 'result': False})
            self.assertDictEqual(win_groupadd.members('dc=foo', 'dc=\\user2'),
                                 ret)

        with patch(win_groupadd.win32.client, 'flag', None):
            comment = ['dc=foo membership is correct']
            ret.update({'comment': comment, 'result': None})
            self.assertDictEqual(win_groupadd.members('dc=foo', 'dc=\\user1'),
                                 ret)
Esempio n. 2
0
 def test_members_group_does_not_exist(self):
     '''
     Test adding a list of users where the group does not exist
     '''
     obj_group_mock = MagicMock(side_effect=PYWINTYPES_ERROR)
     with patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock),\
             patch.object(win_groupadd, '_get_group_object', obj_group_mock):
         self.assertFalse(win_groupadd.members('foo', 'spongebob'))
Esempio n. 3
0
 def test_members_group_does_not_exist(self):
     """
     Test adding a list of users where the group does not exist
     """
     obj_group_mock = MagicMock(side_effect=PYWINTYPES_ERROR)
     with patch.object(
         salt.utils.win_functions, "get_sam_name", self.sam_mock
     ), patch.object(win_groupadd, "_get_group_object", obj_group_mock):
         self.assertFalse(win_groupadd.members("foo", "spongebob"))
Esempio n. 4
0
 def test_members(self):
     '''
     Test adding a list of members to a group, all existing users removed
     '''
     obj_group_mock = MagicMock(
         return_value=MockGroupObj('foo', ['WinNT://HOST/steve']))
     with patch.object(win_groupadd, '_get_group_object', obj_group_mock), \
             patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock):
         self.assertTrue(
             win_groupadd.members('foo', 'spongebob,patrick,squidward'))
         obj_group_mock.assert_called_once_with('foo')
Esempio n. 5
0
 def test_members(self):
     """
     Test adding a list of members to a group, all existing users removed
     """
     obj_group_mock = MagicMock(
         return_value=MockGroupObj("foo", ["WinNT://HOST/steve"])
     )
     with patch.object(
         win_groupadd, "_get_group_object", obj_group_mock
     ), patch.object(salt.utils.win_functions, "get_sam_name", self.sam_mock):
         self.assertTrue(win_groupadd.members("foo", "spongebob,patrick,squidward"))
         obj_group_mock.assert_called_once_with("foo")
Esempio n. 6
0
    def test_members_fail_to_add(self):
        '''
        Test adding a list of members and failing to add
        '''
        class GroupObj(MockGroupObj):
            def Add(self, name):
                raise PYWINTYPES_ERROR

        obj_group_mock = MagicMock(
            return_value=GroupObj('foo', ['WinNT://HOST/spongebob']))
        with patch.object(win_groupadd, '_get_group_object', obj_group_mock), \
                patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock):
            self.assertFalse(win_groupadd.members('foo', 'patrick'))
            obj_group_mock.assert_called_once_with('foo')
Esempio n. 7
0
    def test_members(self):
        '''
        Test if it remove a user to a group
        '''
        comment = ['Failure accessing group dc=foo.  C']
        ret = {'name': 'dc=foo', 'result': False, 'comment': comment,
               'changes': {'Users Added': [], 'Users Removed': []}}

        with patch(win_groupadd.win32.client, 'flag', 2):
            self.assertDictEqual(win_groupadd.members
                                 ('dc=foo', 'dc=\\user1,dc=\\user2,dc=\\user3'),
                                 ret)

        with patch(win_groupadd.win32.client, 'flag', 1):
            comment = ['Failed to add dc=\\user2 to dc=foo.  C',
                       'Failed to remove dc=\\user1 from dc=foo.  C']
            ret.update({'comment': comment, 'result': False})
            self.assertDictEqual(win_groupadd.members('dc=foo', 'dc=\\user2'), ret)

        with patch(win_groupadd.win32.client, 'flag', None):
            comment = ['dc=foo membership is correct']
            ret.update({'comment': comment, 'result': None})
            self.assertDictEqual(win_groupadd.members('dc=foo', 'dc=\\user1'), ret)
Esempio n. 8
0
 def test_members_correct_membership(self):
     '''
     Test adding a list of users where the list of users already exists
     '''
     members_list = [
         'WinNT://HOST/spongebob', 'WinNT://HOST/squidward',
         'WinNT://HOST/patrick'
     ]
     obj_group_mock = MagicMock(
         return_value=MockGroupObj('foo', members_list))
     with patch.object(win_groupadd, '_get_group_object', obj_group_mock), \
             patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock):
         self.assertTrue(
             win_groupadd.members('foo', 'spongebob,patrick,squidward'))
         obj_group_mock.assert_called_once_with('foo')
Esempio n. 9
0
 def test_members_correct_membership(self):
     """
     Test adding a list of users where the list of users already exists
     """
     members_list = [
         "WinNT://HOST/spongebob",
         "WinNT://HOST/squidward",
         "WinNT://HOST/patrick",
     ]
     obj_group_mock = MagicMock(return_value=MockGroupObj("foo", members_list))
     with patch.object(
         win_groupadd, "_get_group_object", obj_group_mock
     ), patch.object(salt.utils.win_functions, "get_sam_name", self.sam_mock):
         self.assertTrue(win_groupadd.members("foo", "spongebob,patrick,squidward"))
         obj_group_mock.assert_called_once_with("foo")
Esempio n. 10
0
    def test_members_fail_to_add(self):
        """
        Test adding a list of members and failing to add
        """
        class GroupObj(MockGroupObj):
            def Add(self, name):
                raise PYWINTYPES_ERROR

        obj_group_mock = MagicMock(
            return_value=GroupObj("foo", ["WinNT://HOST/spongebob"]))
        with patch.object(win_groupadd, "_get_group_object",
                          obj_group_mock), patch.object(
                              salt.utils.win_functions, "get_sam_name",
                              sam_mock):
            self.assertFalse(win_groupadd.members("foo", "patrick"))
            obj_group_mock.assert_called_once_with("foo")
Esempio n. 11
0
 def test_members_group_does_not_exist(self):
     '''
     Test adding a list of users where the group does not exist
     '''
     groupobj_mock = MagicMock(side_effect=PYWINTYPES_ERROR)
     with patch.object(win_groupadd, '_get_group_object', groupobj_mock), \
          patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock):
         self.assertDictEqual(
             win_groupadd.members('foo', 'spongebob'), {
                 'changes': {
                     'Users Added': [],
                     'Users Removed': []
                 },
                 'comment': ['Failure accessing group foo.  C'],
                 'name': 'foo',
                 'result': False
             })
Esempio n. 12
0
 def test_members(self):
     '''
     Test adding a list of members to a group, all existing users removed
     '''
     groupobj_mock = MagicMock(
         return_value=MockGroupObj('foo', ['WinNT://HOST/steve']))
     with patch.object(win_groupadd, '_get_group_object', groupobj_mock), \
          patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock):
         self.assertDictEqual(
             win_groupadd.members('foo', 'spongebob,patrick,squidward'), {
                 'changes': {
                     'Users Added': [
                         'HOST\\patrick', 'HOST\\spongebob',
                         'HOST\\squidward'
                     ],
                     'Users Removed': ['HOST\\steve']
                 },
                 'comment': [],
                 'name': 'foo',
                 'result': True
             })
Esempio n. 13
0
    def test_members_fail_to_add(self):
        '''
        Test adding a list of members and failing to add
        '''
        class GroupObj(MockGroupObj):
            def Add(self, name):
                raise PYWINTYPES_ERROR

        groupobj_mock = MagicMock(
            return_value=GroupObj('foo', ['WinNT://HOST/spongebob']))
        with patch.object(win_groupadd, '_get_group_object', groupobj_mock), \
             patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock):
            self.assertDictEqual(
                win_groupadd.members('foo', 'patrick'), {
                    'changes': {
                        'Users Added': [],
                        'Users Removed': ['HOST\\spongebob']
                    },
                    'comment': ['Failed to add HOST\\patrick to foo.  C'],
                    'name': 'foo',
                    'result': False
                })
Esempio n. 14
0
 def test_members_correct_membership(self):
     '''
     Test adding a list of users where the list of users already exists
     '''
     members_list = [
         'WinNT://HOST/spongebob', 'WinNT://HOST/squidward',
         'WinNT://HOST/patrick'
     ]
     groupobj_mock = MagicMock(
         return_value=MockGroupObj('foo', members_list))
     with patch.object(win_groupadd, '_get_group_object', groupobj_mock), \
          patch.object(salt.utils.win_functions, 'get_sam_name', sam_mock):
         self.assertDictEqual(
             win_groupadd.members('foo', 'spongebob,patrick,squidward'), {
                 'changes': {
                     'Users Added': [],
                     'Users Removed': []
                 },
                 'comment': ['foo membership is correct'],
                 'name': 'foo',
                 'result': None
             })