Skip to content
Permalink
Browse files
8220575: Correctly format test URI's that contain a retrieved IPv6 ad…
…dress

Reviewed-by: mdoerr
Backport-of: 0c2b7c4
  • Loading branch information
RealCLanger committed Oct 25, 2021
1 parent 25c33bc commit 5495b791d600ecb37f8ad12ff195ddfc10430161
Showing with 248 additions and 46 deletions.
  1. +16 −2 test/jdk/com/sun/net/httpserver/TestLogging.java
  2. +10 −1 test/jdk/com/sun/net/httpserver/bugs/6725892/Test.java
  3. +9 −1 test/jdk/com/sun/net/httpserver/bugs/B6373555.java
  4. +12 −1 test/jdk/com/sun/net/httpserver/bugs/B6401598.java
  5. +9 −1 test/jdk/java/net/HttpCookie/ExpiredCookieTest.java
  6. +9 −1 test/jdk/java/net/HttpURLConnection/NoProxyTest.java
  7. +8 −1 test/jdk/java/net/ProxySelector/NullSelector.java
  8. +18 −5 test/jdk/java/net/ResponseCache/Test2.java
  9. +7 −2 test/jdk/java/net/URLClassLoader/closetest/CloseTest.java
  10. +8 −1 test/jdk/java/net/URLConnection/TimeoutTest.java
  11. +9 −1 test/jdk/java/net/URLPermission/OpenURL.java
  12. +9 −1 test/jdk/java/net/httpclient/LargeResponseContent.java
  13. +12 −5 test/jdk/sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java
  14. +10 −1 test/jdk/sun/net/www/protocol/http/6550798/test.java
  15. +5 −1 test/jdk/sun/net/www/protocol/http/B6890349.java
  16. +11 −2 test/jdk/sun/net/www/protocol/http/B8012625.java
  17. +10 −1 test/jdk/sun/net/www/protocol/http/NoNTLM.java
  18. +28 −12 test/jdk/sun/net/www/protocol/http/RedirectOnPost.java
  19. +8 −1 test/jdk/sun/net/www/protocol/http/ResponseCacheStream.java
  20. +8 −1 test/jdk/sun/net/www/protocol/http/RetryUponTimeout.java
  21. +8 −1 test/jdk/sun/net/www/protocol/http/SetChunkedStreamingMode.java
  22. +8 −1 test/jdk/sun/net/www/protocol/http/UserAgent.java
  23. +8 −1 test/jdk/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java
  24. +8 −1 test/jdk/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java
@@ -24,6 +24,7 @@
/**
* @test
* @bug 6422914
* @library /test/lib
* @summary change httpserver exception printouts
*/

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

