Skip to content

Commit 5495b79

Browse files
committed
8220575: Correctly format test URI's that contain a retrieved IPv6 address
Reviewed-by: mdoerr Backport-of: 0c2b7c4
1 parent 25c33bc commit 5495b79

File tree

24 files changed

+248
-46
lines changed

24 files changed

+248
-46
lines changed

test/jdk/com/sun/net/httpserver/TestLogging.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/**
2525
* @test
2626
* @bug 6422914
27+
* @library /test/lib
2728
* @summary change httpserver exception printouts
2829
*/
2930

@@ -37,6 +38,7 @@
3738
import java.security.*;
3839
import java.security.cert.*;
3940
import javax.net.ssl.*;
41+
import jdk.test.lib.net.URIBuilder;
4042

4143
public class TestLogging extends Test {
4244

@@ -63,13 +65,25 @@ public static void main (String[] args) throws Exception {
6365

6466
int p1 = s1.getAddress().getPort();
6567

66-
URL url = new URL ("http://127.0.0.1:"+p1+"/test1/smallfile.txt");
68+
URL url = URIBuilder.newBuilder()
69+
.scheme("http")
70+
.loopback()
71+
.port(p1)
72+
.path("/test1/smallfile.txt")
73+
.toURLUnchecked();
74+
System.out.println("URL: " + url);
6775
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
6876
InputStream is = urlc.getInputStream();
6977
while (is.read() != -1) ;
7078
is.close();
7179

72-
url = new URL ("http://127.0.0.1:"+p1+"/test1/doesntexist.txt");
80+
url = URIBuilder.newBuilder()
81+
.scheme("http")
82+
.loopback()
83+
.port(p1)
84+
.path("/test1/doesntexist.txt")
85+
.toURLUnchecked();
86+
System.out.println("URL: " + url);
7387
urlc = (HttpURLConnection)url.openConnection();
7488
try {
7589
is = urlc.getInputStream();

test/jdk/com/sun/net/httpserver/bugs/6725892/Test.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/**
2525
* @test
2626
* @bug 6725892
27+
* @library /test/lib
2728
* @run main/othervm -Dsun.net.httpserver.maxReqTime=2 Test
2829
* @summary
2930
*/
@@ -36,6 +37,8 @@
3637
import java.net.*;
3738
import javax.net.ssl.*;
3839

40+
import jdk.test.lib.net.URIBuilder;
41+
3942
public class Test {
4043

4144
static HttpServer s1;
@@ -76,7 +79,13 @@ public static void main (String[] args) throws Exception {
7679

7780
port = s1.getAddress().getPort();
7881
System.out.println ("Server on port " + port);
79-
url = new URL ("http://127.0.0.1:"+port+"/foo");
82+
url = URIBuilder.newBuilder()
83+
.scheme("http")
84+
.loopback()
85+
.port(port)
86+
.path("/foo")
87+
.toURLUnchecked();
88+
System.out.println("URL: " + url);
8089
test1();
8190
test2();
8291
test3();

test/jdk/com/sun/net/httpserver/bugs/B6373555.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/**
2525
* @test
2626
* @bug 6373555
27+
* @library /test/lib
2728
* @summary HTTP Server failing to answer client requests
2829
*/
2930

@@ -32,6 +33,7 @@
3233
import java.util.*;
3334
import com.sun.net.httpserver.*;
3435
import java.util.concurrent.*;
36+
import jdk.test.lib.net.URIBuilder;
3537

3638
public class B6373555 {
3739

@@ -96,7 +98,13 @@ public void run() {
9698
try {
9799
Thread.sleep(10);
98100
byte[] buf = getBuf();
99-
URL url = new URL("http://127.0.0.1:"+port+"/test");
101+
URL url = URIBuilder.newBuilder()
102+
.scheme("http")
103+
.loopback()
104+
.port(port)
105+
.path("/test")
106+
.toURLUnchecked();
107+
System.out.println("URL: " + url);
100108
HttpURLConnection con = (HttpURLConnection)url.openConnection();
101109
con.setDoOutput(true);
102110
con.setDoInput(true);

test/jdk/com/sun/net/httpserver/bugs/B6401598.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test
26+
* @library /test/lib
2627
* @bug 6401598
2728
* @summary new HttpServer cannot serve binary stream data
2829
*/
@@ -31,9 +32,12 @@
3132
import java.net.HttpURLConnection;
3233
import java.net.MalformedURLException;
3334
import java.net.URL;
35+
import java.net.InetAddress;
3436
import java.net.InetSocketAddress;
3537
import java.util.concurrent.*;
3638

39+
import jdk.test.lib.net.URIBuilder;
40+
3741
import com.sun.net.httpserver.HttpExchange;
3842
import com.sun.net.httpserver.HttpHandler;
3943
import com.sun.net.httpserver.HttpServer;
@@ -90,7 +94,14 @@ public static void main(String[] args) {
9094
short counter;
9195

9296
for (counter = 0; counter < 1000; counter++) {
93-
HttpURLConnection connection = getHttpURLConnection(new URL("http://127.0.0.1:"+port+"/server/"), 10000);
97+
URL url = URIBuilder.newBuilder()
98+
.scheme("http")
99+
.loopback()
100+
.port(port)
101+
.path("/server/")
102+
.toURLUnchecked();
103+
System.out.println("URL: " + url);
104+
HttpURLConnection connection = getHttpURLConnection(url, 10000);
94105

95106
OutputStream os = connection.getOutputStream();
96107

test/jdk/java/net/HttpCookie/ExpiredCookieTest.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
/*
2525
* @test
2626
* @bug 8000525
27+
* @library /test/lib
2728
*/
2829

2930
import java.net.*;
3031
import java.util.*;
3132
import java.io.*;
3233
import java.text.*;
34+
import jdk.test.lib.net.URIBuilder;
3335

3436
public class ExpiredCookieTest {
3537
// lifted from HttpCookie.java
@@ -81,7 +83,13 @@ public static void main(String[] args) throws Exception {
8183
"TEST4=TEST4; Path=/; Expires=" + datestring.toString());
8284

8385
header.put("Set-Cookie", values);
84-
cm.put(new URI("http://127.0.0.1/"), header);
86+
URI uri = URIBuilder.newBuilder()
87+
.scheme("http")
88+
.loopback()
89+
.path("/")
90+
.buildUnchecked();
91+
System.out.println("URI: " + uri);
92+
cm.put(uri, header);
8593

8694
CookieStore cookieJar = cm.getCookieStore();
8795
List <HttpCookie> cookies = cookieJar.getCookies();

test/jdk/java/net/HttpURLConnection/NoProxyTest.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
/*
2525
* @test
2626
* @bug 8144008
27+
* @library /test/lib
2728
* @summary Setting NO_PROXY on HTTP URL connections does not stop proxying
2829
* @run main/othervm NoProxyTest
2930
*/
3031

3132
import java.io.IOException;
33+
import java.net.InetAddress;
3234
import java.net.MalformedURLException;
3335
import java.net.Proxy;
3436
import java.net.ProxySelector;
@@ -37,6 +39,7 @@
3739
import java.net.URL;
3840
import java.net.URLConnection;
3941
import java.util.List;
42+
import jdk.test.lib.net.URIBuilder;
4043

4144
public class NoProxyTest {
4245

@@ -52,7 +55,12 @@ public void connectFailed(URI u, SocketAddress s, IOException e) { }
5255
public static void main(String args[]) throws MalformedURLException {
5356
ProxySelector.setDefault(new NoProxyTestSelector());
5457

55-
URL url = URI.create("http://127.0.0.1/").toURL();
58+
URL url = URIBuilder.newBuilder()
59+
.scheme("http")
60+
.loopback()
61+
.path("/")
62+
.toURLUnchecked();
63+
System.out.println("URL: " + url);
5664
URLConnection connection;
5765
try {
5866
connection = url.openConnection(Proxy.NO_PROXY);

test/jdk/java/net/ProxySelector/NullSelector.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,22 @@
2323

2424
/* @test
2525
* @bug 6215885
26+
* @library /test/lib
2627
* @summary URLConnection.openConnection NPE if ProxySelector.setDefault is set to null
2728
*/
2829

2930
import java.net.*;
3031
import java.io.*;
32+
import jdk.test.lib.net.URIBuilder;
3133

3234
public class NullSelector {
3335
public static void main(String[] args) throws Exception {
34-
URL url = new URL("http://127.0.0.1/");
36+
URL url = URIBuilder.newBuilder()
37+
.scheme("http")
38+
.loopback()
39+
.path("/")
40+
.toURLUnchecked();
41+
System.out.println("URL: " + url);
3542
ProxySelector.setDefault(null);
3643
URLConnection con = url.openConnection();
3744
con.setConnectTimeout(500);

test/jdk/java/net/ResponseCache/Test2.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/**
2525
* @test
2626
* @bug 8042622
27+
* @library /test/lib
2728
* @summary Check for CRL results in IllegalArgumentException "white space not allowed"
2829
* @modules jdk.httpserver
2930
* @run main/othervm Test2
@@ -38,6 +39,7 @@
3839
import java.security.*;
3940
import javax.security.auth.callback.*;
4041
import javax.net.ssl.*;
42+
import jdk.test.lib.net.URIBuilder;
4143

4244
public class Test2 {
4345

@@ -63,7 +65,7 @@ public CacheRequest put(URI uri, URLConnection c) throws IOException {
6365

6466
static int port;
6567

66-
static String urlstring, redirstring;
68+
static URL url, redir;
6769

6870
public static void main (String[] args) throws Exception {
6971
Handler handler = new Handler();
@@ -78,10 +80,21 @@ public static void main (String[] args) throws Exception {
7880
server.setExecutor (executor);
7981
server.start ();
8082

81-
urlstring = "http://127.0.0.1:" + Integer.toString(port)+"/test/foo";
82-
redirstring = urlstring + "/redirect/bar";
83+
url = URIBuilder.newBuilder()
84+
.scheme("http")
85+
.loopback()
86+
.port(port)
87+
.path("/test/foo")
88+
.toURLUnchecked();
89+
System.out.println("URL: " + url);
90+
redir = URIBuilder.newBuilder()
91+
.scheme("http")
92+
.loopback()
93+
.port(port)
94+
.path("/test/foo/redirect/bar")
95+
.toURLUnchecked();
96+
System.out.println("Redir URL: " + redir);
8397

84-
URL url = new URL (urlstring);
8598
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
8699
urlc.addRequestProperty("X-Foo", "bar");
87100
urlc.setInstanceFollowRedirects(true);
@@ -114,7 +127,7 @@ public void handle (HttpExchange t)
114127
Headers rmap = t.getResponseHeaders();
115128
invocation ++;
116129
if (invocation == 1) {
117-
rmap.add("Location", redirstring);
130+
rmap.add("Location", redir.toString());
118131
while (is.read () != -1) ;
119132
is.close();
120133
System.out.println ("sending response");

test/jdk/java/net/URLClassLoader/closetest/CloseTest.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.nio.file.Paths;
5151

5252
import jdk.test.lib.compiler.CompilerUtils;
53+
import jdk.test.lib.net.URIBuilder;
5354
import jdk.test.lib.util.JarUtils;
5455

5556
import com.sun.net.httpserver.HttpContext;
@@ -158,8 +159,12 @@ static HttpServer getHttpServer() {
158159

159160
static URL getServerURL() throws Exception {
160161
int port = httpServer.getAddress().getPort();
161-
String s = "http://127.0.0.1:" + port + "/";
162-
return new URL(s);
162+
return URIBuilder.newBuilder()
163+
.scheme("http")
164+
.loopback()
165+
.port(port)
166+
.path("/")
167+
.toURL();
163168
}
164169

165170
static void startHttpServer(String docroot) throws Exception {

test/jdk/java/net/URLConnection/TimeoutTest.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
/*
2525
* @test
2626
* @bug 4389976
27+
* @library /test/lib
2728
* @summary can't unblock read() of InputStream from URL connection
2829
* @run main/timeout=40/othervm -Dsun.net.client.defaultReadTimeout=2000 TimeoutTest
2930
*/
3031

3132
import java.io.*;
3233
import java.net.*;
34+
import jdk.test.lib.net.URIBuilder;
3335

3436
public class TimeoutTest {
3537

@@ -68,7 +70,12 @@ public void test() throws Exception {
6870
ServerSocket ss = new ServerSocket(0);
6971
Server s = new Server (ss);
7072
try{
71-
URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort());
73+
URL url = URIBuilder.newBuilder()
74+
.scheme("http")
75+
.loopback()
76+
.port(ss.getLocalPort())
77+
.toURL();
78+
System.out.println("URL: " + url);
7279
URLConnection urlc = url.openConnection ();
7380
InputStream is = urlc.getInputStream ();
7481
throw new RuntimeException("Should have received timeout");

test/jdk/java/net/URLPermission/OpenURL.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
/*
2525
* @test
2626
* @bug 8029354
27+
* @library /test/lib
2728
* @run main/othervm OpenURL
2829
*/
2930

3031
import java.net.*;
3132
import java.io.*;
33+
import jdk.test.lib.net.URIBuilder;
3234

3335
public class OpenURL {
3436

@@ -37,7 +39,13 @@ public static void main (String[] args) throws Exception {
3739
System.setSecurityManager(new SecurityManager());
3840

3941
try {
40-
URL url = new URL ("http://joe@127.0.0.1/a/b");
42+
URL url = URIBuilder.newBuilder()
43+
.scheme("http")
44+
.userInfo("joe")
45+
.loopback()
46+
.path("/a/b")
47+
.toURL();
48+
System.out.println("URL: " + url);
4149
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
4250
InputStream is = urlc.getInputStream();
4351
// error will throw exception other than SecurityException

0 commit comments

Comments
 (0)