diff --git a/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java b/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java index 7018497ac..6682c6854 100644 --- a/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java +++ b/build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java @@ -33,6 +33,7 @@ public class ArtifactoryResolutionTest { final int HTTP_PROXY_PORT = 8888; final int HTTPS_PROXY_PORT = 8889; final String NO_PROXY_PATTERN = "www.http-no-proxy-url.com"; + final String MULTIPLE_NO_PROXY_PATTERNS = "www.no-proxy-1.com,www.http-no-proxy-url.com"; ArtifactoryResolution artifactoryResolution; ArtifactoryResolution artifactoryResolutionOnlyRelease; RemoteRepository snapshotRepository; @@ -180,6 +181,16 @@ public void TestNullProxyHttps() { assertNull(artifactoryResolutionWithNoHttp.createSnapshotRepository().getProxy()); } + @Test(description = "In the case of 'http.nonProxyHosts' with multiple hosts that one of them is matching the repository URL, null is returned from getProxy().") + public void TestMultipleNoProxy() { + // Prepare + ProxySelector multipleNoHostsProxySelector = new ProxySelector(HTTP_PROXY_URL, HTTP_PROXY_PORT, HTTP_PROXY_USERNAME, HTTP_PROXY_PASSWORD, HTTPS_PROXY_URL, HTTPS_PROXY_PORT, HTTPS_PROXY_USERNAME, HTTPS_PROXY_PASSWORD, MULTIPLE_NO_PROXY_PATTERNS); + // Act + ArtifactoryResolution artifactoryResolutionWithNoHttp = new ArtifactoryResolution(HTTP_RELEASE_URL, "https://" + NO_PROXY_PATTERN, USERNAME, PASSWORD, multipleNoHostsProxySelector, new NullPlexusLog()); + // Assert + assertNull(artifactoryResolutionWithNoHttp.createSnapshotRepository().getProxy()); + } + @Test(description = "HTTP proxy is configured, but HTTPS isn't => a valid proxy return.") public void testOnlyHttpProxyConfigured() { // Prepare diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java index b19537677..db62b85dd 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java @@ -25,13 +25,15 @@ public class ProxySelector { private Proxy httpsProxy; public ProxySelector(String httpHost, int httpPort, String httpUsername, String httpPassword, String httpsHost, int httpsPort, String httpsUsername, String httpsPassword, String noProxy) { - this.noProxy = noProxy; if (StringUtils.isNotBlank(httpHost)) { this.httpProxy = new Proxy(httpHost, httpPort, httpUsername, httpPassword, false); } if (StringUtils.isNotBlank(httpsHost)) { this.httpsProxy = new Proxy(httpsHost, httpsPort, httpsUsername, httpsPassword, true); } + // The NO_PROXY environment variable standard uses commas to separate no-proxy hosts. + // The Java system property http.nonProxyHosts uses pipes. + this.noProxy = StringUtils.replace(noProxy, ",", "|"); } public Proxy getProxy(String repositoryUrl) {