8305900: Use loopback IP addresses in security policy files of httpclient tests

Reviewed-by: dfuchs
This commit is contained in:
Jaikiran Pai 2023-04-13 09:41:01 +00:00
parent fb9a29d732
commit 646b666a26
33 changed files with 391 additions and 234 deletions

View File

@ -21,17 +21,6 @@
* questions.
*/
/*
* @test
* @summary Basic test for ofFileDownload
* @bug 8196965
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
* jdk.test.lib.Platform jdk.test.lib.util.FileUtils
* @run testng/othervm AsFileDownloadTest
* @run testng/othervm/java.security.policy=AsFileDownloadTest.policy AsFileDownloadTest
*/
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
@ -79,6 +68,16 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
/*
* @test
* @summary Basic test for ofFileDownload
* @bug 8196965
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
* jdk.test.lib.Platform jdk.test.lib.util.FileUtils
* @run testng/othervm AsFileDownloadTest
* @run testng/othervm/java.security.policy=AsFileDownloadTest.policy AsFileDownloadTest
*/
public class AsFileDownloadTest {
SSLContext sslContext;
@ -287,8 +286,10 @@ public class AsFileDownloadTest {
// -- Infrastructure
static String serverAuthority(HttpServer server) {
return InetAddress.getLoopbackAddress().getHostName() + ":"
+ server.getAddress().getPort();
final String hostIP = InetAddress.getLoopbackAddress().getHostAddress();
// escape for ipv6
final String h = hostIP.contains(":") ? "[" + hostIP + "]" : hostIP;
return h + ":" + server.getAddress().getPort();
}
@BeforeTest

View File

@ -34,7 +34,8 @@ grant codeBase "file:${test.classes}/../../../../test/jdk/java/net/httpclient/li
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
@ -42,10 +43,15 @@ grant codeBase "file:${test.classes}/*" {
permission java.io.FilePermission "${user.dir}${/}asFileDownloadTest.tmp.dir", "read,write";
permission java.io.FilePermission "${user.dir}${/}asFileDownloadTest.tmp.dir/-", "read,write";
permission java.net.URLPermission "http://localhost:*/http1/afdt", "POST";
permission java.net.URLPermission "https://localhost:*/https1/afdt", "POST";
permission java.net.URLPermission "http://localhost:*/http2/afdt", "POST";
permission java.net.URLPermission "https://localhost:*/https2/afdt", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http1/afdt", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/afdt", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/afdt", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/afdt", "POST";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/afdt", "POST";
permission java.net.URLPermission "https://[::1]:*/https1/afdt", "POST";
permission java.net.URLPermission "http://[::1]:*/http2/afdt", "POST";
permission java.net.URLPermission "https://[::1]:*/https2/afdt", "POST";
// needed to grant permission to the HTTP/2 server
@ -58,7 +64,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -34,19 +34,29 @@ grant codeBase "file:${test.classes}/../../../../../test/jdk/java/net/httpclient
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
grant codeBase "file:${test.classes}/*" {
permission java.net.URLPermission "http://localhost:*/http1/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https1/echo", "POST";
permission java.net.URLPermission "http://localhost:*/http2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/http1/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https1/echo", "GET";
permission java.net.URLPermission "http://localhost:*/http2/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https2/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http1/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/http1/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "POST";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/http1/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "GET";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "GET";
// file permissions
permission java.io.FilePermission "${user.dir}${/}defaultFile.txt", "read,write,delete";
@ -69,7 +79,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -36,19 +36,29 @@ grant codeBase "file:${test.classes}/../../../../../test/jdk/java/net/httpclient
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
grant codeBase "file:${test.classes}/*" {
permission java.net.URLPermission "http://localhost:*/http1/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https1/echo", "POST";
permission java.net.URLPermission "http://localhost:*/http2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/http1/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https1/echo", "GET";
permission java.net.URLPermission "http://localhost:*/http2/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https2/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http1/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/http1/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "POST";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/http1/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "GET";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "GET";
// file permissions
permission java.io.FilePermission "${user.dir}${/}defaultFile.txt", "read,write,delete";
@ -74,7 +84,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -41,19 +41,29 @@ grant codeBase "file:${test.classes}/../../../../../test/jdk/java/net/httpclient
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
grant codeBase "file:${test.classes}/*" {
permission java.net.URLPermission "http://localhost:*/http1/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https1/echo", "POST";
permission java.net.URLPermission "http://localhost:*/http2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/http1/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https1/echo", "GET";
permission java.net.URLPermission "http://localhost:*/http2/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https2/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http1/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/http1/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "POST";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/http1/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "GET";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "GET";
// file permissions
permission java.io.FilePermission "${user.dir}${/}defaultFile.txt", "read,write,delete";
@ -77,7 +87,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -34,19 +34,29 @@ grant codeBase "file:${test.classes}/../../../../../test/jdk/java/net/httpclient
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
grant codeBase "file:${test.classes}/*" {
permission java.net.URLPermission "http://localhost:*/http1/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https1/echo", "POST";
permission java.net.URLPermission "http://localhost:*/http2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/http1/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https1/echo", "GET";
permission java.net.URLPermission "http://localhost:*/http2/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https2/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http1/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/http1/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "POST";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/http1/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "GET";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "GET";
// file permissions
permission java.io.FilePermission "${user.dir}${/}defaultFile.txt", "read,write,delete";
@ -62,7 +72,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -119,14 +119,21 @@ public class LightWeightHttpServer {
System.out.println("HTTP server port = " + port);
httpsport = httpsServer.getAddress().getPort();
System.out.println("HTTPS server port = " + httpsport);
httproot = "http://localhost:" + port + "/";
httpsroot = "https://localhost:" + httpsport + "/";
httproot = "http://" + makeServerAuthority(httpServer.getAddress()) + "/";
httpsroot = "https://" + makeServerAuthority(httpsServer.getAddress()) + "/";
proxy = new ProxyServer(0, false);
proxyPort = proxy.getPort();
System.out.println("Proxy port = " + proxyPort);
}
private static String makeServerAuthority(final InetSocketAddress addr) {
final String hostIP = addr.getAddress().getHostAddress();
// escape for ipv6
final String h = hostIP.contains(":") ? "[" + hostIP + "]" : hostIP;
return h + ":" + addr.getPort();
}
public static void stop() throws IOException {
if (httpServer != null) {
httpServer.stop(0);

View File

@ -45,19 +45,29 @@ grant codeBase "file:${test.classes}/../../../../../test/jdk/java/net/httpclient
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
grant codeBase "file:${test.classes}/*" {
permission java.net.URLPermission "http://localhost:*/http1/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https1/echo", "POST";
permission java.net.URLPermission "http://localhost:*/http2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/http1/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https1/echo", "GET";
permission java.net.URLPermission "http://localhost:*/http2/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https2/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http1/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/http1/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "POST";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/http1/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "GET";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "GET";
// file permissions for test files
permission java.io.FilePermission "${user.dir}${/}defaultFile.txt", "read,write,delete";
@ -77,7 +87,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -45,19 +45,29 @@ grant codeBase "file:${test.classes}/../../../../../test/jdk/java/net/httpclient
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
grant codeBase "file:${test.classes}/*" {
permission java.net.URLPermission "http://localhost:*/http1/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https1/echo", "POST";
permission java.net.URLPermission "http://localhost:*/http2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/https2/echo", "POST";
permission java.net.URLPermission "https://localhost:*/http1/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https1/echo", "GET";
permission java.net.URLPermission "http://localhost:*/http2/echo", "GET";
permission java.net.URLPermission "https://localhost:*/https2/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http1/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/http1/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https1/echo", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/http2/echo", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/https2/echo", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "POST";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "POST";
permission java.net.URLPermission "https://[::1]:*/http1/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https1/echo", "GET";
permission java.net.URLPermission "http://[::1]:*/http2/echo", "GET";
permission java.net.URLPermission "https://[::1]:*/https2/echo", "GET";
// file permissions for test files
permission java.io.FilePermission "${user.dir}${/}file.zip", "read,write";
@ -74,7 +84,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -21,24 +21,6 @@
* questions.
*/
/*
* @test
* @bug 8087112
* @modules java.net.http
* java.logging
* jdk.httpserver
* @library /test/lib
* @compile ../../../com/sun/net/httpserver/LogFilter.java
* @compile ../../../com/sun/net/httpserver/EchoHandler.java
* @compile ../../../com/sun/net/httpserver/FileServerHandler.java
* @build jdk.test.lib.net.SimpleSSLContext
* @build LightWeightHttpServer
* @build jdk.test.lib.Platform
* @build jdk.test.lib.util.FileUtils
* @run testng/othervm RequestBodyTest
* @run testng/othervm/java.security.policy=RequestBodyTest.policy RequestBodyTest
*/
import java.io.*;
import java.net.URI;
import java.net.http.HttpClient;
@ -74,6 +56,23 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
/*
* @test
* @bug 8087112
* @modules java.net.http
* java.logging
* jdk.httpserver
* @library /test/lib
* @compile ../../../com/sun/net/httpserver/LogFilter.java
* @compile ../../../com/sun/net/httpserver/EchoHandler.java
* @compile ../../../com/sun/net/httpserver/FileServerHandler.java
* @build jdk.test.lib.net.SimpleSSLContext
* @build LightWeightHttpServer
* @build jdk.test.lib.Platform
* @build jdk.test.lib.util.FileUtils
* @run testng/othervm RequestBodyTest
* @run testng/othervm/java.security.policy=RequestBodyTest.policy RequestBodyTest
*/
public class RequestBodyTest {
static final String fileroot = System.getProperty("test.src", ".") + "/docs";

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2018, 2023, 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
@ -38,14 +38,17 @@ grant codeBase "file:${test.classes}/*" {
permission java.io.FilePermission "${test.src}${/}docs${/}files${/}notsobigfile.txt", "read";
permission java.io.FilePermission "RequestBodyTest.tmp", "read,write,delete";
permission java.net.URLPermission "http://localhost:*/echo/foo", "POST";
permission java.net.URLPermission "https://localhost:*/echo/foo", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/echo/foo", "POST";
permission java.net.URLPermission "https://127.0.0.1:*/echo/foo", "POST";
permission java.net.URLPermission "http://[::1]:*/echo/foo", "POST";
permission java.net.URLPermission "https://[::1]:*/echo/foo", "POST";
// for HTTP/1.1 server logging
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP server
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -34,7 +34,8 @@ grant codeBase "file:${test.classes}/../../../../test/jdk/java/net/httpclient/li
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "listen,accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "listen,accept,resolve";
permission java.net.SocketPermission "[::1]:*", "listen,accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
@ -42,11 +43,15 @@ grant codeBase "file:${test.classes}/*" {
permission java.io.FilePermission "${user.dir}${/}asFileDownloadTest.tmp.dir", "read,write";
permission java.io.FilePermission "${user.dir}${/}asFileDownloadTest.tmp.dir/-", "read,write";
permission java.net.URLPermission "http://localhost:*/http1/-", "GET,POST";
permission java.net.URLPermission "https://localhost:*/https1/-", "GET,POST";
permission java.net.URLPermission "http://localhost:*/http2/-", "GET,POST";
permission java.net.URLPermission "https://localhost:*/https2/-", "GET,POST";
permission java.net.URLPermission "http://127.0.0.1:*/http1/-", "GET,POST";
permission java.net.URLPermission "https://127.0.0.1:*/https1/-", "GET,POST";
permission java.net.URLPermission "http://127.0.0.1:*/http2/-", "GET,POST";
permission java.net.URLPermission "https://127.0.0.1:*/https2/-", "GET,POST";
// ipv6
permission java.net.URLPermission "http://[::1]:*/http1/-", "GET,POST";
permission java.net.URLPermission "https://[::1]:*/https1/-", "GET,POST";
permission java.net.URLPermission "http://[::1]:*/http2/-", "GET,POST";
permission java.net.URLPermission "https://[::1]:*/https2/-", "GET,POST";
// needed to grant permission to the HTTP/2 server
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.common";
@ -58,7 +63,8 @@ grant codeBase "file:${test.classes}/*" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "listen,accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "listen,accept,resolve";
permission java.net.SocketPermission "[::1]:*", "listen,accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -37,17 +37,19 @@ grant codeBase "file:${test.classes}/../../../../test/jdk/java/net/httpclient/li
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack";
permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http";
permission java.net.SocketPermission "localhost:*", "listen,accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "listen,accept,resolve";
permission java.net.SocketPermission "[::1]:*", "listen,accept,resolve";
permission java.lang.RuntimePermission "modifyThread";
};
grant codeBase "file:${test.classes}/-" {
// test issues HTTP GET requests
permission java.net.URLPermission "http://localhost:*/-", "GET";
permission java.net.URLPermission "https://localhost:*/-", "GET";
permission java.net.URLPermission "http://localhost:*/-", "GET";
permission java.net.URLPermission "https://localhost:*/-", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/-", "GET";
permission java.net.URLPermission "https://127.0.0.1:*/-", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/-", "GET";
permission java.net.URLPermission "https://[::1]:*/-", "GET";
// needed to grant permission to the HTTP/2 server
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.common";
@ -59,7 +61,8 @@ grant codeBase "file:${test.classes}/-" {
permission java.util.logging.LoggingPermission "control";
// needed to grant the HTTP servers
permission java.net.SocketPermission "localhost:*", "accept,resolve";
permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";
permission java.net.SocketPermission "[::1]:*", "accept,resolve";
permission java.util.PropertyPermission "*", "read";
permission java.lang.RuntimePermission "modifyThread";

View File

@ -711,8 +711,15 @@ public interface HttpServerAdapters {
public abstract Version getVersion();
public String serverAuthority() {
return InetAddress.getLoopbackAddress().getHostName() + ":"
+ getAddress().getPort();
InetSocketAddress address = getAddress();
String hostString = address.getHostString();
hostString = address.getAddress().isLoopbackAddress() || hostString.equals("localhost")
? address.getAddress().getHostAddress() // use the raw IP address, if loopback
: hostString; // use whatever host string was used to construct the address
hostString = hostString.contains(":")
? "[" + hostString + "]"
: hostString;
return hostString + ":" + address.getPort();
}
public static HttpTestServer of(HttpServer server) {

View File

@ -85,8 +85,11 @@ public class Http2TestServer implements AutoCloseable {
}
public String serverAuthority() {
return InetAddress.getLoopbackAddress().getHostName() + ":"
+ getAddress().getPort();
final InetSocketAddress inetSockAddr = getAddress();
final String hostIP = inetSockAddr.getAddress().getHostAddress();
// escape for ipv6
final String h = hostIP.contains(":") ? "[" + hostIP + "]" : hostIP;
return h + ":" + inetSockAddr.getPort();
}
public Http2TestServer(boolean secure,

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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
@ -29,7 +29,8 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
@ -39,8 +40,8 @@ grant {
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET";
permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET";
permission java.net.URLPermission "http://[::1]:${port.number}/files/foo.txt", "GET";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,16 +28,18 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://[::1]:${port.number}/files/foo.txt", "GET:*";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,18 +28,26 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "socket://127.0.0.1:${port.number1}", "CONNECT";
// ipv6
permission java.net.URLPermission "http://[::1]:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "socket://[::1]:${port.number1}", "CONNECT";
// this specific test uses a proxy configured to loopback address. the httpclient implementation
// during permissions check uses the InetAddress.hostString() API which can return resolved
// hostname, so we use include a permission for "localhost" to cover that case too
permission java.net.URLPermission "socket://localhost:${port.number1}", "CONNECT";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,18 +28,26 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "socket://127.0.0.1:${port.number1}", "CONNECT";
// ipv6
permission java.net.URLPermission "http://[::1]:${port.number}/files/foo.txt", "GET:*";
permission java.net.URLPermission "socket://[::1]:${port.number1}", "CONNECT";
// this specific test uses a proxy configured to loopback address. the httpclient implementation
// during permissions check uses the InetAddress.hostString() API which can return resolved
// hostname, so we use include a permission for "localhost" to cover that case too
permission java.net.URLPermission "socket://localhost:${port.number1}", "CONNECT";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET";
permission java.net.URLPermission "http://[::1]:*/files/foo.txt", "GET";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,12 +28,14 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://[::1]:*/files/foo.txt", "GET:*";
// Test checks for this explicitly
permission java.lang.RuntimePermission "foobar";
@ -42,6 +44,6 @@ grant {
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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
@ -29,17 +29,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:Host";
permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:Host";
permission java.net.URLPermission "http://[::1]:${port.number}/files/foo.txt", "GET:Host";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,18 +28,20 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:Host";
permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:Host";
permission java.net.URLPermission "http://[::1]:${port.number}/files/foo.txt", "GET:Host";
permission java.net.URLPermission "http://foohost:123/files/foo.txt", "GET:Host";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/files/*", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/files/*", "GET";
permission java.net.URLPermission "http://[::1]:*/files/*", "GET";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/redirect/foo.txt", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/redirect/foo.txt", "GET";
permission java.net.URLPermission "http://[::1]:*/redirect/foo.txt", "GET";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,18 +28,22 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/redirect/foo.txt", "GET";
permission java.net.URLPermission "http://localhost:*/redirect/bar.txt", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/redirect/foo.txt", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/redirect/bar.txt", "GET";
// ipv6
permission java.net.URLPermission "http://[::1]:*/redirect/foo.txt", "GET";
permission java.net.URLPermission "http://[::1]:*/redirect/bar.txt", "GET";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/redirect/bar.txt", "GET";
permission java.net.URLPermission "http://127.0.0.1:*/redirect/bar.txt", "GET";
permission java.net.URLPermission "http://[::1]:*/redirect/bar.txt", "GET";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/files/foo.txt", "POST";
permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "POST";
permission java.net.URLPermission "http://[::1]:*/files/foo.txt", "POST";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,20 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:X-Bar";
permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:X-Bar";
permission java.net.URLPermission "http://[::1]:*/files/foo.txt", "GET:X-Bar";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:X-Foo1,X-Foo,X-Bar";
permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:X-Foo1,X-Foo,X-Bar";
permission java.net.URLPermission "http://[::1]:*/files/foo.txt", "GET:X-Foo1,X-Foo,X-Bar";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2016, 2023, 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,17 +28,19 @@ grant {
permission java.io.FilePermission "${test.classes}${/}-", "read,write,delete";
permission java.lang.RuntimePermission "modifyThread";
permission java.util.logging.LoggingPermission "control", "";
permission java.net.SocketPermission "localhost:1024-", "accept,listen";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
permission java.io.FilePermission "${test.src}${/}docs${/}-", "read";
permission java.lang.RuntimePermission "createClassLoader";
// permissions specific to this test
permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:*";
permission java.net.URLPermission "http://[::1]:*/files/foo.txt", "GET:*";
};
// For proxy only. Not being tested
grant codebase "file:${test.classes}/proxydir/-" {
permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect";
permission java.net.SocketPermission "localhost:1024-", "connect,resolve";
permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -103,6 +103,7 @@ public class Security {
static String httproot, fileuri, fileroot, redirectroot;
static List<HttpClient> clients = new LinkedList<>();
static URI uri;
static String serverAuthority;
interface ThrowingRunnable { void run() throws Throwable; }
@ -201,56 +202,56 @@ public class Security {
return new TestAndResult[] {
// (0) policy does not have permission for file. Should fail
TestAndResult.of(true, () -> { // Policy 0
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse<?> response = client.send(request, ofString());
System.out.println("Received response:" + response);
}),
// (1) policy has permission for file URL
TestAndResult.of(false, () -> { //Policy 1
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse<?> response = client.send(request, ofString());
System.out.println("Received response:" + response);
}),
// (2) policy has permission for all file URLs under /files
TestAndResult.of(false, () -> { // Policy 2
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse<?> response = client.send(request, ofString());
System.out.println("Received response:" + response);
}),
// (3) policy has permission for first URL but not redirected URL
TestAndResult.of(true, () -> { // Policy 3
URI u = URI.create("http://localhost:" + port + "/redirect/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/redirect/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse<?> response = client.send(request, ofString());
System.out.println("Received response:" + response);
}),
// (4) policy has permission for both first URL and redirected URL
TestAndResult.of(false, () -> { // Policy 4
URI u = URI.create("http://localhost:" + port + "/redirect/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/redirect/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse<?> response = client.send(request, ofString());
System.out.println("Received response:" + response);
}),
// (5) policy has permission for redirected but not first URL
TestAndResult.of(true, () -> { // Policy 5
URI u = URI.create("http://localhost:" + port + "/redirect/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/redirect/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse<?> response = client.send(request, ofString());
System.out.println("Received response:" + response);
}),
// (6) policy has permission for file URL, but not method
TestAndResult.of(true, () -> { //Policy 6
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse<?> response = client.send(request, ofString());
System.out.println("Received response:" + response);
}),
// (7) policy has permission for file URL, method, but not header
TestAndResult.of(true, () -> { //Policy 7
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u)
.header("X-Foo", "bar")
.GET()
@ -260,7 +261,7 @@ public class Security {
}),
// (8) policy has permission for file URL, method and header
TestAndResult.of(false, () -> { //Policy 8
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u)
.header("X-Foo", "bar")
.GET()
@ -270,7 +271,7 @@ public class Security {
}),
// (9) policy has permission for file URL, method and header
TestAndResult.of(false, () -> { //Policy 9
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u)
.headers("X-Foo", "bar", "X-Bar", "foo")
.GET()
@ -292,7 +293,7 @@ public class Security {
}),
// (13) async version of test 0
TestAndResult.of(true, () -> { // Policy 0
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
try {
HttpResponse<?> response = client.sendAsync(request, ofString()).get();
@ -307,14 +308,14 @@ public class Security {
}),
// (14) async version of test 1
TestAndResult.of(false, () -> { //Policy 1
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
try {
HttpResponse<?> response = client.sendAsync(request, ofString()).get();
System.out.println("Received response:" + response);
} catch (ExecutionException e) {
if (e.getCause() instanceof SecurityException) {
throw (SecurityException)e.getCause();
if (e.getCause() instanceof SecurityException se) {
throw se;
} else {
throw new RuntimeException(e);
}
@ -323,7 +324,7 @@ public class Security {
// (15) check that user provided unprivileged code running on a worker
// thread does not gain ungranted privileges.
TestAndResult.of(true, () -> { //Policy 12
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u).GET().build();
HttpResponse.BodyHandler<String> sth = ofString();
@ -369,18 +370,18 @@ public class Security {
System.out.println("Received response:" + response);
} catch (CompletionException e) {
Throwable t = e.getCause();
if (t instanceof SecurityException)
throw (SecurityException)t;
if (t instanceof SecurityException se)
throw se;
else if ((t instanceof IOException)
&& (t.getCause() instanceof SecurityException))
throw ((SecurityException)t.getCause());
&& (t.getCause() instanceof SecurityException se))
throw se;
else
throw new RuntimeException(t);
}
}),
// (16) allowed to set Host header but does not have permission
TestAndResult.of(true, () -> { //Policy 16
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u)
.header("Host", "foohost:123")
.GET().build();
@ -389,7 +390,7 @@ public class Security {
}),
// (17) allowed to set Host header and does have permission
TestAndResult.of(false, () -> { //Policy 17
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u)
.header("Host", "foohost:123")
.GET().build();
@ -426,14 +427,13 @@ public class Security {
}
System.out.println("Proxy port, p:" + p);
InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(),
p);
InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), p);
HttpClient cl = HttpClient.newBuilder()
.proxy(ProxySelector.of(addr))
.build();
clients.add(cl);
URI u = URI.create("http://localhost:" + port + "/files/foo.txt");
URI u = URI.create("http://" + serverAuthority + "/files/foo.txt");
HttpRequest request = HttpRequest.newBuilder(u)
.headers("X-Foo", "bar", "X-Bar", "foo")
.build();
@ -498,13 +498,20 @@ public class Security {
throw new RuntimeException("Error wrong port");
System.out.println("Port was assigned by Driver");
}
System.out.println("HTTP server port = " + port);
httproot = "http://localhost:" + port + "/files/";
redirectroot = "http://localhost:" + port + "/redirect/";
serverAuthority = makeServerAuthority(addr.getAddress().getHostAddress(), port);
System.out.println("HTTP server started at " + serverAuthority);
httproot = "http://" + serverAuthority + "/files/";
redirectroot = "http://" + serverAuthority + "/redirect/";
uri = new URI(httproot);
fileuri = httproot + "foo.txt";
}
private static String makeServerAuthority(final String host, final int port) {
// escape for ipv6
final String h = host.contains(":") ? "[" + host + "]" : host;
return h + ":" + port;
}
static class RedirectHandler implements HttpHandler {
String root;