Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple no proxy hosts in Maven #801

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading