8055747: Move SimpleSSLContext to jdk/testlibrary

Reviewed-by: chegar
This commit is contained in:
Michael McMahon 2014-08-26 10:10:58 +01:00
parent 82dd03274a
commit 7c8053cd97
15 changed files with 101 additions and 23 deletions

View File

@ -24,11 +24,14 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm -Dsun.net.httpserver.selCacheTimeout=2 SelCacheTest
* @summary Light weight HTTP server
*/
import com.sun.net.httpserver.*;
import jdk.testlibrary.SimpleSSLContext;
import java.util.*;
import java.util.concurrent.*;
@ -65,7 +68,7 @@ public class SelCacheTest extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
ctx = new SimpleSSLContext(System.getProperty("test.src")).get();
ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test1
* @run main/othervm -Dsun.net.httpserver.maxReqTime=10 Test1
* @run main/othervm -Dsun.net.httpserver.nodelay=true Test1
@ -36,6 +38,7 @@ import java.util.concurrent.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/* basic http/s connectivity test
* Tests:
@ -72,7 +75,7 @@ public class Test1 extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
ctx = new SimpleSSLContext(System.getProperty("test.src")).get();
ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test12
* @summary Light weight HTTP server
*/
@ -34,6 +36,7 @@ import java.util.concurrent.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/* basic http/s connectivity test
* Tests:
@ -62,7 +65,7 @@ public class Test12 extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
ctx = new SimpleSSLContext(System.getProperty("test.src")).get();
ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test13
* @summary Light weight HTTP server
*/
@ -34,8 +36,8 @@ import java.util.concurrent.*;
import java.util.logging.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/* basic http/s connectivity test
* Tests:
@ -71,7 +73,7 @@ public class Test13 extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
ctx = new SimpleSSLContext(System.getProperty("test.src")).get();
ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test6a
* @summary Light weight HTTP server
*/
@ -34,6 +36,7 @@ import java.util.concurrent.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/**
* Test https POST large file via chunked encoding (unusually small chunks)
@ -47,7 +50,7 @@ public class Test6a extends Test {
HttpsServer server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
SSLContext ssl = new SimpleSSLContext().get();
server.setExecutor (executor);
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
server.start ();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test7a
* @summary Light weight HTTP server
*/
@ -34,6 +36,7 @@ import java.util.concurrent.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/**
* Test POST large file via chunked encoding (large chunks)
@ -52,7 +55,7 @@ public class Test7a extends Test {
HttpsServer server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
SSLContext ssl = new SimpleSSLContext().get();
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
server.setExecutor (executor);
server.start ();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test8a
* @summary Light weight HTTP server
*/
@ -34,6 +36,7 @@ import java.util.concurrent.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/**
* Test POST large file via fixed len encoding
@ -55,7 +58,7 @@ public class Test8a extends Test {
server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
executor = Executors.newCachedThreadPool();
SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
SSLContext ssl = new SimpleSSLContext().get();
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
server.setExecutor (executor);
server.start ();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test9
* @summary Light weight HTTP server
*/
@ -34,6 +36,7 @@ import java.util.concurrent.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/* Same as Test1 but requests run in parallel.
*/
@ -59,7 +62,7 @@ public class Test9 extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
ctx = new SimpleSSLContext(System.getProperty("test.src")).get();
ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();

View File

