8231504: Update networking tests to avoid implicit dependency on the system proxies
authorchegar
Fri, 27 Sep 2019 09:55:35 +0100
changeset 58365 73950479184b
parent 58364 2c87d191056c
child 58366 222a91b9438a
8231504: Update networking tests to avoid implicit dependency on the system proxies Reviewed-by: dfuchs
test/jdk/java/net/CookieHandler/LocalHostCookie.java
test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTest.java
test/jdk/java/net/ProxySelector/NullSelector.java
test/jdk/java/net/ResponseCache/B6181108.java
test/jdk/java/net/ResponseCache/ResponseCacheTest.java
test/jdk/java/net/ResponseCache/getResponseCode.java
test/jdk/java/net/URLConnection/B5052093.java
test/jdk/java/net/URLConnection/DisconnectAfterEOF.java
test/jdk/java/net/URLConnection/HttpContinueStackOverflow.java
test/jdk/java/net/URLConnection/Redirect307Test.java
test/jdk/java/net/URLConnection/Responses.java
test/jdk/java/net/URLConnection/URLConnectionHeaders.java
test/jdk/java/net/URLConnection/contentHandler/UserContentHandler.java
test/jdk/java/net/URLPermission/OpenURL.java
test/jdk/java/net/httpclient/ManyRequestsLegacy.java
test/jdk/java/net/httpclient/PlainProxyConnectionTest.java
test/jdk/java/net/httpclient/ProxyTest.java
test/jdk/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java
test/jdk/sun/net/www/protocol/http/UserAuth.java
test/jdk/sun/net/www/protocol/http/UserCookie.java
--- a/test/jdk/java/net/CookieHandler/LocalHostCookie.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/CookieHandler/LocalHostCookie.java	Fri Sep 27 09:55:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,7 @@
 import java.net.*;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.Executors;
+import static java.net.Proxy.NO_PROXY;
 
 /*
  * @test
@@ -52,7 +52,7 @@
             s = new Server();
             s.startServer();
             URL url = new URL("http","localhost", s.getPort(), "/");
-            HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
+            HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(NO_PROXY);
             urlConnection.setRequestMethod("GET");
             urlConnection.setDoOutput(true);
             urlConnection.connect();
--- a/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTest.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/HttpURLConnection/SetAuthenticator/HTTPTest.java	Fri Sep 27 09:55:35 2019 +0100
@@ -40,6 +40,7 @@
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLSession;
 import jdk.test.lib.net.SimpleSSLContext;
+import static java.net.Proxy.NO_PROXY;
 
 /*
  * @test
@@ -296,7 +297,7 @@
         HttpURLConnection conn = (HttpURLConnection)
                 (authType == HttpAuthType.PROXY
                     ? url.openConnection(proxy)
-                    : url.openConnection());
+                    : url.openConnection(NO_PROXY));
         return conn;
     }
 }
--- a/test/jdk/java/net/ProxySelector/NullSelector.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/ProxySelector/NullSelector.java	Fri Sep 27 09:55:35 2019 +0100
@@ -25,6 +25,7 @@
  * @bug 6215885
  * @library /test/lib
  * @summary URLConnection.openConnection NPE if ProxySelector.setDefault is set to null
+ * @run main/othervm NullSelector
  */
 
 import java.net.*;
