Search in sources :

Example 1 with GoAgentServerHttpClientBuilder

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));
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) GoAgentServerHttpClientBuilder(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Test(org.junit.Test)

Example 2 with GoAgentServerHttpClientBuilder

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;
        }
    };
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GoAgentServerHttpClientBuilder(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient) AgentAutoRegistrationProperties(com.thoughtworks.go.config.AgentAutoRegistrationProperties)

Example 3 with GoAgentServerHttpClientBuilder

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()));
                }
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) GoAgentServerHttpClientBuilder(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder) Header(org.apache.http.Header) HashMap(java.util.HashMap) Map(java.util.Map) Theory(org.junit.experimental.theories.Theory)

Aggregations

GoAgentServerHttpClientBuilder (com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClientBuilder)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 GoAgentServerHttpClient (com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient)1 AgentAutoRegistrationProperties (com.thoughtworks.go.config.AgentAutoRegistrationProperties)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Header (org.apache.http.Header)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 Test (org.junit.Test)1 Theory (org.junit.experimental.theories.Theory)1