aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormichaelm <none@none>2013-11-07 10:22:11 +0000
committermichaelm <none@none>2013-11-07 10:22:11 +0000
commit3e26640c2ba6f988fca445b1197141afd8edc957 (patch)
tree669a94f3bb019cc6e2090bc0f02b9dabf254f99b /test
parent370fd7aed60d6e1120d1a175d93ebee83860cd90 (diff)
8027881: test/java/net/URLPermission/nstest/LookupTest.java failing intermittently, output insufficient
Reviewed-by: chegar
Diffstat (limited to 'test')
-rw-r--r--test/java/net/URLPermission/URLPermissionTest.java2
-rw-r--r--test/java/net/URLPermission/nstest/LookupTest.java57
-rw-r--r--test/java/net/URLPermission/nstest/lookup.sh48
-rw-r--r--test/java/net/URLPermission/nstest/policy41
4 files changed, 80 insertions, 68 deletions
diff --git a/test/java/net/URLPermission/URLPermissionTest.java b/test/java/net/URLPermission/URLPermissionTest.java
index 948e9dabb..7e55a63bc 100644
--- a/test/java/net/URLPermission/URLPermissionTest.java
+++ b/test/java/net/URLPermission/URLPermissionTest.java
@@ -26,7 +26,7 @@ import java.io.*;
/**
* @test
- * @bug 8010464 8027570
+ * @bug 8010464 8027570 8027687
*/
public class URLPermissionTest {
diff --git a/test/java/net/URLPermission/nstest/LookupTest.java b/test/java/net/URLPermission/nstest/LookupTest.java
index 5b7635765..fb31e7dcd 100644
--- a/test/java/net/URLPermission/nstest/LookupTest.java
+++ b/test/java/net/URLPermission/nstest/LookupTest.java
@@ -21,12 +21,6 @@
* questions.
*/
-/* @test
- * @compile -XDignore.symbol.file=true SimpleNameService.java
- * SimpleNameServiceDescriptor.java
- * @run main/othervm/timeout=200 -Dsun.net.spi.nameservice.provider.1=simple,sun LookupTest
- */
-
/**
* This is a simple smoke test of the HttpURLPermission mechanism, which
* checks for either IOException (due to unknown host) or SecurityException
@@ -35,6 +29,7 @@
import java.net.*;
import java.io.*;
+import jdk.testlibrary.Utils;
public class LookupTest {
@@ -48,12 +43,12 @@ public class LookupTest {
InputStream is = urlc.getInputStream();
} catch (SecurityException e) {
if (!throwsSecException) {
- throw new RuntimeException ("(1) was not expecting " + e);
+ throw new RuntimeException ("(1) was not expecting ", e);
}
return;
} catch (IOException ioe) {
if (!throwsIOException) {
- throw new RuntimeException ("(2) was not expecting " + ioe);
+ throw new RuntimeException ("(2) was not expecting ", ioe);
}
return;
}
@@ -64,31 +59,41 @@ public class LookupTest {
}
}
- public static void main(String args[]) throws Exception {
- SimpleNameService.put("allowedAndFound.com", "127.0.0.1");
- SimpleNameService.put("notAllowedButFound.com", "99.99.99.99");
- // name "notAllowedAndNotFound.com" is not in map
- // name "allowedButNotfound.com" is not in map
- startServer();
-
- String policyFileName = "file://" + System.getProperty("test.src", ".") + "/policy";
- System.err.println ("policy = " + policyFileName);
+ static int port;
+ static ServerSocket serverSocket;
- System.setProperty("java.security.policy", policyFileName);
+ public static void main(String args[]) throws Exception {
+ String cmd = args[0];
+ if (cmd.equals("-getport")) {
+ port = Utils.getFreePort();
+ System.out.println(port);
+ } else if (cmd.equals("-runtest")) {
+ port = Integer.parseInt(args[1]);
+ SimpleNameService.put("allowedAndFound.com", "127.0.0.1");
+ SimpleNameService.put("notAllowedButFound.com", "99.99.99.99");
+ // name "notAllowedAndNotFound.com" is not in map
+ // name "allowedButNotfound.com" is not in map
+ try {
+ startServer();
- System.setSecurityManager(new SecurityManager());
+ System.setSecurityManager(new SecurityManager());
- test("http://allowedAndFound.com:50100/foo", false, false);
+ test("http://allowedAndFound.com:" + port + "/foo", false, false);
- test("http://notAllowedButFound.com:50100/foo", true, false);
+ test("http://notAllowedButFound.com:" + port + "/foo", true, false);
- test("http://allowedButNotfound.com:50100/foo", false, true);
+ test("http://allowedButNotfound.com:" + port + "/foo", false, true);
- test("http://notAllowedAndNotFound.com:50100/foo", true, false);
+ test("http://notAllowedAndNotFound.com:" + port + "/foo", true, false);
+ } finally {
+ serverSocket.close();
+ }
+ } else {
+ throw new RuntimeException("Bad invocation: " + cmd);
+ }
}
static Thread server;
- static ServerSocket serverSocket;
static class Server extends Thread {
public void run() {
@@ -112,11 +117,11 @@ public class LookupTest {
static void startServer() {
try {
- serverSocket = new ServerSocket(50100);
+ serverSocket = new ServerSocket(port);
server = new Server();
server.start();
} catch (Exception e) {
- throw new RuntimeException ("Test failed to initialize");
+ throw new RuntimeException ("Test failed to initialize", e);
}
}
}
diff --git a/test/java/net/URLPermission/nstest/lookup.sh b/test/java/net/URLPermission/nstest/lookup.sh
new file mode 100644
index 000000000..b9ebb06a9
--- /dev/null
+++ b/test/java/net/URLPermission/nstest/lookup.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2013, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# @test
+# @library /lib/testlibrary
+# @compile -XDignore.symbol.file=true SimpleNameService.java
+# LookupTest.java SimpleNameServiceDescriptor.java
+# @run shell/timeout=50 lookup.sh
+#
+DIR=`pwd`
+
+port=`${TESTJAVA}/bin/java -cp ${TESTCLASSES} LookupTest -getport`
+
+cat << POLICY > policy
+grant {
+ permission java.net.URLPermission "http://allowedAndFound.com:${port}/-", "*:*";
+ permission java.net.URLPermission "http://allowedButNotfound.com:${port}/-", "*:*";
+ permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
+ permission java.util.PropertyPermission "java.io.tmpdir", "read";
+
+ // needed for HttpServer
+ permission "java.net.SocketPermission" "localhost:1024-", "resolve,accept";
+};
+POLICY
+
+${TESTJAVA}/bin/java -Djava.security.policy=file://${DIR}/policy -Dsun.net.spi.nameservice.provider.1=simple,sun -cp ${TESTCLASSES}:${TESTSRC} LookupTest -runtest $port
diff --git a/test/java/net/URLPermission/nstest/policy b/test/java/net/URLPermission/nstest/policy
deleted file mode 100644
index 967af68d0..000000000
--- a/test/java/net/URLPermission/nstest/policy
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Copyright (c) 2013, 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
-// under the terms of the GNU General Public License version 2 only, as
-// published by the Free Software Foundation.
-//
-// This code is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-// version 2 for more details (a copy is included in the LICENSE file that
-// accompanied this code).
-//
-// You should have received a copy of the GNU General Public License version
-// 2 along with this work; if not, write to the Free Software Foundation,
-// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-// or visit www.oracle.com if you need additional information or have any
-// questions.
-//
-
-grant {
- permission java.net.URLPermission "http://allowedAndFound.com:50100/-", "*:*";
- permission java.net.URLPermission "http://allowedButNotfound.com:50100/-", "*:*";
-
- // needed for HttpServer
- permission "java.net.SocketPermission" "localhost:1024-", "resolve,accept";
-};
-
-// Normal permissions that aren't granted when run under jtreg
-
-grant codeBase "file:${{java.ext.dirs}}/*" {
- permission java.security.AllPermission;
-};
-
-grant codeBase "file:${{java.home}}/jre/lib/rt.jar" {
- permission java.security.AllPermission;
-};
-