diff --git a/.circleci/config.yml b/.circleci/config.yml index bf0f6104..c21397c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,6 @@ jobs: branches: ignore: - gh-pages # list of branches to ignore - resource_class: large steps: - checkout - restore_cache: @@ -37,4 +36,4 @@ jobs: destination: artifacts - store_test_results: path: ~/junit/ - destination: testartifacts \ No newline at end of file + destination: testartifacts 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 98743df2..6fd20268 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 @@ -105,6 +105,19 @@ public class HttpClientConfigurableHttpConnectionFactory return HttpClients.custom(); } if (builderMap.size() > 1) { + /* + * Try to determine if there is an exact match URL or not. So if there is a placeholder in the URL, filter + * it out. We should be left with only URLs which have no placeholders. + * That is the one we want to use in the case there are multiple matches. + */ + List keys = builderMap.keySet().stream().filter(key -> { + String[] tokens = key.split(PLACEHOLDER_PATTERN); + return tokens.length == 1; + }).collect(Collectors.toList()); + + if (keys.size() == 1) { + return builderMap.get(keys.get(0)); + } this.log.error(String.format( "More than one git repo URL template matched URL:" + " %s, proxy and skipSslValidation config won't be applied. Matched templates: %s", diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java index ebc59d8d..10991e44 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java @@ -79,9 +79,9 @@ public class RefreshableConfigServerIntegrationTests { } /* - * We're emulating an application "foo" which is running with the "development" profile - * and is asking for its properties using the REST endpoint. We're also calling the - * /env & /refresh actuator endpoints to change the + * We're emulating an application "foo" which is running with the "development" + * profile and is asking for its properties using the REST endpoint. We're also + * calling the /env & /refresh actuator endpoints to change the * `spring.cloud.config.server.overrides.foo` property. Since we see that we only get * the overridden "foo" property after the context refresh we are sure that the * properties have been set and the EnvironmentController bean has successfully been 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 cb5f5cca..71bfa827 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 @@ -159,6 +159,24 @@ public class HttpClientConfigurableHttpConnectionFactoryTest { assertThat(actualHttpClientBuilder).isSameAs(expectedHttpClientBuilder); } + @Test + public void multipleMatchesWithPlaceholder() throws Exception { + MultipleJGitEnvironmentProperties properties1 = new MultipleJGitEnvironmentProperties(); + properties1.setUri("https://github.com/marnee01/mderider-{application}.git"); + MultipleJGitEnvironmentProperties properties2 = new MultipleJGitEnvironmentProperties(); + properties2.setUri("https://github.com/marnee01/mderider-MultiApps.git"); + this.connectionFactory.addConfiguration(properties1); + this.connectionFactory.addConfiguration(properties2); + + HttpConnection actualConnection = this.connectionFactory.create(new URL( + "https://github.com/marnee01/mderider-MultiApps.git/info/refs?service=git-upload-pack")); + HttpClientBuilder expectedHttpClientBuilder = this.connectionFactory.httpClientBuildersByUri + .get(properties2.getUri()); + HttpClientBuilder actualHttpClientBuilder = getActualHttpClientBuilder( + actualConnection); + assertThat(actualHttpClientBuilder).isSameAs(expectedHttpClientBuilder); + } + @Test public void composite_urlsWithPlaceholders() throws Exception { MultipleJGitEnvironmentProperties properties1 = new MultipleJGitEnvironmentProperties();