Search in sources :

Example 1 with JGitEnvironmentProperties

use of org.springframework.cloud.config.server.environment.JGitEnvironmentProperties in project spring-cloud-config by spring-cloud.

the class SshUriPropertyProcessorTest method testHttpsUriDoesNotAddEntry.

@Test
public void testHttpsUriDoesNotAddEntry() {
    MultipleJGitEnvironmentProperties sshUriProperties = new MultipleJGitEnvironmentProperties();
    sshUriProperties.setUri("https://user@github.com/proj/repo.git");
    SshUriPropertyProcessor sshUriPropertyProcessor = new SshUriPropertyProcessor(sshUriProperties);
    Map<String, JGitEnvironmentProperties> sshKeysByHostname = sshUriPropertyProcessor.getSshKeysByHostname();
    assertThat(sshKeysByHostname.values()).hasSize(0);
}
Also used : JGitEnvironmentProperties(org.springframework.cloud.config.server.environment.JGitEnvironmentProperties) MultipleJGitEnvironmentProperties(org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties) MultipleJGitEnvironmentProperties(org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties) Test(org.junit.Test)

Example 2 with JGitEnvironmentProperties

use of org.springframework.cloud.config.server.environment.JGitEnvironmentProperties in project spring-cloud-config by spring-cloud.

the class SshUriPropertyProcessorTest method testSingleSshUriProperties.

@Test
public void testSingleSshUriProperties() {
    SshUriPropertyProcessor sshUriPropertyProcessor = new SshUriPropertyProcessor(mainRepoPropertiesFixture());
    Map<String, JGitEnvironmentProperties> sshKeysByHostname = sshUriPropertyProcessor.getSshKeysByHostname();
    assertThat(sshKeysByHostname.values()).hasSize(1);
    JGitEnvironmentProperties sshKey = sshKeysByHostname.get(HOST1);
    assertMainRepo(sshKey);
}
Also used : JGitEnvironmentProperties(org.springframework.cloud.config.server.environment.JGitEnvironmentProperties) MultipleJGitEnvironmentProperties(org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties) Test(org.junit.Test)

Example 3 with JGitEnvironmentProperties

use of org.springframework.cloud.config.server.environment.JGitEnvironmentProperties in project spring-cloud-config by spring-cloud.

the class HttpClientSupportTest method httpsProxy.

@Test
@EnabledOnJre(JRE.JAVA_8)
public void httpsProxy() throws GeneralSecurityException, IOException {
    WireMockServer wireMockProxyServer = new WireMockServer(options().httpDisabled(true).dynamicHttpsPort().enableBrowserProxying(true).trustAllProxyTargets(true));
    WireMockServer wireMockServer = new WireMockServer(options().httpDisabled(true).dynamicHttpsPort());
    wireMockProxyServer.start();
    wireMockServer.start();
    WireMock.configureFor("https", "localhost", wireMockServer.httpsPort());
    stubFor(get("/test/proxy").willReturn(aResponse().withStatus(200)));
    JGitEnvironmentProperties properties = new JGitEnvironmentProperties();
    Map<ProxyHostProperties.ProxyForScheme, ProxyHostProperties> proxy = new HashMap<>();
    ProxyHostProperties hostProperties = new ProxyHostProperties();
    hostProperties.setHost("localhost");
    hostProperties.setPort(wireMockProxyServer.httpsPort());
    proxy.put(ProxyHostProperties.ProxyForScheme.HTTPS, hostProperties);
    properties.setProxy(proxy);
    properties.setSkipSslValidation(true);
    CloseableHttpClient httpClient = null;
    CloseableHttpResponse response = null;
    try {
        httpClient = HttpClientSupport.builder(properties).build();
        response = httpClient.execute(new HttpGet("https://localhost:" + wireMockServer.httpsPort() + "/test/proxy"));
    } finally {
        if (response != null) {
            response.close();
        }
        if (httpClient != null) {
            httpClient.close();
        }
        verify(1, getRequestedFor(urlEqualTo("/test/proxy")));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HashMap(java.util.HashMap) ProxyHostProperties(org.springframework.cloud.config.server.proxy.ProxyHostProperties) JGitEnvironmentProperties(org.springframework.cloud.config.server.environment.JGitEnvironmentProperties) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) EnabledOnJre(org.junit.jupiter.api.condition.EnabledOnJre)

Example 4 with JGitEnvironmentProperties

use of org.springframework.cloud.config.server.environment.JGitEnvironmentProperties in project spring-cloud-config by spring-cloud.

the class HttpClientSupportTest method setsTimeout.

@Test
public void setsTimeout() throws GeneralSecurityException, IOException {
    JGitEnvironmentProperties properties = new JGitEnvironmentProperties();
    properties.setTimeout(1);
    CloseableHttpClient httpClient = HttpClientSupport.builder(properties).build();
    Assertions.assertThatThrownBy(() -> {
        httpClient.execute(new HttpGet(String.format("http://127.0.0.1:%s/test/endpoint", this.localServerPort)));
    }).isInstanceOf(SocketTimeoutException.class);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) JGitEnvironmentProperties(org.springframework.cloud.config.server.environment.JGitEnvironmentProperties) HttpGet(org.apache.http.client.methods.HttpGet) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with JGitEnvironmentProperties

use of org.springframework.cloud.config.server.environment.JGitEnvironmentProperties in project spring-cloud-config by spring-cloud.

the class PropertyBasedSshSessionFactoryTest method strictHostKeyCheckingIsOptional.

@Test
public void strictHostKeyCheckingIsOptional() {
    JGitEnvironmentProperties sshKey = new JGitEnvironmentProperties();
    sshKey.setUri("ssh://gitlab.example.local:3322/somerepo.git");
    sshKey.setPrivateKey(PRIVATE_KEY);
    setupSessionFactory(sshKey);
    this.factory.configure(this.hc, this.session);
    verify(this.session).setConfig("StrictHostKeyChecking", "no");
    verifyNoMoreInteractions(this.session);
}
Also used : JGitEnvironmentProperties(org.springframework.cloud.config.server.environment.JGitEnvironmentProperties) Test(org.junit.Test)

Aggregations

JGitEnvironmentProperties (org.springframework.cloud.config.server.environment.JGitEnvironmentProperties)22 Test (org.junit.Test)14 MultipleJGitEnvironmentProperties (org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties)9 HashSet (java.util.HashSet)3 ProxyHostProperties (org.springframework.cloud.config.server.proxy.ProxyHostProperties)3 HostKey (com.jcraft.jsch.HostKey)2 ProxyHTTP (com.jcraft.jsch.ProxyHTTP)2 HashMap (java.util.HashMap)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 JSchException (com.jcraft.jsch.JSchException)1 LinkedHashSet (java.util.LinkedHashSet)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 EnabledOnJre (org.junit.jupiter.api.condition.EnabledOnJre)1 JGitEnvironmentRepository (org.springframework.cloud.config.server.environment.JGitEnvironmentRepository)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1