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

Bugfix/upstream proxy auth #149

Merged
merged 7 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -139,20 +139,34 @@ public BrowserUpRemoteProxyServer startServer(BrowserUpRemoteProxyServer proxySe
startServerUriBuilder.setParameter("trustAllServers", "true");

// Set bind address
if (StringUtils.isNotBlank(proxyServer.getBindAddress())) {
startServerUriBuilder.setParameter("bindAddress", proxyServer.getBindAddress());
}
proxyServer.getBindAddress().filter(StringUtils::isNotBlank).ifPresent(s -> {
startServerUriBuilder.setParameter("bindAddress", s);
});

// Set upstream proxy.
if (proxyServer.getUpstreamProxy() != null) {
startServerUriBuilder.setParameter("httpProxy", String.format("%s:%d", proxyServer.getUpstreamProxy().getHost(), proxyServer.getUpstreamProxy().getPort()));
startServerUriBuilder.setParameter("proxyHTTPS", String.format("%s:%d", proxyServer.getUpstreamProxy().getHost(), proxyServer.getUpstreamProxy().getPort()));
proxyServer.getUpstreamProxy().ifPresent(url -> {
startServerUriBuilder.setParameter("httpProxy", String.format("%s:%d", url.getHost(), url.getPort()));
if (url.getHost().equalsIgnoreCase("https")) {
startServerUriBuilder.setParameter("proxyHTTPS", "true");
}

// Set non proxy exceptions for upstream proxy
if (StringUtils.isNotBlank(proxyServer.getUpstreamNonProxy())) {
startServerUriBuilder.setParameter("httpNonProxyHosts", proxyServer.getUpstreamNonProxy());
String userInfo = url.getUserInfo();
if (StringUtils.isNotBlank(userInfo)) {
String[] parts = userInfo.split(":");
if (parts.length > 0) {
startServerUriBuilder.setParameter("proxyUsername", parts[0]);

if (parts.length > 1) {
startServerUriBuilder.setParameter("proxyPassword", parts[1]);
}
}
}
}

// Set non proxy exceptions for upstream proxy
proxyServer.getUpstreamNonProxy().filter(StringUtils::isNotBlank).ifPresent(s -> {
startServerUriBuilder.setParameter("httpNonProxyHosts", s);
});
});

final URI uri = buildUri(startServerUriBuilder, "Error parsing URL for POST /proxy for BrowserUp proxy server.");
final HttpPost httpPost = new HttpPost(uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package eu.tsystems.mms.tic.testerra.bup;

import java.net.URL;
import java.util.Optional;

/**
* Date: 25.05.2020
Expand All @@ -33,9 +34,7 @@ public class BrowserUpRemoteProxyServer {

private Integer port;
private URL upstreamProxy;

private String upstreamNonProxy;

private String bindAddress;

public Integer getPort() {
Expand All @@ -46,24 +45,29 @@ public void setPort(Integer port) {
this.port = port;
}

public URL getUpstreamProxy() {
return upstreamProxy;
public Optional<URL> getUpstreamProxy() {
return Optional.ofNullable(upstreamProxy);
}

/**
* Sets the URL for the upstream/chained proxy.
* Uses the user info for upstream proxy credentials.
* @param upstreamProxy
*/
public void setUpstreamProxy(URL upstreamProxy) {
this.upstreamProxy = upstreamProxy;
}

public String getUpstreamNonProxy() {
return upstreamNonProxy;
public Optional<String> getUpstreamNonProxy() {
return Optional.ofNullable(upstreamNonProxy);
}

public void setUpstreamNonProxy(String upstreamNonProxy) {
this.upstreamNonProxy = upstreamNonProxy;
}

public String getBindAddress() {
return bindAddress;
public Optional<String> getBindAddress() {
return Optional.ofNullable(bindAddress);
}

public void setBindAddress(String bindAddress) {
Expand Down
Loading