8027881: test/java/net/URLPermission/nstest/LookupTest.java failing intermittently, output insufficient
Reviewed-by: chegar
This commit is contained in:
parent
dd458ac89c
commit
bffc06393b
@ -26,7 +26,7 @@ import java.io.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8010464 8027570
|
* @bug 8010464 8027570 8027687
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class URLPermissionTest {
|
public class URLPermissionTest {
|
||||||
|
@ -21,12 +21,6 @@
|
|||||||
* questions.
|
* 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
|
* This is a simple smoke test of the HttpURLPermission mechanism, which
|
||||||
* checks for either IOException (due to unknown host) or SecurityException
|
* checks for either IOException (due to unknown host) or SecurityException
|
||||||
@ -35,6 +29,7 @@
|
|||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.testlibrary.Utils;
|
||||||
|
|
||||||
public class LookupTest {
|
public class LookupTest {
|
||||||
|
|
||||||
@ -48,12 +43,12 @@ public class LookupTest {
|
|||||||
InputStream is = urlc.getInputStream();
|
InputStream is = urlc.getInputStream();
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
if (!throwsSecException) {
|
if (!throwsSecException) {
|
||||||
throw new RuntimeException ("(1) was not expecting " + e);
|
throw new RuntimeException ("(1) was not expecting ", e);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
if (!throwsIOException) {
|
if (!throwsIOException) {
|
||||||
throw new RuntimeException ("(2) was not expecting " + ioe);
|
throw new RuntimeException ("(2) was not expecting ", ioe);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -64,31 +59,41 @@ public class LookupTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int port;
|
||||||
|
static ServerSocket serverSocket;
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
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("allowedAndFound.com", "127.0.0.1");
|
||||||
SimpleNameService.put("notAllowedButFound.com", "99.99.99.99");
|
SimpleNameService.put("notAllowedButFound.com", "99.99.99.99");
|
||||||
// name "notAllowedAndNotFound.com" is not in map
|
// name "notAllowedAndNotFound.com" is not in map
|
||||||
// name "allowedButNotfound.com" is not in map
|
// name "allowedButNotfound.com" is not in map
|
||||||
|
try {
|
||||||
startServer();
|
startServer();
|
||||||
|
|
||||||
String policyFileName = "file://" + System.getProperty("test.src", ".") + "/policy";
|
|
||||||
System.err.println ("policy = " + policyFileName);
|
|
||||||
|
|
||||||
System.setProperty("java.security.policy", policyFileName);
|
|
||||||
|
|
||||||
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 Thread server;
|
||||||
static ServerSocket serverSocket;
|
|
||||||
|
|
||||||
static class Server extends Thread {
|
static class Server extends Thread {
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -112,11 +117,11 @@ public class LookupTest {
|
|||||||
|
|
||||||
static void startServer() {
|
static void startServer() {
|
||||||
try {
|
try {
|
||||||
serverSocket = new ServerSocket(50100);
|
serverSocket = new ServerSocket(port);
|
||||||
server = new Server();
|
server = new Server();
|
||||||
server.start();
|
server.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException ("Test failed to initialize");
|
throw new RuntimeException ("Test failed to initialize", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
48
jdk/test/java/net/URLPermission/nstest/lookup.sh
Normal file
48
jdk/test/java/net/URLPermission/nstest/lookup.sh
Normal file
@ -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
|
@ -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;
|
|
||||||
};
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user