mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8224761: Replace wildcard address with loopback or local host in tests - part 12
Fixes a batch of intermittent failures. Reviewed-by: chegar, vtewari
This commit is contained in:
parent
625020c0fd
commit
5461726dcc
10 changed files with 124 additions and 56 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -27,6 +27,7 @@
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @build jdk.test.lib.net.SimpleSSLContext
|
* @build jdk.test.lib.net.SimpleSSLContext
|
||||||
* @run main/othervm Test6a
|
* @run main/othervm Test6a
|
||||||
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true Test6a
|
||||||
* @summary Light weight HTTP server
|
* @summary Light weight HTTP server
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -38,6 +39,8 @@ import java.net.*;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import jdk.test.lib.net.SimpleSSLContext;
|
import jdk.test.lib.net.SimpleSSLContext;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test https POST large file via chunked encoding (unusually small chunks)
|
* Test https POST large file via chunked encoding (unusually small chunks)
|
||||||
*/
|
*/
|
||||||
|
@ -46,7 +49,8 @@ public class Test6a extends Test {
|
||||||
|
|
||||||
public static void main (String[] args) throws Exception {
|
public static void main (String[] args) throws Exception {
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
InetSocketAddress addr = new InetSocketAddress (0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
|
InetSocketAddress addr = new InetSocketAddress (loopback, 0);
|
||||||
HttpsServer server = HttpsServer.create (addr, 0);
|
HttpsServer server = HttpsServer.create (addr, 0);
|
||||||
HttpContext ctx = server.createContext ("/test", handler);
|
HttpContext ctx = server.createContext ("/test", handler);
|
||||||
ExecutorService executor = Executors.newCachedThreadPool();
|
ExecutorService executor = Executors.newCachedThreadPool();
|
||||||
|
@ -55,9 +59,16 @@ public class Test6a extends Test {
|
||||||
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
|
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
|
||||||
server.start ();
|
server.start ();
|
||||||
|
|
||||||
URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
|
URL url = URIBuilder.newBuilder()
|
||||||
System.out.print ("Test6a: " );
|
.scheme("https")
|
||||||
HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
|
.host(server.getAddress().getAddress())
|
||||||
|
.port(server.getAddress().getPort())
|
||||||
|
.path("/test/foo.html")
|
||||||
|
.toURL();
|
||||||
|
|
||||||
|
System.out.println("Test6a: URL=" + url);
|
||||||
|
System.out.print("Test6a: ");
|
||||||
|
HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||||
urlc.setDoOutput (true);
|
urlc.setDoOutput (true);
|
||||||
urlc.setRequestMethod ("POST");
|
urlc.setRequestMethod ("POST");
|
||||||
urlc.setChunkedStreamingMode (32); // small chunks
|
urlc.setChunkedStreamingMode (32); // small chunks
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -41,6 +41,7 @@ import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.DatagramSocketImpl;
|
import java.net.DatagramSocketImpl;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -73,7 +74,9 @@ public class UnreferencedMulticastSockets {
|
||||||
MulticastSocket ss;
|
MulticastSocket ss;
|
||||||
|
|
||||||
Server() throws IOException {
|
Server() throws IOException {
|
||||||
ss = new MulticastSocket(0);
|
InetSocketAddress serverAddress =
|
||||||
|
new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
|
||||||
|
ss = new MulticastSocket(serverAddress);
|
||||||
System.out.printf(" DatagramServer addr: %s: %d%n",
|
System.out.printf(" DatagramServer addr: %s: %d%n",
|
||||||
this.getHost(), this.getPort());
|
this.getHost(), this.getPort());
|
||||||
pendingSockets.add(new NamedWeak(ss, pendingQueue, "serverMulticastSocket"));
|
pendingSockets.add(new NamedWeak(ss, pendingQueue, "serverMulticastSocket"));
|
||||||
|
@ -81,7 +84,7 @@ public class UnreferencedMulticastSockets {
|
||||||
}
|
}
|
||||||
|
|
||||||
InetAddress getHost() throws UnknownHostException {
|
InetAddress getHost() throws UnknownHostException {
|
||||||
InetAddress localhost = InetAddress.getByName("localhost"); //.getLocalHost();
|
InetAddress localhost = InetAddress.getLoopbackAddress();
|
||||||
return localhost;
|
return localhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import jdk.test.lib.net.URIBuilder;
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class ProxyTest implements HttpCallback {
|
public class ProxyTest implements HttpCallback {
|
||||||
|
@ -43,10 +43,10 @@ public class ProxyTest implements HttpCallback {
|
||||||
public ProxyTest() {
|
public ProxyTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void request (HttpTransaction req) {
|
public void request(HttpTransaction req) {
|
||||||
req.setResponseEntityBody ("Hello .");
|
req.setResponseEntityBody("Hello .");
|
||||||
try {
|
try {
|
||||||
req.sendResponse (200, "Ok");
|
req.sendResponse(200, "Ok");
|
||||||
req.orderlyClose();
|
req.orderlyClose();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
@ -54,17 +54,12 @@ public class ProxyTest implements HttpCallback {
|
||||||
|
|
||||||
static public class MyProxySelector extends ProxySelector {
|
static public class MyProxySelector extends ProxySelector {
|
||||||
private static volatile URI lastURI;
|
private static volatile URI lastURI;
|
||||||
private final ArrayList<Proxy> noProxy;
|
private final static List<Proxy> NO_PROXY = List.of(Proxy.NO_PROXY);
|
||||||
|
|
||||||
public MyProxySelector() {
|
|
||||||
noProxy = new ArrayList<Proxy>(1);
|
|
||||||
noProxy.add(Proxy.NO_PROXY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.util.List<Proxy> select(URI uri) {
|
public java.util.List<Proxy> select(URI uri) {
|
||||||
System.out.println("Selecting no proxy for " + uri);
|
System.out.println("Selecting no proxy for " + uri);
|
||||||
lastURI = uri;
|
lastURI = uri;
|
||||||
return noProxy;
|
return NO_PROXY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
|
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
|
||||||
|
@ -80,15 +75,15 @@ public class ProxyTest implements HttpCallback {
|
||||||
ProxySelector.setDefault(new MyProxySelector());
|
ProxySelector.setDefault(new MyProxySelector());
|
||||||
try {
|
try {
|
||||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
server = new TestHttpServer (new ProxyTest(), 1, 10, 0);
|
server = new TestHttpServer(new ProxyTest(), 1, 10, loopback, 0);
|
||||||
URL url = URIBuilder.newBuilder()
|
URL url = URIBuilder.newBuilder()
|
||||||
.scheme("http")
|
.scheme("http")
|
||||||
.loopback()
|
.loopback()
|
||||||
.port(server.getLocalPort())
|
.port(server.getLocalPort())
|
||||||
.toURL();
|
.toURL();
|
||||||
System.out.println ("client opening connection to: " + url);
|
System.out.println("client opening connection to: " + url);
|
||||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection ();
|
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
|
||||||
InputStream is = urlc.getInputStream ();
|
InputStream is = urlc.getInputStream();
|
||||||
is.close();
|
is.close();
|
||||||
URI lastURI = MyProxySelector.lastURI();
|
URI lastURI = MyProxySelector.lastURI();
|
||||||
if (!String.valueOf(lastURI).equals(url + "/")) {
|
if (!String.valueOf(lastURI).equals(url + "/")) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -25,6 +25,9 @@
|
||||||
* @summary Fixed a potential NullPointerException when setting a ResponseCache that returns a null CacheRequest
|
* @summary Fixed a potential NullPointerException when setting a ResponseCache that returns a null CacheRequest
|
||||||
* @bug 4837267
|
* @bug 4837267
|
||||||
* @modules jdk.httpserver
|
* @modules jdk.httpserver
|
||||||
|
* @library /test/lib
|
||||||
|
* @run main Test
|
||||||
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true Test
|
||||||
* @author Michael McMahon
|
* @author Michael McMahon
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -33,6 +36,8 @@ import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class Test
|
public class Test
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -51,14 +56,15 @@ public class Test
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
|
HttpServer server = HttpServer.create(new InetSocketAddress(loopback, 0), 0);
|
||||||
server.createContext("/", new MyHandler());
|
server.createContext("/", new MyHandler());
|
||||||
server.start();
|
server.start();
|
||||||
ResponseCache bak = ResponseCache.getDefault();
|
ResponseCache bak = ResponseCache.getDefault();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResponseCache.setDefault (new ResponseCache() {
|
ResponseCache.setDefault(new ResponseCache() {
|
||||||
public CacheResponse get (URI uri, String rqstMethod, Map<String,List<String>> rqstHeaders)
|
public CacheResponse get(URI uri, String rqstMethod, Map<String,List<String>> rqstHeaders)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -68,8 +74,13 @@ public class Test
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
URL url = new URL ("http://localhost:" + server.getAddress().getPort() + "/");
|
URL url = URIBuilder.newBuilder()
|
||||||
URLConnection urlc = url.openConnection ();
|
.scheme("http")
|
||||||
|
.host(server.getAddress().getAddress())
|
||||||
|
.port(server.getAddress().getPort())
|
||||||
|
.path("/")
|
||||||
|
.toURL();
|
||||||
|
URLConnection urlc = url.openConnection(Proxy.NO_PROXY);
|
||||||
InputStream is = urlc.getInputStream();
|
InputStream is = urlc.getInputStream();
|
||||||
while (is.read() != -1) ;
|
while (is.read() != -1) ;
|
||||||
is.close();
|
is.close();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -30,9 +30,14 @@
|
||||||
* connection.
|
* connection.
|
||||||
* Check that a content-length of 0 results in an
|
* Check that a content-length of 0 results in an
|
||||||
* empty input stream.
|
* empty input stream.
|
||||||
|
* @library /test/lib
|
||||||
|
* @run main ZeroContentLength
|
||||||
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true ZeroContentLength
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class ZeroContentLength {
|
public class ZeroContentLength {
|
||||||
|
|
||||||
|
@ -231,7 +236,7 @@ public class ZeroContentLength {
|
||||||
*/
|
*/
|
||||||
int doRequest(String uri) throws Exception {
|
int doRequest(String uri) throws Exception {
|
||||||
URL url = new URL(uri);
|
URL url = new URL(uri);
|
||||||
HttpURLConnection http = (HttpURLConnection)url.openConnection();
|
HttpURLConnection http = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
|
||||||
|
|
||||||
int cl = http.getContentLength();
|
int cl = http.getContentLength();
|
||||||
|
|
||||||
|
@ -264,13 +269,17 @@ public class ZeroContentLength {
|
||||||
ZeroContentLength() throws Exception {
|
ZeroContentLength() throws Exception {
|
||||||
|
|
||||||
/* start the server */
|
/* start the server */
|
||||||
ServerSocket ss = new ServerSocket(0);
|
ServerSocket ss = new ServerSocket();
|
||||||
|
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
|
||||||
Server svr = new Server(ss);
|
Server svr = new Server(ss);
|
||||||
svr.start();
|
svr.start();
|
||||||
|
|
||||||
String uri = "http://localhost:" +
|
String uri = URIBuilder.newBuilder()
|
||||||
Integer.toString(ss.getLocalPort()) +
|
.scheme("http")
|
||||||
"/foo.html";
|
.host(ss.getInetAddress())
|
||||||
|
.port(ss.getLocalPort())
|
||||||
|
.path("/foo.html")
|
||||||
|
.build().toString();
|
||||||
|
|
||||||
int expectedTotal = 0;
|
int expectedTotal = 0;
|
||||||
int actualTotal = 0;
|
int actualTotal = 0;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -24,12 +24,17 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6726695 6993490
|
* @bug 6726695 6993490
|
||||||
* @summary HttpURLConnection shoul support 'Expect: 100-contimue' headers for PUT
|
* @summary HttpURLConnection should support 'Expect: 100-contimue' headers for PUT
|
||||||
|
* @library /test/lib
|
||||||
|
* @run main B6726695
|
||||||
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true B6726695
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
public class B6726695 extends Thread {
|
public class B6726695 extends Thread {
|
||||||
private ServerSocket server = null;
|
private ServerSocket server = null;
|
||||||
private int port = 0;
|
private int port = 0;
|
||||||
|
@ -48,7 +53,8 @@ public class B6726695 extends Thread {
|
||||||
|
|
||||||
public B6726695() {
|
public B6726695() {
|
||||||
try {
|
try {
|
||||||
server = new ServerSocket(0);
|
server = new ServerSocket();
|
||||||
|
server.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
|
||||||
port = server.getLocalPort();
|
port = server.getLocalPort();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -64,10 +70,15 @@ public class B6726695 extends Thread {
|
||||||
* the Expect: 100-Continue header. So the POST should proceed after
|
* the Expect: 100-Continue header. So the POST should proceed after
|
||||||
* a timeout.
|
* a timeout.
|
||||||
*/
|
*/
|
||||||
URL url = new URL("http://localhost:" + port + "/foo");
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("http")
|
||||||
|
.loopback()
|
||||||
|
.port(port)
|
||||||
|
.path("/foo")
|
||||||
|
.toURL();
|
||||||
|
|
||||||
// 1st Connection. Should be rejected. I.E. get a ProtocolException
|
// 1st Connection. Should be rejected. I.E. get a ProtocolException
|
||||||
URLConnection con = url.openConnection();
|
URLConnection con = url.openConnection(Proxy.NO_PROXY);
|
||||||
HttpURLConnection http = (HttpURLConnection) con;
|
HttpURLConnection http = (HttpURLConnection) con;
|
||||||
http.setRequestMethod("POST");
|
http.setRequestMethod("POST");
|
||||||
http.setRequestProperty("Expect", "100-Continue");
|
http.setRequestProperty("Expect", "100-Continue");
|
||||||
|
@ -86,7 +97,7 @@ public class B6726695 extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2nd connection. Should be accepted by server.
|
// 2nd connection. Should be accepted by server.
|
||||||
http = (HttpURLConnection) url.openConnection();
|
http = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
|
||||||
http.setRequestMethod("POST");
|
http.setRequestMethod("POST");
|
||||||
http.setRequestProperty("Expect", "100-Continue");
|
http.setRequestProperty("Expect", "100-Continue");
|
||||||
http.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
http.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||||
|
@ -109,7 +120,7 @@ public class B6726695 extends Thread {
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
// 3rd connection. Simulate a server that doesn't implement 100-continue
|
// 3rd connection. Simulate a server that doesn't implement 100-continue
|
||||||
http = (HttpURLConnection) url.openConnection();
|
http = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
|
||||||
http.setRequestMethod("POST");
|
http.setRequestMethod("POST");
|
||||||
http.setRequestProperty("Expect", "100-Continue");
|
http.setRequestProperty("Expect", "100-Continue");
|
||||||
http.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
http.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -51,7 +51,8 @@ import jdk.test.lib.net.URIBuilder;
|
||||||
public class InfiniteLoop {
|
public class InfiniteLoop {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
|
HttpServer server = HttpServer.create(new InetSocketAddress(loopback, 0), 0);
|
||||||
server.createContext("/test/InfiniteLoop", new RespHandler());
|
server.createContext("/test/InfiniteLoop", new RespHandler());
|
||||||
server.start();
|
server.start();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -24,8 +24,11 @@
|
||||||
* @test
|
* @test
|
||||||
* @bug 7095980 8007315
|
* @bug 7095980 8007315
|
||||||
* @modules jdk.httpserver
|
* @modules jdk.httpserver
|
||||||
|
* @library /test/lib
|
||||||
* @summary Ensure HttpURLConnection (and supporting APIs) don't expose
|
* @summary Ensure HttpURLConnection (and supporting APIs) don't expose
|
||||||
* HttpOnly cookies
|
* HttpOnly cookies
|
||||||
|
* @run main HttpOnly
|
||||||
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true HttpOnly
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -34,6 +37,7 @@ import java.net.CookieManager;
|
||||||
import java.net.CookiePolicy;
|
import java.net.CookiePolicy;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -46,6 +50,8 @@ import com.sun.net.httpserver.HttpExchange;
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
import com.sun.net.httpserver.HttpServer;
|
import com.sun.net.httpserver.HttpServer;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1) start the HTTP server
|
* 1) start the HTTP server
|
||||||
* 2) populate cookie store with HttpOnly cookies
|
* 2) populate cookie store with HttpOnly cookies
|
||||||
|
@ -67,8 +73,12 @@ public class HttpOnly {
|
||||||
CookieHandler previousHandler = CookieHandler.getDefault();
|
CookieHandler previousHandler = CookieHandler.getDefault();
|
||||||
try {
|
try {
|
||||||
InetSocketAddress address = server.getAddress();
|
InetSocketAddress address = server.getAddress();
|
||||||
URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
|
URI uri = URIBuilder.newBuilder()
|
||||||
+ ":" + address.getPort() + URI_PATH);
|
.scheme("http")
|
||||||
|
.host(address.getAddress())
|
||||||
|
.port(address.getPort())
|
||||||
|
.path(URI_PATH)
|
||||||
|
.build();
|
||||||
populateCookieStore(uri);
|
populateCookieStore(uri);
|
||||||
doClient(uri);
|
doClient(uri);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -92,7 +102,7 @@ public class HttpOnly {
|
||||||
}
|
}
|
||||||
|
|
||||||
void doClient(URI uri) throws Exception {
|
void doClient(URI uri) throws Exception {
|
||||||
HttpURLConnection uc = (HttpURLConnection) uri.toURL().openConnection();
|
HttpURLConnection uc = (HttpURLConnection) uri.toURL().openConnection(Proxy.NO_PROXY);
|
||||||
int resp = uc.getResponseCode();
|
int resp = uc.getResponseCode();
|
||||||
check(resp == 200,
|
check(resp == 200,
|
||||||
"Unexpected response code. Expected 200, got " + resp);
|
"Unexpected response code. Expected 200, got " + resp);
|
||||||
|
@ -157,7 +167,7 @@ public class HttpOnly {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now add some user set cookies into the mix.
|
// Now add some user set cookies into the mix.
|
||||||
uc = (HttpURLConnection) uri.toURL().openConnection();
|
uc = (HttpURLConnection) uri.toURL().openConnection(Proxy.NO_PROXY);
|
||||||
uc.addRequestProperty("Cookie", "CUSTOMER_ID=CHEGAR;");
|
uc.addRequestProperty("Cookie", "CUSTOMER_ID=CHEGAR;");
|
||||||
resp = uc.getResponseCode();
|
resp = uc.getResponseCode();
|
||||||
check(resp == 200,
|
check(resp == 200,
|
||||||
|
@ -214,7 +224,8 @@ public class HttpOnly {
|
||||||
|
|
||||||
// HTTP Server
|
// HTTP Server
|
||||||
HttpServer startHttpServer() throws IOException {
|
HttpServer startHttpServer() throws IOException {
|
||||||
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
|
InetAddress localhost = InetAddress.getLocalHost();
|
||||||
|
HttpServer httpServer = HttpServer.create(new InetSocketAddress(localhost, 0), 0);
|
||||||
httpServer.createContext(URI_PATH, new SimpleHandler());
|
httpServer.createContext(URI_PATH, new SimpleHandler());
|
||||||
httpServer.start();
|
httpServer.start();
|
||||||
return httpServer;
|
return httpServer;
|
||||||
|
@ -272,4 +283,3 @@ public class HttpOnly {
|
||||||
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
|
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
|
||||||
if (failed > 0) throw new AssertionError("Some tests failed");}
|
if (failed > 0) throw new AssertionError("Some tests failed");}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -27,7 +27,9 @@
|
||||||
* @summary createSocket() - smpatch fails using 1.6.0_10 because of
|
* @summary createSocket() - smpatch fails using 1.6.0_10 because of
|
||||||
* "Unconnected sockets not implemented"
|
* "Unconnected sockets not implemented"
|
||||||
* @modules jdk.httpserver
|
* @modules jdk.httpserver
|
||||||
|
* @library /test/lib
|
||||||
* @run main/othervm HttpsCreateSockTest
|
* @run main/othervm HttpsCreateSockTest
|
||||||
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true HttpsCreateSockTest
|
||||||
*
|
*
|
||||||
* SunJSSE does not support dynamic system properties, no way to re-use
|
* SunJSSE does not support dynamic system properties, no way to re-use
|
||||||
* system properties in samevm/agentvm mode.
|
* system properties in samevm/agentvm mode.
|
||||||
|
@ -42,6 +44,7 @@ import javax.net.ssl.SSLSocketFactory;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
|
@ -51,6 +54,8 @@ import com.sun.net.httpserver.HttpExchange;
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
import com.sun.net.httpserver.HttpsConfigurator;
|
import com.sun.net.httpserver.HttpsConfigurator;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.URIBuilder;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This class tests that the HTTPS protocol handler is using its socket factory for
|
* This class tests that the HTTPS protocol handler is using its socket factory for
|
||||||
* creating new Sockets. It does this by wrapping the default SSLSocketFactory with
|
* creating new Sockets. It does this by wrapping the default SSLSocketFactory with
|
||||||
|
@ -104,10 +109,15 @@ public class HttpsCreateSockTest
|
||||||
void doClient() throws IOException {
|
void doClient() throws IOException {
|
||||||
InetSocketAddress address = httpsServer.getAddress();
|
InetSocketAddress address = httpsServer.getAddress();
|
||||||
|
|
||||||
URL url = new URL("https://localhost:" + address.getPort() + "/");
|
URL url = URIBuilder.newBuilder()
|
||||||
|
.scheme("https")
|
||||||
|
.host(address.getAddress())
|
||||||
|
.port(address.getPort())
|
||||||
|
.path("/")
|
||||||
|
.toURLUnchecked();
|
||||||
System.out.println("trying to connect to " + url + "...");
|
System.out.println("trying to connect to " + url + "...");
|
||||||
|
|
||||||
HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();
|
HttpsURLConnection uc = (HttpsURLConnection) url.openConnection(Proxy.NO_PROXY);
|
||||||
uc.setHostnameVerifier(new AllHostnameVerifier());
|
uc.setHostnameVerifier(new AllHostnameVerifier());
|
||||||
if (uc instanceof javax.net.ssl.HttpsURLConnection) {
|
if (uc instanceof javax.net.ssl.HttpsURLConnection) {
|
||||||
((javax.net.ssl.HttpsURLConnection) uc).setSSLSocketFactory(new SimpleSSLSocketFactory());
|
((javax.net.ssl.HttpsURLConnection) uc).setSSLSocketFactory(new SimpleSSLSocketFactory());
|
||||||
|
@ -123,7 +133,9 @@ public class HttpsCreateSockTest
|
||||||
* Https Server
|
* Https Server
|
||||||
*/
|
*/
|
||||||
public void startHttpsServer() throws IOException, NoSuchAlgorithmException {
|
public void startHttpsServer() throws IOException, NoSuchAlgorithmException {
|
||||||
httpsServer = com.sun.net.httpserver.HttpsServer.create(new InetSocketAddress(0), 0);
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
|
InetSocketAddress address = new InetSocketAddress(loopback, 0);
|
||||||
|
httpsServer = com.sun.net.httpserver.HttpsServer.create(address, 0);
|
||||||
httpsServer.createContext("/", new MyHandler());
|
httpsServer.createContext("/", new MyHandler());
|
||||||
httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
|
httpsServer.setHttpsConfigurator(new HttpsConfigurator(SSLContext.getDefault()));
|
||||||
httpsServer.start();
|
httpsServer.start();
|
||||||
|
|
|
@ -37,6 +37,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
import static java.net.NetworkInterface.getNetworkInterfaces;
|
import static java.net.NetworkInterface.getNetworkInterfaces;
|
||||||
import static java.util.Collections.list;
|
import static java.util.Collections.list;
|
||||||
|
@ -380,14 +382,17 @@ public class NetworkConfiguration {
|
||||||
|
|
||||||
/** Prints all the system interface information to the give stream. */
|
/** Prints all the system interface information to the give stream. */
|
||||||
public static void printSystemConfiguration(PrintStream out) {
|
public static void printSystemConfiguration(PrintStream out) {
|
||||||
|
PrivilegedAction<Void> pa = () -> {
|
||||||
try {
|
try {
|
||||||
out.println("*** all system network interface configuration ***");
|
out.println("*** all system network interface configuration ***");
|
||||||
for (NetworkInterface nif : list(getNetworkInterfaces())) {
|
for (NetworkInterface nif : list(getNetworkInterfaces())) {
|
||||||
out.print(interfaceInformation(nif));
|
out.print(interfaceInformation(nif));
|
||||||
}
|
}
|
||||||
out.println("*** end ***");
|
out.println("*** end ***");
|
||||||
|
return null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}};
|
||||||
|
AccessController.doPrivileged(pa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue