Search in sources :

Example 1 with AllowedRegexErrorResponseTransformStrategy

use of org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy in project druid by druid-io.

the class ErrorHandlerTest method testErrorHandlerHandlesNonSanitizableExceptionCorrectly.

@Test
public void testErrorHandlerHandlesNonSanitizableExceptionCorrectly() {
    ServerConfig serverConfig = Mockito.mock(ServerConfig.class);
    AllowedRegexErrorResponseTransformStrategy emptyAllowedRegexErrorResponseTransformStrategy = new AllowedRegexErrorResponseTransformStrategy(ImmutableList.of());
    Mockito.when(serverConfig.getErrorResponseTransformStrategy()).thenReturn(emptyAllowedRegexErrorResponseTransformStrategy);
    ErrorHandler errorHandler = new ErrorHandler(serverConfig);
    Exception input = new Exception("message");
    RuntimeException output = errorHandler.sanitize(input);
    Assert.assertEquals(null, output.getMessage());
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig) AllowedRegexErrorResponseTransformStrategy(org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy) QueryException(org.apache.druid.query.QueryException) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) Test(org.junit.Test)

Example 2 with AllowedRegexErrorResponseTransformStrategy

use of org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy in project druid by druid-io.

the class ErrorHandlerTest method testErrorHandlerHasAffectingErrorResponseTransformStrategyReturnsTrueWhenNotUsingNoErrorResponseTransformStrategy.

@Test
public void testErrorHandlerHasAffectingErrorResponseTransformStrategyReturnsTrueWhenNotUsingNoErrorResponseTransformStrategy() {
    ServerConfig serverConfig = Mockito.mock(ServerConfig.class);
    AllowedRegexErrorResponseTransformStrategy emptyAllowedRegexErrorResponseTransformStrategy = new AllowedRegexErrorResponseTransformStrategy(ImmutableList.of());
    Mockito.when(serverConfig.getErrorResponseTransformStrategy()).thenReturn(emptyAllowedRegexErrorResponseTransformStrategy);
    ErrorHandler errorHandler = new ErrorHandler(serverConfig);
    Assert.assertTrue(errorHandler.hasAffectingErrorResponseTransformStrategy());
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig) AllowedRegexErrorResponseTransformStrategy(org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy) Test(org.junit.Test)

Example 3 with AllowedRegexErrorResponseTransformStrategy

use of org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy in project druid by druid-io.

the class SqlResourceTest method testUnsupportedQueryThrowsExceptionWithFilterResponse.

@Test
public void testUnsupportedQueryThrowsExceptionWithFilterResponse() throws Exception {
    resource = new SqlResource(JSON_MAPPER, CalciteTests.TEST_AUTHORIZER_MAPPER, sqlLifecycleFactory, lifecycleManager, new ServerConfig() {

        @Override
        public boolean isShowDetailedJettyErrors() {
            return true;
        }

        @Override
        public ErrorResponseTransformStrategy getErrorResponseTransformStrategy() {
            return new AllowedRegexErrorResponseTransformStrategy(ImmutableList.of());
        }
    });
    String errorMessage = "This will be support in Druid 9999";
    SqlQuery badQuery = EasyMock.createMock(SqlQuery.class);
    EasyMock.expect(badQuery.getQuery()).andReturn("SELECT ANSWER TO LIFE");
    EasyMock.expect(badQuery.getContext()).andReturn(ImmutableMap.of("sqlQueryId", "id"));
    EasyMock.expect(badQuery.getParameterList()).andThrow(new QueryUnsupportedException(errorMessage));
    EasyMock.replay(badQuery);
    final QueryException exception = doPost(badQuery).lhs;
    Assert.assertNotNull(exception);
    Assert.assertNull(exception.getMessage());
    Assert.assertNull(exception.getHost());
    Assert.assertEquals(exception.getErrorCode(), QueryUnsupportedException.ERROR_CODE);
    Assert.assertNull(exception.getErrorClass());
    Assert.assertTrue(lifecycleManager.getAll("id").isEmpty());
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig) UnsupportedSQLQueryException(org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException) QueryException(org.apache.druid.query.QueryException) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException) AllowedRegexErrorResponseTransformStrategy(org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy) Test(org.junit.Test)

Example 4 with AllowedRegexErrorResponseTransformStrategy

use of org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy in project druid by druid-io.

the class AsyncQueryForwardingServletTest method testHandleExceptionWithFilterEnabledButMessageMatchAllowedRegex.

