use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.
the class ITTLSTest method checkAccessWithWrongRoot.
@Test
public void checkAccessWithWrongRoot() {
LOG.info("---------Testing TLS resource access when client certificate is signed by a non-trusted root CA---------");
HttpClient wrongRootClient = makeCustomHttpClient("client_tls/client_another_root.jks", "druid_another_root");
checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getCoordinatorTLSUrl());
checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getOverlordTLSUrl());
checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getBrokerTLSUrl());
checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getHistoricalTLSUrl());
checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getRouterTLSUrl());
checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getPermissiveRouterTLSUrl());
makeRequest(wrongRootClient, HttpMethod.GET, config.getNoClientAuthRouterTLSUrl() + "/status", null);
}
use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.
the class ITTLSTest method testTLSNodeAccessWithIntermediate.
@Test
public void testTLSNodeAccessWithIntermediate() {
LOG.info("---------Testing TLS resource access with 3-part cert chain---------");
HttpClient intermediateCertClient = makeCustomHttpClient("client_tls/intermediate_ca_client.jks", "intermediate_ca_client");
makeRequest(intermediateCertClient, HttpMethod.GET, config.getCoordinatorTLSUrl() + "/status", null);
makeRequest(intermediateCertClient, HttpMethod.GET, config.getOverlordTLSUrl() + "/status", null);
makeRequest(intermediateCertClient, HttpMethod.GET, config.getBrokerTLSUrl() + "/status", null);
makeRequest(intermediateCertClient, HttpMethod.GET, config.getHistoricalTLSUrl() + "/status", null);
makeRequest(intermediateCertClient, HttpMethod.GET, config.getRouterTLSUrl() + "/status", null);
makeRequest(intermediateCertClient, HttpMethod.GET, config.getPermissiveRouterTLSUrl() + "/status", null);
makeRequest(intermediateCertClient, HttpMethod.GET, config.getNoClientAuthRouterTLSUrl() + "/status", null);
}
use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.
the class IndexTaskClientTest method dontRetryIfNotFoundWithCorrectTaskId.
@Test
public void dontRetryIfNotFoundWithCorrectTaskId() {
final String taskId = "taskId";
final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
response.headers().add(ChatHandlerResource.TASK_ID_HEADER, taskId);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(response, StandardCharsets.UTF_8).addChunk("Error")))).times(1);
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final IOException e = Assert.assertThrows(IOException.class, () -> indexTaskClient.submitRequestWithEmptyContent(taskId, HttpMethod.GET, "test", null, false));
Assert.assertEquals("Received server error with status [404 Not Found]; first 1KB of body: Error", e.getMessage());
}
EasyMock.verify(httpClient);
}
use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.
the class IndexTaskClientTest method retryOnServerError.
@Test
public void retryOnServerError() throws IOException {
final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR), StandardCharsets.UTF_8).addChunk("Error")))).times(2);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.value(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK), StandardCharsets.UTF_8)))).once();
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final StringFullResponseHolder response = indexTaskClient.submitRequestWithEmptyContent("taskId", HttpMethod.GET, "test", null, true);
Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
}
EasyMock.verify(httpClient);
}
use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.
the class IndexTaskClientTest method retryIfNotFoundWithIncorrectTaskId.
@Test
public void retryIfNotFoundWithIncorrectTaskId() throws IOException {
final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
final String taskId = "taskId";
final String incorrectTaskId = "incorrectTaskId";
final DefaultHttpResponse incorrectResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
incorrectResponse.headers().add(ChatHandlerResource.TASK_ID_HEADER, incorrectTaskId);
final DefaultHttpResponse correctResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
correctResponse.headers().add(ChatHandlerResource.TASK_ID_HEADER, taskId);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(incorrectResponse, StandardCharsets.UTF_8)))).times(2);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.value(new StringFullResponseHolder(correctResponse, StandardCharsets.UTF_8)))).once();
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final StringFullResponseHolder response = indexTaskClient.submitRequestWithEmptyContent(taskId, HttpMethod.GET, "test", null, true);
Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
}
EasyMock.verify(httpClient);
}
Aggregations