@ -24,6 +24,8 @@
/**
* @test
* @bug 6270015
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm Test9a
* @summary Light weight HTTP server
*/
@ -34,6 +36,7 @@ import java.util.concurrent.*;
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
/* Same as Test1 but requests run in parallel.
*/
@ -56,8 +59,8 @@ public class Test9a extends Test {
HttpContext c1 = server.createContext ("/test1", h);
executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
serverCtx = new SimpleSSLContext(System.getProperty("test.src")).get();
clientCtx = new SimpleSSLContext(System.getProperty("test.src")).get();
serverCtx = new SimpleSSLContext().get();
clientCtx = new SimpleSSLContext().get();
server.setHttpsConfigurator(new HttpsConfigurator (serverCtx));
server.start();

View File

@ -27,7 +27,8 @@ import java.net.URLPermission;
*
* @test
* @bug 8010464
* @compile ../../../com/sun/net/httpserver/SimpleSSLContext.java
* @library /lib/testlibrary/
* @build jdk.testlibrary.SimpleSSLContext
* @run main/othervm/policy=policy.1 URLTest one
* @run main/othervm URLTest one
* @run main/othervm/policy=policy.2 URLTest two
@ -43,6 +44,7 @@ import java.util.concurrent.*;
import java.util.logging.*;
import com.sun.net.httpserver.*;
import javax.net.ssl.*;
import jdk.testlibrary.SimpleSSLContext;
public class URLTest {
static boolean failed = false;
@ -209,10 +211,7 @@ public class URLTest {
httpServer.setExecutor (e);
httpsServer.setExecutor (es);
// take the keystore from elsewhere in test hierarchy
String keysdir = System.getProperty("test.src")
+ "/../../../com/sun/net/httpserver/";
ctx = new SimpleSSLContext(keysdir).get();
ctx = new SimpleSSLContext().get();
httpsServer.setHttpsConfigurator(new HttpsConfigurator (ctx));
httpServer.start();

View File

@ -28,12 +28,13 @@ grant {
// needed for HttpServer
permission "java.net.SocketPermission" "localhost:1024-", "listen,resolve,accept";
permission "java.util.PropertyPermission" "test.src", "read";
permission java.io.FilePermission "${test.src}/../../../com/sun/net/httpserver/testkeys", "read";
permission java.io.FilePermission "${test.src}/../../../lib/testlibrary/jdk/testlibrary/testkeys", "read";
//permission "java.util.logging.LoggingPermission" "control";
//permission "java.io.FilePermission" "/tmp/-", "read,write";
permission "java.lang.RuntimePermission" "modifyThread";
permission "java.lang.RuntimePermission" "setFactory";
permission "java.util.PropertyPermission" "test.src.path", "read";
};
// Normal permissions that aren't granted when run under jtreg

View File

@ -28,12 +28,13 @@ grant {
// needed for HttpServer
permission "java.net.SocketPermission" "localhost:1024-", "listen,resolve,accept";
permission "java.util.PropertyPermission" "test.src", "read";
permission java.io.FilePermission "${test.src}/../../../com/sun/net/httpserver/testkeys", "read";
permission java.io.FilePermission "${test.src}/../../../lib/testlibrary/jdk/testlibrary/testkeys", "read";
//permission "java.util.logging.LoggingPermission" "control";
//permission "java.io.FilePermission" "/tmp/-", "read,write";
permission "java.lang.RuntimePermission" "modifyThread";
permission "java.lang.RuntimePermission" "setFactory";
permission "java.util.PropertyPermission" "test.src.path", "read";
};
// Normal permissions that aren't granted when run under jtreg

View File

@ -28,12 +28,13 @@ grant {
// needed for HttpServer
permission "java.net.SocketPermission" "localhost:1024-", "listen,resolve,accept";
permission "java.util.PropertyPermission" "test.src", "read";
permission java.io.FilePermission "${test.src}/../../../com/sun/net/httpserver/testkeys", "read";
permission java.io.FilePermission "${test.src}/../../../lib/testlibrary/jdk/testlibrary/testkeys", "read";
//permission "java.util.logging.LoggingPermission" "control";
//permission "java.io.FilePermission" "/tmp/-", "read,write";
permission "java.lang.RuntimePermission" "modifyThread";
permission "java.lang.RuntimePermission" "setFactory";
permission "java.util.PropertyPermission" "test.src.path", "read";
};
// Normal permissions that aren't granted when run under jtreg

View File

@ -21,6 +21,8 @@
* questions.
*/
package jdk.testlibrary;
import com.sun.net.httpserver.*;
import java.util.*;
@ -31,16 +33,64 @@ import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
/**
* Creates a simple usable SSLContext for SSLSocketFactory
* or a HttpsServer using either a given keystore or a default
* one in the test tree.
*
* Using this class with a security manager requires the following
* permissions to be granted:
*
* permission "java.util.PropertyPermission" "test.src.path", "read";
* permission java.io.FilePermission
* "${test.src}/../../../lib/testlibrary/jdk/testlibrary/testkeys", "read";
* The exact path above depends on the location of the test.
*/
public class SimpleSSLContext {
SSLContext ssl;
SimpleSSLContext (String dir) throws IOException {
/**
* loads default keystore from SimpleSSLContext
* source directory
*/
public SimpleSSLContext () throws IOException {
String paths = System.getProperty("test.src.path");
StringTokenizer st = new StringTokenizer(paths,":");
boolean securityExceptions = false;
while (st.hasMoreTokens()) {
String path = st.nextToken();
try {
File f = new File(path, "jdk/testlibrary/testkeys");
if (f.exists()) {
init (new FileInputStream(f));
return;
}
} catch (SecurityException e) {
// catch and ignore because permission only required
// for one entry on path (at most)
securityExceptions = true;
}
}
if (securityExceptions) {
System.err.println("SecurityExceptions thrown on loading testkeys");
}
}
/**
* loads default keystore from given directory
*/
public SimpleSSLContext (String dir) throws IOException {
String file = dir+"/testkeys";
FileInputStream fis = new FileInputStream(file);
init(fis);
}
private void init (InputStream i) throws IOException {
try {
String file = dir+"/testkeys";
char[] passphrase = "passphrase".toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(file), passphrase);
ks.load(i, passphrase);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, passphrase);
@ -63,7 +113,7 @@ public class SimpleSSLContext {
}
}
SSLContext get () {
public SSLContext get () {
return ssl;
}
}