Skip to content

Commit f36267b

Browse files
authored
Support multiple no proxy hosts in Maven (#801)
1 parent 26cff7f commit f36267b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

build-info-extractor-maven3/src/test/java/org/jfrog/build/extractor/maven/resolver/ArtifactoryResolutionTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class ArtifactoryResolutionTest {
3333
final int HTTP_PROXY_PORT = 8888;
3434
final int HTTPS_PROXY_PORT = 8889;
3535
final String NO_PROXY_PATTERN = "www.http-no-proxy-url.com";
36+
final String MULTIPLE_NO_PROXY_PATTERNS = "www.no-proxy-1.com,www.http-no-proxy-url.com";
3637
ArtifactoryResolution artifactoryResolution;
3738
ArtifactoryResolution artifactoryResolutionOnlyRelease;
3839
RemoteRepository snapshotRepository;
@@ -180,6 +181,16 @@ public void TestNullProxyHttps() {
180181
assertNull(artifactoryResolutionWithNoHttp.createSnapshotRepository().getProxy());
181182
}
182183

184+
@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().")
185+
public void TestMultipleNoProxy() {
186+
// Prepare
187+
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);
188+
// Act
189+
ArtifactoryResolution artifactoryResolutionWithNoHttp = new ArtifactoryResolution(HTTP_RELEASE_URL, "https://" + NO_PROXY_PATTERN, USERNAME, PASSWORD, multipleNoHostsProxySelector, new NullPlexusLog());
190+
// Assert
191+
assertNull(artifactoryResolutionWithNoHttp.createSnapshotRepository().getProxy());
192+
}
193+
183194
@Test(description = "HTTP proxy is configured, but HTTPS isn't => a valid proxy return.")
184195
public void testOnlyHttpProxyConfigured() {
185196
// Prepare

build-info-extractor/src/main/java/org/jfrog/build/extractor/ProxySelector.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ public class ProxySelector {
2525
private Proxy httpsProxy;
2626

2727
public ProxySelector(String httpHost, int httpPort, String httpUsername, String httpPassword, String httpsHost, int httpsPort, String httpsUsername, String httpsPassword, String noProxy) {
28-
this.noProxy = noProxy;
2928
if (StringUtils.isNotBlank(httpHost)) {
3029
this.httpProxy = new Proxy(httpHost, httpPort, httpUsername, httpPassword, false);
3130
}
3231
if (StringUtils.isNotBlank(httpsHost)) {
3332
this.httpsProxy = new Proxy(httpsHost, httpsPort, httpsUsername, httpsPassword, true);
3433
}
34+
// The NO_PROXY environment variable standard uses commas to separate no-proxy hosts.
35+
// The Java system property http.nonProxyHosts uses pipes.
36+
this.noProxy = StringUtils.replace(noProxy, ",", "|");
3537
}
3638

3739
public Proxy getProxy(String repositoryUrl) {

0 commit comments

Comments
 (0)