提交 fc73eb55 编写于 作者: M michaelm

8027881: test/java/net/URLPermission/nstest/LookupTest.java failing...

8027881: test/java/net/URLPermission/nstest/LookupTest.java failing intermittently, output insufficient
Reviewed-by: chegar
上级 790a6aaf
......@@ -26,7 +26,7 @@ import java.io.*;
/**
* @test
* @bug 8010464 8027570
* @bug 8010464 8027570 8027687
*/
public class URLPermissionTest {
......
......@@ -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);
}
}
}
#!/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
//
// 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;
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册