public class TestLogging extends Test {

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

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

URL url = new URL ("http://127.0.0.1:"+p1+"/test1/smallfile.txt");
URL url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(p1)
.path("/test1/smallfile.txt")
.toURLUnchecked();
System.out.println("URL: " + url);
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
InputStream is = urlc.getInputStream();
while (is.read() != -1) ;
is.close();

url = new URL ("http://127.0.0.1:"+p1+"/test1/doesntexist.txt");
url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(p1)
.path("/test1/doesntexist.txt")
.toURLUnchecked();
System.out.println("URL: " + url);
urlc = (HttpURLConnection)url.openConnection();
try {
is = urlc.getInputStream();
@@ -24,6 +24,7 @@
/**
* @test
* @bug 6725892
* @library /test/lib
* @run main/othervm -Dsun.net.httpserver.maxReqTime=2 Test
* @summary
*/
@@ -36,6 +37,8 @@
import java.net.*;
import javax.net.ssl.*;

import jdk.test.lib.net.URIBuilder;

public class Test {

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

port = s1.getAddress().getPort();
System.out.println ("Server on port " + port);
url = new URL ("http://127.0.0.1:"+port+"/foo");
url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(port)
.path("/foo")
.toURLUnchecked();
System.out.println("URL: " + url);
test1();
test2();
test3();
@@ -24,6 +24,7 @@
/**
* @test
* @bug 6373555
* @library /test/lib
* @summary HTTP Server failing to answer client requests
*/

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

public class B6373555 {

@@ -96,7 +98,13 @@ public void run() {
try {
Thread.sleep(10);
byte[] buf = getBuf();
URL url = new URL("http://127.0.0.1:"+port+"/test");
URL url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(port)
.path("/test")
.toURLUnchecked();
System.out.println("URL: " + url);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
@@ -23,6 +23,7 @@

/**
* @test
* @library /test/lib
* @bug 6401598
* @summary new HttpServer cannot serve binary stream data
*/
@@ -31,9 +32,12 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.*;

import jdk.test.lib.net.URIBuilder;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
@@ -90,7 +94,14 @@ public static void main(String[] args) {
short counter;

for (counter = 0; counter < 1000; counter++) {
HttpURLConnection connection = getHttpURLConnection(new URL("http://127.0.0.1:"+port+"/server/"), 10000);
URL url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(port)
.path("/server/")
.toURLUnchecked();
System.out.println("URL: " + url);
HttpURLConnection connection = getHttpURLConnection(url, 10000);

OutputStream os = connection.getOutputStream();

@@ -24,12 +24,14 @@
/*
* @test
* @bug 8000525
* @library /test/lib
*/

import java.net.*;
import java.util.*;
import java.io.*;
import java.text.*;
import jdk.test.lib.net.URIBuilder;

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

header.put("Set-Cookie", values);
cm.put(new URI("http://127.0.0.1/"), header);
URI uri = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.path("/")
.buildUnchecked();
System.out.println("URI: " + uri);
cm.put(uri, header);

CookieStore cookieJar = cm.getCookieStore();
List <HttpCookie> cookies = cookieJar.getCookies();
@@ -24,11 +24,13 @@
/*
* @test
* @bug 8144008
* @library /test/lib
* @summary Setting NO_PROXY on HTTP URL connections does not stop proxying
* @run main/othervm NoProxyTest
*/

import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.ProxySelector;
@@ -37,6 +39,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import jdk.test.lib.net.URIBuilder;

public class NoProxyTest {

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

URL url = URI.create("http://127.0.0.1/").toURL();
URL url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.path("/")
.toURLUnchecked();
System.out.println("URL: " + url);
URLConnection connection;
try {
connection = url.openConnection(Proxy.NO_PROXY);
@@ -23,15 +23,22 @@

/* @test
* @bug 6215885
* @library /test/lib
* @summary URLConnection.openConnection NPE if ProxySelector.setDefault is set to null
*/

import java.net.*;
import java.io.*;
import jdk.test.lib.net.URIBuilder;

public class NullSelector {
public static void main(String[] args) throws Exception {
URL url = new URL("http://127.0.0.1/");
URL url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.path("/")
.toURLUnchecked();
System.out.println("URL: " + url);
ProxySelector.setDefault(null);
URLConnection con = url.openConnection();
con.setConnectTimeout(500);
@@ -24,6 +24,7 @@
/**
* @test
* @bug 8042622
* @library /test/lib
* @summary Check for CRL results in IllegalArgumentException "white space not allowed"
* @modules jdk.httpserver
* @run main/othervm Test2
@@ -38,6 +39,7 @@
import java.security.*;
import javax.security.auth.callback.*;
import javax.net.ssl.*;
import jdk.test.lib.net.URIBuilder;

public class Test2 {

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

static int port;

static String urlstring, redirstring;
static URL url, redir;

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

urlstring = "http://127.0.0.1:" + Integer.toString(port)+"/test/foo";
redirstring = urlstring + "/redirect/bar";
url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(port)
.path("/test/foo")
.toURLUnchecked();
System.out.println("URL: " + url);
redir = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(port)
.path("/test/foo/redirect/bar")
.toURLUnchecked();
System.out.println("Redir URL: " + redir);

URL url = new URL (urlstring);
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
urlc.addRequestProperty("X-Foo", "bar");
urlc.setInstanceFollowRedirects(true);
@@ -114,7 +127,7 @@ public void handle (HttpExchange t)
Headers rmap = t.getResponseHeaders();
invocation ++;
if (invocation == 1) {
rmap.add("Location", redirstring);
rmap.add("Location", redir.toString());
while (is.read () != -1) ;
is.close();
System.out.println ("sending response");
@@ -50,6 +50,7 @@
import java.nio.file.Paths;

import jdk.test.lib.compiler.CompilerUtils;
import jdk.test.lib.net.URIBuilder;
import jdk.test.lib.util.JarUtils;

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

static URL getServerURL() throws Exception {
int port = httpServer.getAddress().getPort();
String s = "http://127.0.0.1:" + port + "/";
return new URL(s);
return URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(port)
.path("/")
.toURL();
}

static void startHttpServer(String docroot) throws Exception {
@@ -24,12 +24,14 @@
/*
* @test
* @bug 4389976
* @library /test/lib
* @summary can't unblock read() of InputStream from URL connection
* @run main/timeout=40/othervm -Dsun.net.client.defaultReadTimeout=2000 TimeoutTest
*/

import java.io.*;
import java.net.*;
import jdk.test.lib.net.URIBuilder;

public class TimeoutTest {

@@ -68,7 +70,12 @@ public void test() throws Exception {
ServerSocket ss = new ServerSocket(0);
Server s = new Server (ss);
try{
URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort());
URL url = URIBuilder.newBuilder()
.scheme("http")
.loopback()
.port(ss.getLocalPort())
.toURL();
System.out.println("URL: " + url);
URLConnection urlc = url.openConnection ();
InputStream is = urlc.getInputStream ();
throw new RuntimeException("Should have received timeout");
@@ -24,11 +24,13 @@
/*
* @test
* @bug 8029354
* @library /test/lib
* @run main/othervm OpenURL
*/

import java.net.*;
import java.io.*;
import jdk.test.lib.net.URIBuilder;

public class OpenURL {

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

try {
URL url = new URL ("http://joe@127.0.0.1/a/b");
URL url = URIBuilder.newBuilder()
.scheme("http")
.userInfo("joe")
.loopback()
.path("/a/b")
.toURL();
System.out.println("URL: " + url);
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
InputStream is = urlc.getInputStream();
// error will throw exception other than SecurityException
Loading

1 comment on commit 5495b79

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 5495b79 Oct 25, 2021

Please sign in to comment.