@Test
public void testHandleExceptionWithFilterEnabledButMessageMatchAllowedRegex() throws Exception {
    String errorMessage = "test exception message";
    ObjectMapper mockMapper = Mockito.mock(ObjectMapper.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    ServletOutputStream outputStream = Mockito.mock(ServletOutputStream.class);
    Mockito.when(response.getOutputStream()).thenReturn(outputStream);
    final AsyncQueryForwardingServlet servlet = new AsyncQueryForwardingServlet(new MapQueryToolChestWarehouse(ImmutableMap.of()), mockMapper, TestHelper.makeSmileMapper(), null, null, null, new NoopServiceEmitter(), new NoopRequestLogger(), new DefaultGenericQueryMetricsFactory(), new AuthenticatorMapper(ImmutableMap.of()), new Properties(), new ServerConfig() {

        @Override
        public boolean isShowDetailedJettyErrors() {
            return true;
        }

        @Override
        public ErrorResponseTransformStrategy getErrorResponseTransformStrategy() {
            return new AllowedRegexErrorResponseTransformStrategy(ImmutableList.of("test .*"));
        }
    });
    Exception testException = new IllegalStateException(errorMessage);
    servlet.handleException(response, mockMapper, testException);
    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    Mockito.verify(mockMapper).writeValue(ArgumentMatchers.eq(outputStream), captor.capture());
    Assert.assertTrue(captor.getValue() instanceof QueryException);
    Assert.assertEquals(QueryInterruptedException.UNKNOWN_EXCEPTION, ((QueryException) captor.getValue()).getErrorCode());
    Assert.assertEquals(errorMessage, captor.getValue().getMessage());
    Assert.assertNull(((QueryException) captor.getValue()).getErrorClass());
    Assert.assertNull(((QueryException) captor.getValue()).getHost());
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Properties(java.util.Properties) QueryException(org.apache.druid.query.QueryException) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) AuthenticatorMapper(org.apache.druid.server.security.AuthenticatorMapper) ServerConfig(org.apache.druid.server.initialization.ServerConfig) QueryException(org.apache.druid.query.QueryException) ErrorResponseTransformStrategy(org.apache.druid.common.exception.ErrorResponseTransformStrategy) AllowedRegexErrorResponseTransformStrategy(org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy) MapQueryToolChestWarehouse(org.apache.druid.query.MapQueryToolChestWarehouse) AllowedRegexErrorResponseTransformStrategy(org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseJettyTest(org.apache.druid.server.initialization.BaseJettyTest) Test(org.junit.Test)

Example 5 with AllowedRegexErrorResponseTransformStrategy

use of org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy in project druid by druid-io.

the class ErrorHandlerTest method testErrorHandlerSanitizesErrorAsExpected.

@Test
public void testErrorHandlerSanitizesErrorAsExpected() {
    ServerConfig serverConfig = Mockito.mock(ServerConfig.class);
    AllowedRegexErrorResponseTransformStrategy emptyAllowedRegexErrorResponseTransformStrategy = new AllowedRegexErrorResponseTransformStrategy(ImmutableList.of());
    Mockito.when(serverConfig.getErrorResponseTransformStrategy()).thenReturn(emptyAllowedRegexErrorResponseTransformStrategy);
    ErrorHandler errorHandler = new ErrorHandler(serverConfig);
    QueryException input = new QueryException("error", "error message", "error class", "host");
    RuntimeException output = errorHandler.sanitize(input);
    Assert.assertNull(output.getMessage());
}
Also used : ServerConfig(org.apache.druid.server.initialization.ServerConfig) QueryException(org.apache.druid.query.QueryException) AllowedRegexErrorResponseTransformStrategy(org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy) Test(org.junit.Test)

Aggregations

AllowedRegexErrorResponseTransformStrategy (org.apache.druid.common.exception.AllowedRegexErrorResponseTransformStrategy)10 ServerConfig (org.apache.druid.server.initialization.ServerConfig)10 Test (org.junit.Test)10 QueryException (org.apache.druid.query.QueryException)8 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4 Properties (java.util.Properties)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ErrorResponseTransformStrategy (org.apache.druid.common.exception.ErrorResponseTransformStrategy)4 DefaultGenericQueryMetricsFactory (org.apache.druid.query.DefaultGenericQueryMetricsFactory)4 MapQueryToolChestWarehouse (org.apache.druid.query.MapQueryToolChestWarehouse)4 BaseJettyTest (org.apache.druid.server.initialization.BaseJettyTest)4 NoopRequestLogger (org.apache.druid.server.log.NoopRequestLogger)4 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)4 AuthenticatorMapper (org.apache.druid.server.security.AuthenticatorMapper)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 UnsupportedSQLQueryException (org.apache.druid.sql.calcite.planner.UnsupportedSQLQueryException)2