--- a/test/jdk/java/net/ResponseCache/B6181108.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/ResponseCache/B6181108.java	Fri Sep 27 09:55:35 2019 +0100
@@ -33,6 +33,7 @@
 import java.util.*;
 import java.io.*;
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 public class B6181108 implements Runnable {
     ServerSocket ss;
@@ -105,7 +106,7 @@
                    .toString();
         urlWithSpace = base + "/space%20test/page1.html";
         URL url = new URL(urlWithSpace);
-        URLConnection urlc = url.openConnection();
+        URLConnection urlc = url.openConnection(NO_PROXY);
         int i = ((HttpURLConnection)(urlc)).getResponseCode();
         System.out.println("response code = " + i);
         ResponseCache.setDefault(null);
--- a/test/jdk/java/net/ResponseCache/ResponseCacheTest.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/ResponseCache/ResponseCacheTest.java	Fri Sep 27 09:55:35 2019 +0100
@@ -33,6 +33,7 @@
 import java.io.*;
 import javax.net.ssl.*;
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 /**
  * Request should get serviced by the cache handler. Response get
@@ -137,7 +138,7 @@
                    .port(ss.getLocalPort())
                    .path("/file2.1")
                    .toURL();
-        http = (HttpURLConnection)url2.openConnection();
+        http = (HttpURLConnection)url2.openConnection(NO_PROXY);
         System.out.println("responsecode2 is :"+http.getResponseCode());
         Map<String,List<String>> headers2 = http.getHeaderFields();
 
--- a/test/jdk/java/net/ResponseCache/getResponseCode.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/ResponseCache/getResponseCode.java	Fri Sep 27 09:55:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,7 @@
 import java.net.*;
 import java.util.*;
 import java.io.*;
+import static java.net.Proxy.NO_PROXY;
 
 
 /**
@@ -43,7 +44,7 @@
 
     getResponseCode() throws Exception {
         url = new URL("http://localhost/file1.cache");
-        HttpURLConnection http = (HttpURLConnection)url.openConnection();
+        HttpURLConnection http = (HttpURLConnection)url.openConnection(NO_PROXY);
         int respCode = http.getResponseCode();
         http.disconnect();
 
--- a/test/jdk/java/net/URLConnection/B5052093.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLConnection/B5052093.java	Fri Sep 27 09:55:35 2019 +0100
@@ -33,6 +33,7 @@
 import java.net.*;
 import java.io.*;
 import sun.net.www.protocol.file.FileURLConnection;
+import static java.net.Proxy.NO_PROXY;
 
 public class B5052093 implements HttpCallback {
     private static TestHttpServer server;
@@ -68,7 +69,7 @@
         server = new TestHttpServer(new B5052093(), 1, 10, loopback, 0);
         try {
             URL url = new URL("http://" + server.getAuthority() + "/foo");
-            URLConnection conn = url.openConnection();
+            URLConnection conn = url.openConnection(NO_PROXY);
             int i = conn.getContentLength();
             long l = conn.getContentLengthLong();
             if (i != -1 || l != testSize) {
--- a/test/jdk/java/net/URLConnection/DisconnectAfterEOF.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLConnection/DisconnectAfterEOF.java	Fri Sep 27 09:55:35 2019 +0100
@@ -33,8 +33,7 @@
 import java.io.*;
 import java.util.*;
 import jdk.test.lib.net.URIBuilder;
-
-
+import static java.net.Proxy.NO_PROXY;
 
 public class DisconnectAfterEOF {
 
@@ -217,7 +216,7 @@
     }
 
     static URLConnection doRequest(String uri) throws IOException {
-        URLConnection uc = (new URL(uri)).openConnection();
+        URLConnection uc = (new URL(uri)).openConnection(NO_PROXY);
         uc.setDoOutput(true);
         OutputStream out = uc.getOutputStream();
         out.write(new byte[16000]);
--- a/test/jdk/java/net/URLConnection/HttpContinueStackOverflow.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLConnection/HttpContinueStackOverflow.java	Fri Sep 27 09:55:35 2019 +0100
@@ -38,8 +38,8 @@
 import java.net.Socket;
 import java.net.URL;
 import java.net.HttpURLConnection;
-
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 public class HttpContinueStackOverflow {
 
@@ -93,7 +93,7 @@
                 .path("/anything.html")
                 .toURL();
 
-        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+        HttpURLConnection conn = (HttpURLConnection)url.openConnection(NO_PROXY);
         conn.getResponseCode();
         System.out.println("TEST PASSED");
     }
--- a/test/jdk/java/net/URLConnection/Redirect307Test.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLConnection/Redirect307Test.java	Fri Sep 27 09:55:35 2019 +0100
@@ -29,8 +29,8 @@
  */
 import java.io.*;
 import java.net.*;
-
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 class RedirServer extends Thread {
 
@@ -113,7 +113,7 @@
                 .loopback()
                 .port(port)
                 .toURL();
-        URLConnection conURL =  url.openConnection();
+        URLConnection conURL =  url.openConnection(NO_PROXY);
         conURL.setDoInput(true);
         conURL.setAllowUserInteraction(false);
         conURL.setUseCaches(false);
--- a/test/jdk/java/net/URLConnection/Responses.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLConnection/Responses.java	Fri Sep 27 09:55:35 2019 +0100
@@ -29,6 +29,7 @@
  */
 import java.net.*;
 import java.io.*;
+import static java.net.Proxy.NO_PROXY;
 
 public class Responses {
 
@@ -149,7 +150,7 @@
             System.out.println("Test with response: >" + tests[i][0] + "<");
 
             URL url = new URL("http://" + authority + "/" + i);
-            HttpURLConnection http = (HttpURLConnection)url.openConnection();
+            HttpURLConnection http = (HttpURLConnection)url.openConnection(NO_PROXY);
 
             try {
 
--- a/test/jdk/java/net/URLConnection/URLConnectionHeaders.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLConnection/URLConnectionHeaders.java	Fri Sep 27 09:55:35 2019 +0100
@@ -35,6 +35,7 @@
 import java.util.*;
 import java.io.*;
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 public class URLConnectionHeaders {
 
@@ -94,7 +95,7 @@
                       .port(port)
                       .path("/index.html")
                       .toURL();
-            URLConnection uc = url.openConnection();
+            URLConnection uc = url.openConnection(NO_PROXY);
 
             // add request properties
             uc.addRequestProperty("Cookie", "cookie1");
--- a/test/jdk/java/net/URLConnection/contentHandler/UserContentHandler.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLConnection/contentHandler/UserContentHandler.java	Fri Sep 27 09:55:35 2019 +0100
@@ -40,6 +40,7 @@
 import java.io.*;
 import java.util.*;
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 public class UserContentHandler implements Runnable {
 
@@ -98,7 +99,7 @@
                 .path("/anything.txt")
                 .toURL();
 
-        if (!(u.openConnection().getContent() instanceof String)) {
+        if (!(u.openConnection(NO_PROXY).getContent() instanceof String)) {
             throw new RuntimeException("Load user defined content handler failed.");
         } else {
             System.err.println("Load user defined content handler succeed!");
--- a/test/jdk/java/net/URLPermission/OpenURL.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/URLPermission/OpenURL.java	Fri Sep 27 09:55:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
 import java.net.*;
 import java.io.*;
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 public class OpenURL {
 
@@ -46,7 +47,7 @@
                 .path("/a/b")
                 .toURL();
             System.out.println("URL: " + url);
-            HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
+            HttpURLConnection urlc = (HttpURLConnection)url.openConnection(NO_PROXY);
             InputStream is = urlc.getInputStream();
             // error will throw exception other than SecurityException
         } catch (SecurityException e) {
--- a/test/jdk/java/net/httpclient/ManyRequestsLegacy.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/httpclient/ManyRequestsLegacy.java	Fri Sep 27 09:55:35 2019 +0100
@@ -74,6 +74,7 @@
 import java.util.logging.Logger;
 import java.util.logging.Level;
 import jdk.test.lib.net.SimpleSSLContext;
+import static java.net.Proxy.NO_PROXY;
 
 public class ManyRequestsLegacy {
 
@@ -159,7 +160,7 @@
             long start = System.nanoTime();
             try {
                 CompletableFuture<LegacyHttpResponse> cf = new CompletableFuture<>();
-                URLConnection urlc = r.uri().toURL().openConnection();
+                URLConnection urlc = r.uri().toURL().openConnection(NO_PROXY);
                 HttpURLConnection httpc = (HttpURLConnection)urlc;
                 httpc.setRequestMethod(r.method());
                 for (String s : r.headers().map().keySet()) {
--- a/test/jdk/java/net/httpclient/PlainProxyConnectionTest.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/httpclient/PlainProxyConnectionTest.java	Fri Sep 27 09:55:35 2019 +0100
@@ -44,6 +44,7 @@
 import java.net.http.HttpRequest;
 import java.net.http.HttpResponse;
 import java.util.stream.Collectors;
+import static java.net.Proxy.NO_PROXY;
 
 /**
  * @test
@@ -139,7 +140,7 @@
         throws IOException {
         connections.clear();
         System.out.println("Verifying communication with server");
-        try (InputStream is = uri.toURL().openConnection().getInputStream()) {
+        try (InputStream is = uri.toURL().openConnection(NO_PROXY).getInputStream()) {
             String resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
             System.out.println(resp);
             if (!RESPONSE.equals(resp)) {
--- a/test/jdk/java/net/httpclient/ProxyTest.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/java/net/httpclient/ProxyTest.java	Fri Sep 27 09:55:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -57,6 +57,7 @@
 import java.net.http.HttpRequest;
 import java.net.http.HttpResponse;
 import jdk.test.lib.net.SimpleSSLContext;
+import static java.net.Proxy.NO_PROXY;
 
 /**
  * @test
@@ -167,7 +168,7 @@
         System.out.println("Verifying communication with server");
         URI uri = new URI("https://localhost:"
                           + server.getAddress().getPort() + PATH + "x");
-        try (InputStream is = uri.toURL().openConnection().getInputStream()) {
+        try (InputStream is = uri.toURL().openConnection(NO_PROXY).getInputStream()) {
             String resp = new String(is.readAllBytes(), StandardCharsets.UTF_8);
             System.out.println(resp);
             if (!RESPONSE.equals(resp)) {
--- a/test/jdk/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java	Fri Sep 27 09:55:35 2019 +0100
@@ -33,6 +33,7 @@
 import java.net.*;
 import java.io.*;
 import jdk.test.lib.net.URIBuilder;
+import static java.net.Proxy.NO_PROXY;
 
 public class KeepAliveTimerThread {
     static class Fetcher implements Runnable {
@@ -44,7 +45,7 @@
 
         public void run() {
             try {
-                InputStream in = url.openConnection().getInputStream();
+                InputStream in = url.openConnection(NO_PROXY).getInputStream();
                 byte b[] = new byte[128];
                 int n;
                 do {
--- a/test/jdk/sun/net/www/protocol/http/UserAuth.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/sun/net/www/protocol/http/UserAuth.java	Fri Sep 27 09:55:35 2019 +0100
@@ -35,7 +35,7 @@
 import java.io.*;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ExecutorService;
-
+import static java.net.Proxy.NO_PROXY;
 
 public class UserAuth
 {
@@ -61,7 +61,7 @@
 
             // GET Request
             URL url = new URL("http://" + address.getHostName() + ":" + address.getPort() + "/redirect/");
-            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
+            HttpURLConnection uc = (HttpURLConnection)url.openConnection(NO_PROXY);
             uc.setRequestProperty("Authorization", "testString:ValueDoesNotMatter");
             int resp = uc.getResponseCode();
 
--- a/test/jdk/sun/net/www/protocol/http/UserCookie.java	Thu Sep 26 14:41:09 2019 -0700
+++ b/test/jdk/sun/net/www/protocol/http/UserCookie.java	Fri Sep 27 09:55:35 2019 +0100
@@ -33,6 +33,7 @@
 import com.sun.net.httpserver.*;
 import java.util.*;
 import java.io.*;
+import static java.net.Proxy.NO_PROXY;
 
 public class UserCookie
 {
@@ -59,7 +60,7 @@
             InetSocketAddress address = httpServer.getAddress();
 
             URL url = new URL("http://" + address.getHostName() + ":" + address.getPort() + "/test/");
-            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
+            HttpURLConnection uc = (HttpURLConnection)url.openConnection(NO_PROXY);
             uc.setRequestProperty("Cookie", "value=ValueDoesNotMatter");
             int resp = uc.getResponseCode();