Skip to content

Commit

Permalink
Support multiple no proxy hosts in Maven
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Aug 9, 2024
1 parent b82ee06 commit 1b16541
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1b16541

Please sign in to comment.