From 12e882e41ced0edfa0fb5aa0fc6f6eb0f66d7d56 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 4 Aug 2022 10:52:23 -0400 Subject: [PATCH 1/2] Fixing AWS test --- .../AwsParameterStoreEnvironmentRepositoryTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java index 02454927..f63dca7e 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java @@ -808,6 +808,8 @@ public class AwsParameterStoreEnvironmentRepositoryTests { AwsParameterStoreEnvironmentRepositoryFactory factory = new AwsParameterStoreEnvironmentRepositoryFactory( new ConfigServerProperties()); AwsParameterStoreEnvironmentProperties properties = new AwsParameterStoreEnvironmentProperties(); + properties.setRegion("us-east-1"); + properties.setEndpoint("https://myawsendpoint/"); properties.setOrder(expectedOrder); AwsParameterStoreEnvironmentRepository repository = factory.build(properties); int actualOrder = repository.getOrder(); From ea606a4628d91a07a583725d2f86db7a8273a44a Mon Sep 17 00:00:00 2001 From: ts-schu <109224314+ts-schu@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:45:08 +0200 Subject: [PATCH 2/2] Fix access to redirected git repositories (#2128) * Don't provide a custom HttpClient if not needed * Disable redirect handling * Fix unit test * Add comment why to disable redirect handling * Remove trailing whitespace * Rearrange code and add comment --- ...ttpClientConfigurableHttpConnectionFactory.java | 14 ++++++++++---- .../config/server/support/HttpClientSupport.java | 4 ++++ ...lientConfigurableHttpConnectionFactoryTest.java | 6 ++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java index 76d8ec0d..47f4e656 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactory.java @@ -32,7 +32,6 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; import org.eclipse.jgit.transport.http.HttpConnection; import org.eclipse.jgit.transport.http.apache.HttpClientConnection; @@ -70,7 +69,14 @@ public class HttpClientConfigurableHttpConnectionFactory implements Configurable @Override public HttpConnection create(URL url, Proxy proxy) throws IOException { - return new HttpClientConnection(url.toString(), null, lookupHttpClientBuilder(url).build()); + HttpClientBuilder builder = lookupHttpClientBuilder(url); + if (builder != null) { + return new HttpClientConnection(url.toString(), null, builder.build()); + } + else { + /* No matching builder found: let jGit handle the creation of the HttpClient */ + return new HttpClientConnection(url.toString()); + } } private void addHttpClient(JGitEnvironmentProperties properties) throws GeneralSecurityException { @@ -99,7 +105,7 @@ public class HttpClientConfigurableHttpConnectionFactory implements Configurable if (builderMap.isEmpty()) { this.log.warn(String.format("No custom http config found for URL: %s", url)); - return HttpClients.custom(); + return null; } if (builderMap.size() > 1) { /* @@ -118,7 +124,7 @@ public class HttpClientConfigurableHttpConnectionFactory implements Configurable "More than one git repo URL template matched URL:" + " %s, proxy and skipSslValidation config won't be applied. Matched templates: %s", url, builderMap.keySet().stream().collect(Collectors.joining(", ")))); - return HttpClients.custom(); + return null; } return new ArrayList<>(builderMap.values()).get(0); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/HttpClientSupport.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/HttpClientSupport.java index 35195109..e5b3933f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/HttpClientSupport.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/support/HttpClientSupport.java @@ -65,6 +65,10 @@ public final class HttpClientSupport { httpClientBuilder.setDefaultCredentialsProvider(new SystemDefaultCredentialsProvider()); } + /* According to https://git.eclipse.org/c/jgit/jgit.git/commit/?id=e17bfc96f293744cc5c0cef306e100f53d63bb3d + jGit does its own redirect handling and disables HttpClient's redirect handing. */ + httpClientBuilder.disableRedirectHandling(); + int timeout = environmentProperties.getTimeout() * 1000; return httpClientBuilder.setSSLContext(sslContextBuilder.build()).setDefaultRequestConfig( RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java index ea2b4f4d..43948763 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java @@ -198,10 +198,8 @@ public class HttpClientConfigurableHttpConnectionFactoryTest { HttpConnection actualConnection = this.connectionFactory.create( new URL(properties2.getUri().replace("{placeholder1}", "value1").replace("{placeholder2}", "value2"))); - HttpClientBuilder expectedHttpClientBuilder = this.connectionFactory.httpClientBuildersByUri - .get(properties2.getUri()); - HttpClientBuilder actualHttpClientBuilder = getActualHttpClientBuilder(actualConnection); - assertThat(actualHttpClientBuilder).isNotSameAs(expectedHttpClientBuilder); + HttpClient actualHttpClient = getActualHttpClient(actualConnection); + assertThat(actualHttpClient).isNull(); } @Test