use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder in project gocd by gocd.
the class ServerBinaryDownloaderTest method shouldReturnFalseIfTheServerDoesNotRespondWithEntity.
@Test
public void shouldReturnFalseIfTheServerDoesNotRespondWithEntity() throws Exception {
GoAgentServerHttpClientBuilder builder = mock(GoAgentServerHttpClientBuilder.class);
CloseableHttpClient closeableHttpClient = mock(CloseableHttpClient.class);
when(builder.build()).thenReturn(closeableHttpClient);
CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
when(closeableHttpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse);
ServerBinaryDownloader downloader = new ServerBinaryDownloader(builder, ServerUrlGeneratorMother.generatorFor("localhost", 9090));
assertThat(downloader.download(DownloadableFile.AGENT), is(false));
}
use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder in project gocd by gocd.
the class SslInfrastructureServiceTest method requesterStub.
private SslInfrastructureService.RemoteRegistrationRequester requesterStub(final Registration registration) {
final SslInfrastructureServiceTest me = this;
final SystemEnvironment systemEnvironment = new SystemEnvironment();
return new SslInfrastructureService.RemoteRegistrationRequester(null, agentRegistryStub(), new GoAgentServerHttpClient(new GoAgentServerHttpClientBuilder(systemEnvironment))) {
protected Registration requestRegistration(String agentHostName, AgentAutoRegistrationProperties agentAutoRegisterProperties) throws IOException, ClassNotFoundException {
LOGGER.debug("Requesting remote registration");
me.remoteCalled = true;
return registration;
}
};
}
use of com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder in project gocd by gocd.
the class UrlRewriterIntegrationTest method shouldRewrite.
@Theory
public void shouldRewrite(final ResponseAssertion assertion) throws Exception {
useConfiguredUrls = assertion.useConfiguredUrls;
GoAgentServerHttpClientBuilder builder = new GoAgentServerHttpClientBuilder(null, SslVerificationMode.NONE);
try (CloseableHttpClient httpClient = builder.build()) {
HttpRequestBase httpMethod;
if (assertion.method == METHOD.GET) {
httpMethod = new HttpGet(assertion.requestedUrl);
} else if (assertion.method == METHOD.POST) {
httpMethod = new HttpPost(assertion.requestedUrl);
} else if (assertion.method == METHOD.PUT) {
httpMethod = new HttpPut(assertion.requestedUrl);
} else {
throw new RuntimeException("Method has to be one of GET, POST and PUT. Was: " + assertion.method);
}
try (CloseableHttpResponse response = httpClient.execute(httpMethod)) {
assertThat("status code match failed", response.getStatusLine().getStatusCode(), is(assertion.responseCode));
assertThat("handler url match failed", IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8), is(assertion.servedUrl));
for (Map.Entry<String, String> headerValPair : assertion.responseHeaders.entrySet()) {
Header responseHeader = response.getFirstHeader(headerValPair.getKey());
if (headerValPair.getValue() == null) {
assertThat("header match failed", responseHeader, is(nullValue()));
} else {
assertThat("header match failed", responseHeader.getValue(), is(headerValPair.getValue()));
}
}
}
}
}
Aggregations