Ejemplo n.º 1
0
    def test_new_user_success(self):
        '''
        Test if it returns True when new user is added to htpasswd file
        '''

        mock_grep = MagicMock(return_value={'retcode': 1})
        mock_useradd = MagicMock(return_value={
            'retcode': 0,
            'stderr': 'Success'
        })

        with patch.dict(htpasswd.__salt__, {
                'file.grep': mock_grep,
                'webutil.useradd': mock_useradd
        }):
            ret = htpasswd.user_exists('larry', 'badpass',
                                       '/etc/httpd/htpasswd')
            expected = {
                'name': 'larry',
                'result': True,
                'comment': 'Success',
                'changes': {
                    'larry': True
                }
            }
            self.assertEqual(ret, expected)
Ejemplo n.º 2
0
    def test_user_exists_already(self):
        '''
        Test if it returns True when user already exists in htpasswd file
        '''

        mock = MagicMock(return_value={'retcode': 0})

        with patch.dict(htpasswd.__salt__, {'file.grep': mock}):
            ret = htpasswd.user_exists('larry', 'badpass',
                                       '/etc/httpd/htpasswd')
            expected = {'name': 'larry',
                        'result': True,
                        'comment': 'User already known',
                        'changes': {}}
            self.assertEqual(ret, expected)
Ejemplo n.º 3
0
    def test_user_exists_already(self):
        '''
        Test if it returns True when user already exists in htpasswd file
        '''

        mock = MagicMock(return_value={'retcode': 0})

        with patch.dict(htpasswd.__salt__, {'file.grep': mock}):
            ret = htpasswd.user_exists('larry', 'badpass',
                                       '/etc/httpd/htpasswd')
            expected = {
                'name': 'larry',
                'result': True,
                'comment': 'User already known',
                'changes': {}
            }
            self.assertEqual(ret, expected)
Ejemplo n.º 4
0
    def test_new_user_error(self):
        '''
        Test if it returns False when adding user to htpasswd failed
        '''

        mock_grep = MagicMock(return_value={'retcode': 1})
        mock_useradd = MagicMock(return_value={'retcode': 1,
                                               'stderr': 'Error'})

        with patch.dict(htpasswd.__salt__,
                        {'file.grep': mock_grep,
                         'webutil.useradd_all': mock_useradd}):
            ret = htpasswd.user_exists('larry', 'badpass',
                                       '/etc/httpd/htpasswd')
            expected = {'name': 'larry',
                        'result': False,
                        'comment': 'Error',
                        'changes': {}}
            self.assertEqual(ret, expected)
Ejemplo n.º 5
0
    def test_new_user_success(self):
        '''
        Test if it returns True when new user is added to htpasswd file
        '''

        mock_grep = MagicMock(return_value={'retcode': 1})
        mock_useradd = MagicMock(return_value={'retcode': 0,
                                               'stderr': 'Success'})

        with patch.dict(htpasswd.__salt__,
                        {'file.grep': mock_grep,
                         'webutil.useradd_all': mock_useradd}):
            ret = htpasswd.user_exists('larry', 'badpass',
                                       '/etc/httpd/htpasswd')
            expected = {'name': 'larry',
                        'result': True,
                        'comment': 'Success',
                        'changes': {'larry': True}}
            self.assertEqual(ret, expected)
Ejemplo n.º 6
0
    def test_new_user_error(self):
        '''
        Test if it returns False when adding user to htpasswd failed
        '''

        mock_grep = MagicMock(return_value={'retcode': 1})
        mock_useradd = MagicMock(return_value={
            'retcode': 1,
            'stderr': 'Error'
        })

        with patch.dict(htpasswd.__salt__, {
                'file.grep': mock_grep,
                'webutil.useradd': mock_useradd
        }):
            ret = htpasswd.user_exists('larry', 'badpass',
                                       '/etc/httpd/htpasswd')
            expected = {
                'name': 'larry',
                'result': False,
                'comment': 'Error',
                'changes': {}
            }
            self.assertEqual(ret, expected)