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

Removed FTP proxy settings from default proxy #114

Merged
merged 3 commits into from
Sep 1, 2021
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 @@ -19,12 +19,13 @@
* under the License.
*
*/
package eu.tsystems.mms.tic.testframework.utils;
package eu.tsystems.mms.tic.testframework.utils;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,6 +36,7 @@ public class ProxyUtils {
/**
* Will return proxy url like http://{http.proxyUser}:{http.proxyPassword}@{http.proxyHost}:{http.proxyPort}
* based on the System's proxy settings ea. from the proxysettings.properties file
*
* @return null If there is no URL configured
*/
public static URL getSystemHttpProxyUrl() {
Expand All @@ -44,6 +46,7 @@ public static URL getSystemHttpProxyUrl() {
/**
* Will return proxy url like http://{https.proxyUser}:{https.proxyPassword}@{https.proxyHost}:{https.proxyPort}
* based on the System's proxy settings ea. from the proxysettings.properties file
*
* @return null If there is no URL configured
*/
public static URL getSystemHttpsProxyUrl() {
Expand Down Expand Up @@ -73,7 +76,7 @@ private static String getSpecificProxyTypeString(final String proxyType) {
* ProxyType can be "http" or "https" according to java env properties proxy.httpHost or proxy.httpsHost
*
* @param proxyType {@link String} http or https
* @param prefix {@link String} Prefix for URL Scheme
* @param prefix {@link String} Prefix for URL Scheme
* @return URL
*/
private static URL getSpecificProxyTypeUrlWithPrefix(final String proxyType, final String prefix) {
Expand All @@ -84,16 +87,16 @@ private static URL getSpecificProxyTypeUrlWithPrefix(final String proxyType, fin
try {

final String user = System.getProperty(proxyType + ".proxyUser");
if (StringUtils.isNotBlank(user)) {
if (org.apache.commons.lang3.StringUtils.isNotEmpty(user)) {
proxyUrlString += URLEncoder.encode(user, urlEncoding);
}

final String password = System.getProperty(proxyType + ".proxyPassword");
if (StringUtils.isNotBlank(password)) {
if (org.apache.commons.lang3.StringUtils.isNotEmpty(password)) {
proxyUrlString += ":" + URLEncoder.encode(password, urlEncoding);
}

if (StringUtils.isNotBlank(user)) {
if (org.apache.commons.lang3.StringUtils.isNotEmpty(user)) {
proxyUrlString += "@";
}

Expand Down
2 changes: 2 additions & 0 deletions docs/src/docs/browsercaps/proxy-setup.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ public abstract class AbstractTest extends TesterraTest {
}
}
----

NOTE: `WebDriverProxyUtils.getDefaultHttpProxy()` only returns the proxy configuration for HTTP, HTTPS and non-proxy connections.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import eu.tsystems.mms.tic.testframework.report.utils.ExecutionContextController;
import eu.tsystems.mms.tic.testframework.utils.ProxyUtils;
import eu.tsystems.mms.tic.testframework.utils.StringUtils;

import java.net.URL;

import org.openqa.selenium.Proxy;

public class WebDriverProxyUtils {
Expand Down Expand Up @@ -96,7 +98,6 @@ public Proxy createHttpProxyFromUrl(URL url) {
String proxyString = toProxyString(url);
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyString);
proxy.setFtpProxy(proxyString);
proxy.setSslProxy(proxyString);
return proxy;
}
Expand All @@ -115,7 +116,9 @@ public Proxy getDefaultSocksProxy() {
*/
public Proxy getDefaultHttpProxy() {
URL systemProxyUrl = ProxyUtils.getSystemHttpsProxyUrl();
if (systemProxyUrl == null) systemProxyUrl = ProxyUtils.getSystemHttpProxyUrl();
if (systemProxyUrl == null) {
systemProxyUrl = ProxyUtils.getSystemHttpProxyUrl();
}
Proxy proxy = createHttpProxyFromUrl(systemProxyUrl);
proxy.setNoProxy(PropertyManager.getProperty("https.nonProxyHosts"));
return proxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
* under the License.
*
*/
package eu.tsystems.mms.tic.testframework.test.utils;
package eu.tsystems.mms.tic.testframework.test.utils;

import eu.tsystems.mms.tic.testframework.testing.TesterraTest;
import eu.tsystems.mms.tic.testframework.utils.ProxyUtils;
import eu.tsystems.mms.tic.testframework.webdrivermanager.WebDriverProxyUtils;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.Proxy;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

/**
* Tests class for {@link ProxyUtils} and {@link WebDriverProxyUtils}
* <p>
Expand Down Expand Up @@ -131,8 +132,19 @@ public void test05_createProxyFromUrl() throws MalformedURLException {
WebDriverProxyUtils utils = new WebDriverProxyUtils();
String proxyString = "http://proxyUser:secretPassword@my-proxy:3128";
Proxy proxy = utils.createSocksProxyFromUrl(new URL(proxyString));
Assert.assertEquals(proxy.getHttpProxy(),"my-proxy:3128");
Assert.assertEquals(proxy.getSocksUsername(),"proxyUser");
Assert.assertEquals(proxy.getHttpProxy(), "my-proxy:3128");
Assert.assertEquals(proxy.getSocksUsername(), "proxyUser");
Assert.assertEquals(proxy.getSocksPassword(), "secretPassword");
}

@Test
public void test06_createDefaultProxyFromUrl() {
WebDriverProxyUtils utils = new WebDriverProxyUtils();
Proxy proxy = utils.getDefaultHttpProxy();

Assert.assertEquals(proxy.getHttpProxy(), PROXY_HOST_HTTPS + ":" + PROXY_PORT_HTTPS);
Assert.assertEquals(proxy.getSslProxy(), PROXY_HOST_HTTPS + ":" + PROXY_PORT_HTTPS);
Assert.assertNull(proxy.getFtpProxy());
Assert.assertNull(proxy.getSocksProxy());
}
}