mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-02 19:20:19 +00:00
8008729: Make sure that we can run basic jsr223 tests using jtreg
Reviewed-by: jlaskey, hannesw, lagergren
This commit is contained in:
parent
1867421e9b
commit
48a5d9cb5f
7
nashorn/test/TEST.ROOT
Normal file
7
nashorn/test/TEST.ROOT
Normal file
@ -0,0 +1,7 @@
|
||||
# This file identifies the root of the test-suite hierarchy.
|
||||
# It also contains test-suite configuration information.
|
||||
# DO NOT EDIT without first contacting jdk-regtest@sun.com.
|
||||
|
||||
# The list of keywords supported in the entire test suite
|
||||
keys=2d dnd i18n
|
||||
|
||||
@ -33,6 +33,9 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* Test that we can create multiple, independent script engines and use those
|
||||
* independently.
|
||||
*
|
||||
* @test
|
||||
* @run testng jdk.nashorn.api.scripting.MultipleEngineTest
|
||||
*/
|
||||
|
||||
public class MultipleEngineTest {
|
||||
|
||||
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.scripting;
|
||||
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* jsr223 tests for security access checks.
|
||||
*/
|
||||
public class ScriptEngineSecurityTest {
|
||||
|
||||
private void log(String msg) {
|
||||
org.testng.Reporter.log(msg, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityPackagesTest() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("var v = Packages.sun.misc.Unsafe;");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityJavaTypeTest() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("var v = Java.type('sun.misc.Unsafe');");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityClassForNameTest() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("var v = java.lang.Class.forName('sun.misc.Unsafe');");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securitySystemExit() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("java.lang.System.exit(0);");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securitySystemLoadLibrary() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("java.lang.System.loadLibrary('foo');");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,6 +54,10 @@ import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests for JSR-223 script engine for Nashorn.
|
||||
*
|
||||
* @test
|
||||
* @build jdk.nashorn.api.scripting.Window jdk.nashorn.api.scripting.WindowEventHandler jdk.nashorn.api.scripting.ScriptEngineTest
|
||||
* @run testng jdk.nashorn.api.scripting.ScriptEngineTest
|
||||
*/
|
||||
public class ScriptEngineTest {
|
||||
|
||||
@ -655,106 +659,6 @@ public class ScriptEngineTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityPackagesTest() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("var v = Packages.sun.misc.Unsafe;");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityJavaTypeTest() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("var v = Java.type('sun.misc.Unsafe');");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityClassForNameTest() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("var v = java.lang.Class.forName('sun.misc.Unsafe');");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securitySystemExit() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("java.lang.System.exit(0);");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securitySystemLoadLibrary() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
// pass vacuously
|
||||
}
|
||||
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
final ScriptEngine e = m.getEngineByName("nashorn");
|
||||
try {
|
||||
e.eval("java.lang.System.loadLibrary('foo');");
|
||||
fail("should have thrown SecurityException");
|
||||
} catch (final Exception exp) {
|
||||
if (exp instanceof SecurityException) {
|
||||
log("got " + exp + " as expected");
|
||||
} else {
|
||||
fail(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsobjectTest() {
|
||||
final ScriptEngineManager m = new ScriptEngineManager();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user