495085: MockServer tests can pass when a proxy is
configured
Change-Id: Ie4bca4d6fbdb461843dc950c34bc4ff947a0c0ab
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=495085
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientPreemptiveAuthTest.java b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientPreemptiveAuthTest.java
index 43abdb9..3ee08df 100644
--- a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientPreemptiveAuthTest.java
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientPreemptiveAuthTest.java
@@ -13,6 +13,8 @@
import static org.junit.Assert.assertEquals;
+import java.net.Proxy;
+
import org.apache.http.HttpStatus;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationException;
@@ -49,7 +51,7 @@
@Test
public void testExecuteGetNoPreemptiveAuth() throws Exception {
- RepositoryLocation location = new RepositoryLocation(server.getUrl());
+ RepositoryLocation location = createLocation();
location.setCredentials(AuthenticationType.HTTP, new UserCredentials("user", "pass"));
CommonHttpClient client = new CommonHttpClient(location);
@@ -61,7 +63,7 @@
@Test(expected = AuthenticationException.class)
public void testExecuteGetAuthChallengeNoCredentials() throws Exception {
- RepositoryLocation location = new RepositoryLocation(server.getUrl());
+ RepositoryLocation location = createLocation();
CommonHttpClient client = new CommonHttpClient(location);
server.addResponse(MockServer.UNAUTHORIZED);
@@ -70,7 +72,7 @@
@Test
public void testExecuteGetAuthChallenge() throws Exception {
- RepositoryLocation location = new RepositoryLocation(server.getUrl());
+ RepositoryLocation location = createLocation();
location.setCredentials(AuthenticationType.HTTP, new UserCredentials("user", "pass"));
CommonHttpClient client = new CommonHttpClient(location);
@@ -85,7 +87,7 @@
@Test
public void testExecuteGetPreemptiveAuth() throws Exception {
- RepositoryLocation location = new RepositoryLocation(server.getUrl());
+ RepositoryLocation location = createLocation();
location.setCredentials(AuthenticationType.HTTP, new UserCredentials("user", "pass"));
CommonHttpClient client = new CommonHttpClient(location);
@@ -103,4 +105,12 @@
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}
+ private RepositoryLocation createLocation() {
+ return new RepositoryLocation(server.getUrl()) {
+ @Override
+ public Proxy getProxyForHost(String host, String proxyType) {
+ return null;// ensure that we do not try to connect to localhost through a proxy server
+ }
+ };
+ }
}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
index 06fa5ab..ef1d375 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
@@ -643,7 +643,12 @@
+ "<html><title>\u00C3\u00BC</title></html>";
server.addResponse(message);
String url = "http://" + proxyAddress.getHostName() + ":" + proxyAddress.getPort() + "/";
- assertEquals("\u00FC", WebUtil.getTitleFromUrl(new WebLocation(url), null));
+ assertEquals("\u00FC", WebUtil.getTitleFromUrl(new WebLocation(url) {
+ @Override
+ public Proxy getProxyForHost(String host, String proxyType) {
+ return null;// ensure that we do not try to connect to localhost through a proxy server
+ }
+ }, null));
}
// FIXME