Beispiel #1
0
    def test_handle_code_unknown(self):
        # Setup
        response_doc = auth_utils.generate_failure_response('foo')
        e = bindings_exceptions.PermissionsException(response_doc)

        # Test
        code = self.handler.handle_permission(e)

        # Verify
        self.assertEqual(code, exceptions.CODE_PERMISSIONS_EXCEPTION)
        self.assertEqual(self.handler._handle_unknown.call_count, 1)
Beispiel #2
0
    def test_permissions(self):
        """
        Tests a client-side permissions error.
        """

        # Test
        response_body = {'auth_error_code': 'authentication_failed'}
        e = exceptions.PermissionsException(response_body)
        code = self.exception_handler.handle_permission(e)

        # Verify
        self.assertEqual(code, handler.CODE_PERMISSIONS_EXCEPTION)
        self.assertTrue('specified user' in self.recorder.lines[0])
    def test_permissions(self):
        """
        Tests a client-side permissions error.
        """

        # Test
        response_body = auth_utils.generate_failure_response(auth_utils.CODE_FAILED)
        e = exceptions.PermissionsException(response_body)
        code = self.exception_handler.handle_permission(e)

        # Verify
        self.assertEqual(code, handler.CODE_PERMISSIONS_EXCEPTION)
        self.assertTrue('specified user' in self.recorder.lines[0])
Beispiel #4
0
    def test_handle_code_invalid_ssl_cert(self):
        # Setup
        response_doc = auth_utils.generate_failure_response(
            auth_utils.CODE_INVALID_SSL_CERT)
        e = bindings_exceptions.PermissionsException(response_doc)

        # Test
        code = self.handler.handle_permission(e)

        # Verify
        self.assertEqual(code, exceptions.CODE_PERMISSIONS_EXCEPTION)
        self.assertEqual(self.handler._handle_authentication_failed.call_count,
                         1)
    def test_permission(self):
        """
        Tests a client-side error when the connection is rejected due to auth reasons.
        """
        # Test
        response_body = {'auth_error_code': 'authentication_failed'}
        e = bindings_exceptions.PermissionsException(response_body)
        e.error_message = "I've made a huge mistake."
        code = self.handler.handle_permission(e)

        # Verify
        self.assertEqual(code, exceptions.CODE_PERMISSIONS_EXCEPTION)
        self.assertTrue("I've made a huge mistake.\n" == self.recorder.lines[0])
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
Beispiel #6
0
    def test_handle_exception(self):
        """
        Tests the high level call that branches based on exception type for all types.
        """

        # For each exception type, check that the proper code is returned and
        # that a failure message has been output. For simplicity in those tests,
        # reset the tags after each run.

        code = self.exception_handler.handle_exception(
            exceptions.BadRequestException({}))
        self.assertEqual(code, handler.CODE_BAD_REQUEST)
        self.assertEqual(3, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            exceptions.ConflictException({}))
        self.assertEqual(code, handler.CODE_CONFLICT)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            exceptions.ConnectionException({}))
        self.assertEqual(code, handler.CODE_CONNECTION_EXCEPTION)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            exceptions.NotFoundException({'resources': {
                'repo_id': 'foo'
            }}))
        self.assertEqual(code, handler.CODE_NOT_FOUND)
        self.assertEqual(2, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            exceptions.PermissionsException({}))
        self.assertEqual(code, handler.CODE_PERMISSIONS_EXCEPTION)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            exceptions.PulpServerException({}))
        self.assertEqual(code, handler.CODE_PULP_SERVER_EXCEPTION)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            InvalidConfig('Test Message'))
        self.assertEqual(code, handler.CODE_INVALID_CONFIG)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            WrongHost('expected', 'actual'))
        self.assertEqual(code, handler.CODE_WRONG_HOST)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            exceptions.ApacheServerException('Test Message'))
        self.assertEqual(code, handler.CODE_APACHE_SERVER_EXCEPTION)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(gaierror())
        self.assertEqual(code, handler.CODE_UNKNOWN_HOST)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(socket_error())
        self.assertEqual(code, handler.CODE_SOCKET_ERROR)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(
            exceptions.ClientCertificateExpiredException(CERT_FILENAME))
        self.assertEqual(code, handler.CODE_PERMISSIONS_EXCEPTION)
        self.assertEqual([TAG_FAILURE, TAG_PARAGRAPH],
                         self.prompt.get_write_tags())
        self.prompt.tags = []

        code = self.exception_handler.handle_exception(Exception({}))
        self.assertEqual(code, handler.CODE_UNEXPECTED)
        self.assertEqual(1, len(self.prompt.tags))
        self.assertEqual(TAG_FAILURE, self.prompt.get_write_tags()[0])
        self.prompt.tags = []