Skip to content

Commit b23004e

Browse files
committed
Fix test
1 parent 5968b8f commit b23004e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

client/src/test/java/org/asynchttpclient/proxy/ProxyTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,21 @@ public void testProxyProperties() throws IOException, ExecutionException, Timeou
170170
// FIXME not threadsafe!
171171
Properties originalProps = new Properties();
172172
originalProps.putAll(System.getProperties());
173-
System.setProperty(ProxyUtils.PROXY_HOST, "localhost");
173+
System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1");
174174
System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
175175
System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "localhost");
176176
AsyncHttpClientConfigHelper.reloadProperties();
177177

178178
try (AsyncHttpClient client = asyncHttpClient(config().setUseProxyProperties(true))) {
179-
String target = "http://localhost:1234/";
180-
Future<Response> f = client.prepareGet(target).execute();
179+
String proxifiedtarget = "http://127.0.0.1:1234/";
180+
Future<Response> f = client.prepareGet(proxifiedtarget).execute();
181181
Response resp = f.get(3, TimeUnit.SECONDS);
182182
assertNotNull(resp);
183183
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
184184
assertEquals(resp.getHeader("target"), "/");
185185

186-
target = "http://localhost:1234/";
187-
f = client.prepareGet(target).execute();
186+
String nonProxifiedtarget = "http://localhost:1234/";
187+
f = client.prepareGet(nonProxifiedtarget).execute();
188188
try {
189189
resp = f.get(3, TimeUnit.SECONDS);
190190
fail("should not be able to connect");
@@ -220,27 +220,27 @@ public void testIgnoreProxyPropertiesByDefault() throws IOException, ExecutionEx
220220
}
221221
}
222222

223-
@Test(groups = "standalone", enabled = false)
223+
@Test(groups = "standalone", enabled = false)
224224
public void testProxyActivationProperty() throws IOException, ExecutionException, TimeoutException, InterruptedException {
225225
// FIXME not threadsafe!
226226
Properties originalProps = new Properties();
227227
originalProps.putAll(System.getProperties());
228-
System.setProperty(ProxyUtils.PROXY_HOST, "localhost");
228+
System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1");
229229
System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
230230
System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "localhost");
231231
System.setProperty(AsyncHttpClientConfigDefaults.ASYNC_CLIENT_CONFIG_ROOT + "useProxyProperties", "true");
232232
AsyncHttpClientConfigHelper.reloadProperties();
233233

234234
try (AsyncHttpClient client = asyncHttpClient()) {
235-
String target = "http://localhost:1234/";
236-
Future<Response> f = client.prepareGet(target).execute();
235+
String proxifiedTarget = "http://127.0.0.1:1234/";
236+
Future<Response> f = client.prepareGet(proxifiedTarget).execute();
237237
Response resp = f.get(3, TimeUnit.SECONDS);
238238
assertNotNull(resp);
239239
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
240240
assertEquals(resp.getHeader("target"), "/");
241241

242-
target = "http://localhost:1234/";
243-
f = client.prepareGet(target).execute();
242+
String nonProxifiedTarget = "http://localhost:1234/";
243+
f = client.prepareGet(nonProxifiedTarget).execute();
244244
try {
245245
resp = f.get(3, TimeUnit.SECONDS);
246246
fail("should not be able to connect");
@@ -257,14 +257,14 @@ public void testWildcardNonProxyHosts() throws IOException, ExecutionException,
257257
// FIXME not threadsafe!
258258
Properties originalProps = new Properties();
259259
originalProps.putAll(System.getProperties());
260-
System.setProperty(ProxyUtils.PROXY_HOST, "localhost");
260+
System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1");
261261
System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
262262
System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "127.*");
263263
AsyncHttpClientConfigHelper.reloadProperties();
264264

265265
try (AsyncHttpClient client = asyncHttpClient(config().setUseProxyProperties(true))) {
266-
String target = "http://localhost:1234/";
267-
Future<Response> f = client.prepareGet(target).execute();
266+
String nonProxifiedTarget = "http://127.0.0.1:1234/";
267+
Future<Response> f = client.prepareGet(nonProxifiedTarget).execute();
268268
try {
269269
f.get(3, TimeUnit.SECONDS);
270270
fail("should not be able to connect");
@@ -281,8 +281,8 @@ public void testUseProxySelector() throws IOException, ExecutionException, Timeo
281281
ProxySelector originalProxySelector = ProxySelector.getDefault();
282282
ProxySelector.setDefault(new ProxySelector() {
283283
public List<Proxy> select(URI uri) {
284-
if (uri.getHost().equals("localhost")) {
285-
return Arrays.asList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", port1)));
284+
if (uri.getHost().equals("127.0.0.1")) {
285+
return Arrays.asList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", port1)));
286286
} else {
287287
return Arrays.asList(Proxy.NO_PROXY);
288288
}
@@ -293,15 +293,15 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
293293
});
294294

295295
try (AsyncHttpClient client = asyncHttpClient(config().setUseProxySelector(true))) {
296-
String target = "http://localhost:1234/";
297-
Future<Response> f = client.prepareGet(target).execute();
296+
String proxifiedTarget = "http://127.0.0.1:1234/";
297+
Future<Response> f = client.prepareGet(proxifiedTarget).execute();
298298
Response resp = f.get(3, TimeUnit.SECONDS);
299299
assertNotNull(resp);
300300
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
301301
assertEquals(resp.getHeader("target"), "/");
302302

303-
target = "http://localhost:1234/";
304-
f = client.prepareGet(target).execute();
303+
String nonProxifiedTarget = "http://localhost:1234/";
304+
f = client.prepareGet(nonProxifiedTarget).execute();
305305
try {
306306
f.get(3, TimeUnit.SECONDS);
307307
fail("should not be able to connect");

0 commit comments

Comments
 (0)