Example #1
0
 def test_auth_decorator_consumer_not_authorized(self, mock_is_authorized, *unused_mocks):
     """
     Test that if the consumer isn't authorized for a particular action, an exception is
     raised.
     """
     decorated_func = decorators.auth_required(0, False)(self.func)
     self.assertRaises(PulpCodedAuthenticationException, decorated_func, None)
     self.assertEqual(1, mock_is_authorized.call_count)
Example #2
0
 def test_auth_decorator_not_super(self, mock_is_authed, *unused_mocks):
     """
     Test that if the user is not a super user and the operation requires super user,
     an exception is raised. This test mocks out the authentication portion of the decorator.
     """
     decorated_func = decorators.auth_required(0, True)(self.func)
     self.assertRaises(PulpCodedAuthenticationException, decorated_func, None)
     self.assertEqual(0, mock_is_authed.call_count)
Example #3
0
 def test_auth_decorator_not_super(self, mock_is_authed, *unused_mocks):
     """
     Test that if the user is not a super user and the operation requires super user,
     an exception is raised. This test mocks out the authentication portion of the decorator.
     """
     decorated_func = decorators.auth_required(0, True)(self.func)
     self.assertRaises(PulpCodedAuthenticationException, decorated_func,
                       None)
     self.assertEqual(0, mock_is_authed.call_count)
Example #4
0
 def test_auth_decorator_not_authorized(self, mock_is_authorized,
                                        *unused_mocks):
     """
     Test that if an admin user isn't authorized for a particular action, an exception
     is raised.
     """
     decorated_func = decorators.auth_required(0, False)(self.func)
     self.assertRaises(PulpCodedAuthenticationException, decorated_func,
                       None)
     self.assertEqual(1, mock_is_authorized.call_count)
Example #5
0
    def test_auth_decorator_consumer_authorized(self, mock_is_authorized, mock_user_objects,
                                                mock_principal_manager, *unused_mocks):
        """
        Test that if the consumer is authorized, no exception is raised.
        """
        principal_manager = mock_principal_manager.return_value
        decorated_func = decorators.auth_required(0, False)(lambda *x: None)
        decorated_func(None)

        self.assertEqual(0, mock_user_objects.get.call_count)
        mock_is_authorized.assert_called_once_with('/', 'gob', 0)
        principal_manager.set_principal.assert_called_once_with()
        principal_manager.clear_principal.assert_called_once_with()
Example #6
0
    def test_auth_decorator_consumer_authorized(self, mock_is_authorized,
                                                mock_user_objects,
                                                mock_principal_manager,
                                                *unused_mocks):
        """
        Test that if the consumer is authorized, no exception is raised.
        """
        principal_manager = mock_principal_manager.return_value
        decorated_func = decorators.auth_required(0, False)(lambda *x: None)
        decorated_func(None)

        self.assertEqual(0, mock_user_objects.get.call_count)
        mock_is_authorized.assert_called_once_with('/', 'gob', 0)
        principal_manager.set_principal.assert_called_once_with()
        principal_manager.clear_principal.assert_called_once_with()