2018-04-20 17:03:45 +02:00
|
|
|
package com.rarchives.ripme.tst;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URL;
|
|
|
|
import com.rarchives.ripme.utils.Proxy;
|
|
|
|
import com.rarchives.ripme.utils.Utils;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import com.rarchives.ripme.utils.Http;
|
|
|
|
|
|
|
|
|
|
|
|
public class proxyTest extends TestCase {
|
2018-04-20 18:53:49 +02:00
|
|
|
|
|
|
|
|
2018-04-20 18:15:39 +02:00
|
|
|
// This test will only run on machines where the user has added a entry for proxy.socks
|
2018-04-20 17:03:45 +02:00
|
|
|
public void testSocksProxy() throws IOException {
|
2018-04-20 18:53:49 +02:00
|
|
|
// Unset proxy before testing
|
|
|
|
System.setProperty("http.proxyHost", "");
|
|
|
|
System.setProperty("https.proxyHost", "");
|
|
|
|
System.setProperty("socksProxyHost", "");
|
2018-04-20 17:03:45 +02:00
|
|
|
URL url = new URL("https://icanhazip.com");
|
2018-04-20 18:15:39 +02:00
|
|
|
String proxyConfig = Utils.getConfigString("proxy.socks", "");
|
2018-04-20 17:03:45 +02:00
|
|
|
if (!proxyConfig.equals("")) {
|
|
|
|
String ip1 = Http.url(url).ignoreContentType().get().text();
|
2018-04-20 18:15:39 +02:00
|
|
|
Proxy.setSocks(Utils.getConfigString("proxy.socks", ""));
|
2018-04-20 17:03:45 +02:00
|
|
|
String ip2 = Http.url(url).ignoreContentType().get().text();
|
|
|
|
assertFalse(ip1.equals(ip2));
|
|
|
|
} else {
|
|
|
|
System.out.println("Skipping testSocksProxy");
|
|
|
|
assert(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:15:39 +02:00
|
|
|
// This test will only run on machines where the user has added a entry for proxy.http
|
2018-04-20 17:03:45 +02:00
|
|
|
public void testHTTPProxy() throws IOException {
|
2018-04-20 18:53:49 +02:00
|
|
|
// Unset proxy before testing
|
|
|
|
System.setProperty("http.proxyHost", "");
|
|
|
|
System.setProperty("https.proxyHost", "");
|
|
|
|
System.setProperty("socksProxyHost", "");
|
2018-04-20 17:03:45 +02:00
|
|
|
URL url = new URL("https://icanhazip.com");
|
2018-04-20 18:15:39 +02:00
|
|
|
String proxyConfig = Utils.getConfigString("proxy.http", "");
|
2018-04-20 17:03:45 +02:00
|
|
|
if (!proxyConfig.equals("")) {
|
|
|
|
String ip1 = Http.url(url).ignoreContentType().get().text();
|
2018-04-20 18:15:39 +02:00
|
|
|
Proxy.setHTTPProxy(Utils.getConfigString("proxy.http", ""));
|
2018-04-20 17:03:45 +02:00
|
|
|
String ip2 = Http.url(url).ignoreContentType().get().text();
|
|
|
|
assertFalse(ip1.equals(ip2));
|
|
|
|
} else {
|
|
|
|
System.out.println("Skipping testHTTPProxy");
|
|
|
|
assert(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|