From 55dd3581e6bec8760468bb82119c7e9ba920e531 Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Thu, 2 Jan 2025 22:52:01 +0100 Subject: [PATCH] Adapt tests to lack of SecurityManager --- .../script/basic/JDK-8010946-privileged.js | 47 -------------- test/nashorn/script/basic/JDK-8010946.js | 51 --------------- .../script/basic/JDK-8010946.js.EXPECTED | 5 -- test/nashorn/script/basic/JDK-8020508.js | 37 ----------- .../script/basic/JDK-8020508.js.EXPECTED | 1 - test/nashorn/script/basic/JDK-8158467.js | 14 ----- .../script/basic/JDK-8158467.js.EXPECTED | 2 - test/nashorn/script/basic/classloader.js | 41 ------------ .../script/basic/classloader.js.EXPECTED | 1 - test/nashorn/script/sandbox/JDK-8031106.js | 39 ------------ test/nashorn/script/sandbox/classbind.js | 41 ------------ test/nashorn/script/sandbox/classloader.js | 63 ------------------- .../script/sandbox/classloader.js.EXPECTED | 3 - test/nashorn/script/sandbox/doprivileged.js | 58 ----------------- .../script/sandbox/doprivileged.js.EXPECTED | 2 - test/nashorn/script/sandbox/env.js | 36 ----------- test/nashorn/script/sandbox/exec.js | 39 ------------ test/nashorn/script/sandbox/exit.js | 60 ------------------ test/nashorn/script/sandbox/exit.js.EXPECTED | 4 -- test/nashorn/script/sandbox/file.js | 55 ---------------- test/nashorn/script/sandbox/file.js.EXPECTED | 3 - test/nashorn/script/sandbox/loadLibrary.js | 43 ------------- test/nashorn/script/sandbox/net.js | 43 ------------- test/nashorn/script/sandbox/net.js.EXPECTED | 1 - test/nashorn/script/sandbox/property.js | 44 ------------- .../script/sandbox/property.js.EXPECTED | 1 - test/nashorn/script/sandbox/unsafe.js | 21 ------- test/nashorn/script/trusted/JDK-8008305.js | 9 +-- test/nashorn/script/trusted/JDK-8021129.js | 1 - .../script/trusted/JDK-8021129.js.EXPECTED | 7 +-- test/nashorn/script/trusted/JDK-8021189.js | 35 ----------- .../script/trusted/JDK-8021189.js.EXPECTED | 1 - .../trusted/classfilter_extends.js.EXPECTED | 4 +- .../test/models/InternalRunnable.java | 5 -- 34 files changed, 6 insertions(+), 811 deletions(-) delete mode 100644 test/nashorn/script/basic/JDK-8010946-privileged.js delete mode 100644 test/nashorn/script/basic/JDK-8010946.js delete mode 100644 test/nashorn/script/basic/JDK-8010946.js.EXPECTED delete mode 100644 test/nashorn/script/basic/JDK-8020508.js delete mode 100644 test/nashorn/script/basic/JDK-8020508.js.EXPECTED delete mode 100644 test/nashorn/script/basic/classloader.js delete mode 100644 test/nashorn/script/basic/classloader.js.EXPECTED delete mode 100644 test/nashorn/script/sandbox/JDK-8031106.js delete mode 100644 test/nashorn/script/sandbox/classbind.js delete mode 100644 test/nashorn/script/sandbox/classloader.js delete mode 100644 test/nashorn/script/sandbox/classloader.js.EXPECTED delete mode 100644 test/nashorn/script/sandbox/doprivileged.js delete mode 100644 test/nashorn/script/sandbox/doprivileged.js.EXPECTED delete mode 100644 test/nashorn/script/sandbox/env.js delete mode 100644 test/nashorn/script/sandbox/exec.js delete mode 100644 test/nashorn/script/sandbox/exit.js delete mode 100644 test/nashorn/script/sandbox/exit.js.EXPECTED delete mode 100644 test/nashorn/script/sandbox/file.js delete mode 100644 test/nashorn/script/sandbox/file.js.EXPECTED delete mode 100644 test/nashorn/script/sandbox/loadLibrary.js delete mode 100644 test/nashorn/script/sandbox/net.js delete mode 100644 test/nashorn/script/sandbox/net.js.EXPECTED delete mode 100644 test/nashorn/script/sandbox/property.js delete mode 100644 test/nashorn/script/sandbox/property.js.EXPECTED delete mode 100644 test/nashorn/script/trusted/JDK-8021189.js delete mode 100644 test/nashorn/script/trusted/JDK-8021189.js.EXPECTED diff --git a/test/nashorn/script/basic/JDK-8010946-privileged.js b/test/nashorn/script/basic/JDK-8010946-privileged.js deleted file mode 100644 index 2e04f542b..000000000 --- a/test/nashorn/script/basic/JDK-8010946-privileged.js +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * JDK-8010946: AccessController.doPrivileged() doesn't work as expected. - * This is actually a broader issue of having Dynalink correctly handle - * caller-sensitive methods. - * - * NOTE: This is not a standalone test file, it is loaded by JDK-801946.js - * @subtest - */ - -(function() { - var getProperty = java.lang.System.getProperty - var doPrivileged = java.security.AccessController["doPrivileged(PrivilegedAction)"] - - this.executeUnprivileged = function() { - var x = getProperty("java.security.policy") - if(x != null) { - print("Successfully retrieved restricted system property.") - } - } - - this.executePrivileged = function() { - doPrivileged(executeUnprivileged) - } -})(); diff --git a/test/nashorn/script/basic/JDK-8010946.js b/test/nashorn/script/basic/JDK-8010946.js deleted file mode 100644 index 290d60ea3..000000000 --- a/test/nashorn/script/basic/JDK-8010946.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * JDK-8010946: AccessController.doPrivileged() doesn't work as expected. - * This is actually a broader issue of having Dynalink correctly handle - * caller-sensitive methods. - * - * @test - * @run - */ - -// This is unprivileged code that loads privileged code. -load(__DIR__ + "JDK-8010946-privileged.js") - -try { - // This should fail, even though the code itself resides in the - // privileged script, as we're invoking it without going through - // doPrivileged() - print("Attempting unprivileged execution...") - executeUnprivileged() - print("FAIL: Unprivileged execution succeeded!") -} catch(e) { - print("Unprivileged execution failed with " + e) -} - -print() - -// This should succeed, as it's going through doPrivileged(). -print("Attempting privileged execution...") -executePrivileged() diff --git a/test/nashorn/script/basic/JDK-8010946.js.EXPECTED b/test/nashorn/script/basic/JDK-8010946.js.EXPECTED deleted file mode 100644 index f78956a88..000000000 --- a/test/nashorn/script/basic/JDK-8010946.js.EXPECTED +++ /dev/null @@ -1,5 +0,0 @@ -Attempting unprivileged execution... -Unprivileged execution failed with java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.security.policy" "read") - -Attempting privileged execution... -Successfully retrieved restricted system property. diff --git a/test/nashorn/script/basic/JDK-8020508.js b/test/nashorn/script/basic/JDK-8020508.js deleted file mode 100644 index 3499e1744..000000000 --- a/test/nashorn/script/basic/JDK-8020508.js +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * JDK-8020508: Enforce reflection check on - * Object.bindProperties(target, source) for beans - * - * @test - * @run - */ - -var x = {} -try { - Object.bindProperties(x, java.util.Vector.class) -} catch(e) { - print(e) -} diff --git a/test/nashorn/script/basic/JDK-8020508.js.EXPECTED b/test/nashorn/script/basic/JDK-8020508.js.EXPECTED deleted file mode 100644 index 356053d4e..000000000 --- a/test/nashorn/script/basic/JDK-8020508.js.EXPECTED +++ /dev/null @@ -1 +0,0 @@ -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") diff --git a/test/nashorn/script/basic/JDK-8158467.js b/test/nashorn/script/basic/JDK-8158467.js index 51eda1ee1..28d3a195e 100644 --- a/test/nashorn/script/basic/JDK-8158467.js +++ b/test/nashorn/script/basic/JDK-8158467.js @@ -60,20 +60,6 @@ EOF); print(obj.hashCode()); print(obj.toString()); -// should throw SecurityException! -try { - e.eval("Packages.jdk.internal"); -} catch (ex) { - print(ex); -} - -// should throw SecurityException! -try { - e.eval("Java.type('jdk.internal.misc.Unsafe')"); -} catch (ex) { - print(ex); -} - // should throw ClassNotFoundException! try { e.eval("Java.type('org.openjdk.nashorn.internal.runtime.Context')"); diff --git a/test/nashorn/script/basic/JDK-8158467.js.EXPECTED b/test/nashorn/script/basic/JDK-8158467.js.EXPECTED index 63c41c28d..12c612513 100644 --- a/test/nashorn/script/basic/JDK-8158467.js.EXPECTED +++ b/test/nashorn/script/basic/JDK-8158467.js.EXPECTED @@ -4,7 +4,5 @@ hello Runnable 33 I'm object -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.jdk.internal") -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.jdk.internal.misc") java.lang.RuntimeException: java.lang.ClassNotFoundException: org.openjdk.nashorn.internal.runtime.Context java.lang.ClassNotFoundException: org.openjdk.nashorn.api.scripting.JSObject diff --git a/test/nashorn/script/basic/classloader.js b/test/nashorn/script/basic/classloader.js deleted file mode 100644 index b46d23e41..000000000 --- a/test/nashorn/script/basic/classloader.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to extend ClassLoader. - * - * @test - * @security - */ - -try { - var l = new (Java.extend(java.lang.ClassLoader))({}); - fail("should have thrown SecurityException"); -} catch (e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - diff --git a/test/nashorn/script/basic/classloader.js.EXPECTED b/test/nashorn/script/basic/classloader.js.EXPECTED deleted file mode 100644 index e08cc9f8b..000000000 --- a/test/nashorn/script/basic/classloader.js.EXPECTED +++ /dev/null @@ -1 +0,0 @@ -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader") diff --git a/test/nashorn/script/sandbox/JDK-8031106.js b/test/nashorn/script/sandbox/JDK-8031106.js deleted file mode 100644 index 26d15a2a6..000000000 --- a/test/nashorn/script/sandbox/JDK-8031106.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2010, 2014, 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. - */ - -/** - * JDK-8031106: Nashorn: IndexOutOfBoundsException in NashornCallSiteDescriptor.getNameToken() - * - * @test - * @run - */ - -var cl = new java.lang.Object().getClass(); -try { - cl["forName"]; - fail("Should have thrown exception!"); -} catch (e) { - if (! (e instanceof java.lang.SecurityException)) { - fail("SecurityException expected, got " + e); - } -} diff --git a/test/nashorn/script/sandbox/classbind.js b/test/nashorn/script/sandbox/classbind.js deleted file mode 100644 index 05e129287..000000000 --- a/test/nashorn/script/sandbox/classbind.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to bind properties of StaticClass representing Class. - * - * @test - * @bug JDK-8032943: Improve reflection in Nashorn - */ - - -var obj = {} - -try { - Object.bindProperties(obj, Java.type("java.lang.Class")); - fail("SecurityException should have been thrown"); -} catch (e) { - if (! (e instanceof java.lang.SecurityException)) { - fail("SecurityException expected, got " + e); - } -} diff --git a/test/nashorn/script/sandbox/classloader.js b/test/nashorn/script/sandbox/classloader.js deleted file mode 100644 index 36cf464c4..000000000 --- a/test/nashorn/script/sandbox/classloader.js +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to extend ClassLoader. - * - * @test - * @security - * @bug JDK-8032954: Nashorn: extend Java.extend - */ - -try { - var l = new (Java.extend(java.lang.ClassLoader))({}); - fail("should have thrown SecurityException"); -} catch (e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - -try { - Java.extend(Java.type('java.lang.ClassLoader')); - fail("should have thrown SecurityException"); -} catch (e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - -try { - Java.extend(Java.type("javax.management.loading.MLet")); - fail("should have thrown SecurityException"); -} catch (e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} diff --git a/test/nashorn/script/sandbox/classloader.js.EXPECTED b/test/nashorn/script/sandbox/classloader.js.EXPECTED deleted file mode 100644 index 8c241912f..000000000 --- a/test/nashorn/script/sandbox/classloader.js.EXPECTED +++ /dev/null @@ -1,3 +0,0 @@ -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "nashorn.JavaReflection") diff --git a/test/nashorn/script/sandbox/doprivileged.js b/test/nashorn/script/sandbox/doprivileged.js deleted file mode 100644 index 5b08361fc..000000000 --- a/test/nashorn/script/sandbox/doprivileged.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * doPrivileged checks. - * - * @test - * @security - */ - -function check(e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - -var AccessController = java.security.AccessController; -var PrivilegedAction = java.security.PrivilegedAction; - -AccessController.doPrivileged(new PrivilegedAction() { - run: function() { - // try something sensitive - try { - java.lang.System.exit(0); - } catch(e) { - check(e); - } - - try { - var prop = java.lang.System.getProperty("user.dir"); - fail("can get user.dir " + prop); - } catch(e) { - print(e); - } - } -}); diff --git a/test/nashorn/script/sandbox/doprivileged.js.EXPECTED b/test/nashorn/script/sandbox/doprivileged.js.EXPECTED deleted file mode 100644 index 0730cdd4c..000000000 --- a/test/nashorn/script/sandbox/doprivileged.js.EXPECTED +++ /dev/null @@ -1,2 +0,0 @@ -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0") -java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.dir" "read") diff --git a/test/nashorn/script/sandbox/env.js b/test/nashorn/script/sandbox/env.js deleted file mode 100644 index 5ef40a2d2..000000000 --- a/test/nashorn/script/sandbox/env.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to get env object - * - * @test - * @security - * @option -scripting - */ - -var env = $ENV; -// should be empty!! -for (i in env) { - print("FAILED: can get: " + i + " = " + env[i]); -} diff --git a/test/nashorn/script/sandbox/exec.js b/test/nashorn/script/sandbox/exec.js deleted file mode 100644 index 0f32938ed..000000000 --- a/test/nashorn/script/sandbox/exec.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to get exec - * - * @test - * @security - * @option -scripting - */ - -try { - var ans = `java -version`; - fail("should have thrown exception!"); -} catch (e) { - if (! (e instanceof java.lang.SecurityException)) { - fail("SecurityException expected, got " + e); - } -} diff --git a/test/nashorn/script/sandbox/exit.js b/test/nashorn/script/sandbox/exit.js deleted file mode 100644 index b807c9764..000000000 --- a/test/nashorn/script/sandbox/exit.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to call System.exit, quit and exit. - * - * @test - * @security - */ - -function check(e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - -try { - java.lang.System.exit(0); - // will not reach here regardless of outcome.. -} catch (e) { - check(e); -} - -try { - quit(); - // will not reach here regardless of outcome.. -} catch (e) { - check(e); -} - -try { - exit(0); - // will not reach here regardless of outcome.. -} catch (e) { - check(e); -} - -print("Success, didn't exit!"); diff --git a/test/nashorn/script/sandbox/exit.js.EXPECTED b/test/nashorn/script/sandbox/exit.js.EXPECTED deleted file mode 100644 index c1411eb89..000000000 --- a/test/nashorn/script/sandbox/exit.js.EXPECTED +++ /dev/null @@ -1,4 +0,0 @@ -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0") -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0") -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0") -Success, didn't exit! diff --git a/test/nashorn/script/sandbox/file.js b/test/nashorn/script/sandbox/file.js deleted file mode 100644 index 3aaa89788..000000000 --- a/test/nashorn/script/sandbox/file.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * try file system activities. - * - * @test - * @security - */ - -function check(e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - -try { - new java.io.File(".").getCanonicalPath(); -} catch (e) { - check(e); -} - -try { - new java.io.FileInputStream("foo"); -} catch (e) { - check(e); -} - -try { - new java.io.FileOutputStream("foo"); -} catch (e) { - check(e); -} diff --git a/test/nashorn/script/sandbox/file.js.EXPECTED b/test/nashorn/script/sandbox/file.js.EXPECTED deleted file mode 100644 index 5a1e0e453..000000000 --- a/test/nashorn/script/sandbox/file.js.EXPECTED +++ /dev/null @@ -1,3 +0,0 @@ -java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.dir" "read") -java.security.AccessControlException: access denied ("java.io.FilePermission" "foo" "read") -java.security.AccessControlException: access denied ("java.io.FilePermission" "foo" "write") diff --git a/test/nashorn/script/sandbox/loadLibrary.js b/test/nashorn/script/sandbox/loadLibrary.js deleted file mode 100644 index e693d2227..000000000 --- a/test/nashorn/script/sandbox/loadLibrary.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to call System.loadLibrary - * - * @test - * @security - */ - -function check(e) { - if (! (e instanceof java.lang.SecurityException)) { - fail("expected SecurityException, got " + e); - } -} - -try { - java.lang.System.loadLibrary("foo"); - fail("should have thrown exception"); -} catch (e) { - check(e); -} - diff --git a/test/nashorn/script/sandbox/net.js b/test/nashorn/script/sandbox/net.js deleted file mode 100644 index c7fd8d010..000000000 --- a/test/nashorn/script/sandbox/net.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try network activity. - * - * @test - * @security - */ - -function check(e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - -try { - new java.net.URL("http://www.acme.com").openStream(); -} catch (e) { - check(e); -} diff --git a/test/nashorn/script/sandbox/net.js.EXPECTED b/test/nashorn/script/sandbox/net.js.EXPECTED deleted file mode 100644 index dfa7334a7..000000000 --- a/test/nashorn/script/sandbox/net.js.EXPECTED +++ /dev/null @@ -1 +0,0 @@ -java.security.AccessControlException: access denied ("java.net.SocketPermission" "www.acme.com:80" "connect,resolve") diff --git a/test/nashorn/script/sandbox/property.js b/test/nashorn/script/sandbox/property.js deleted file mode 100644 index 8aeb499ea..000000000 --- a/test/nashorn/script/sandbox/property.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * Try to read sensitive System property. - * - * @test - * @security - */ - -function check(e) { - if (e instanceof java.lang.SecurityException) { - print(e); - } else { - fail("expected SecurityException, got " + e); - } -} - -try { - var prop = java.lang.System.getProperty("user.dir"); - fail("can read user.dir " + prop); -} catch (e) { - check(e); -} diff --git a/test/nashorn/script/sandbox/property.js.EXPECTED b/test/nashorn/script/sandbox/property.js.EXPECTED deleted file mode 100644 index 73c67af59..000000000 --- a/test/nashorn/script/sandbox/property.js.EXPECTED +++ /dev/null @@ -1 +0,0 @@ -java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.dir" "read") diff --git a/test/nashorn/script/sandbox/unsafe.js b/test/nashorn/script/sandbox/unsafe.js index 9c6f1b824..457a69a9e 100644 --- a/test/nashorn/script/sandbox/unsafe.js +++ b/test/nashorn/script/sandbox/unsafe.js @@ -35,27 +35,6 @@ function check(e) { } } -try { - var unsafe = java.lang.Class.forName("sun.misc.Unsafe"); - fail("No SecurityException for Class.forName sun.misc.Unsafe"); -} catch (e) { - check(e); -} - -try { - var unsafe = Java.type("sun.misc.Unsafe"); - fail("No SecurityException for Java.type sun.misc.Unsafe"); -} catch (e) { - check(e); -} - -try { - var unsafe = Packages.sun.misc.Unsafe; - fail("No SecurityException for Packages.sun.misc.Unsafe"); -} catch (e) { - check(e); -} - try { var cl = Packages.org.openjdk.nashorn.internal.runtime.Context.class; var unsafe = cl.getClassLoader().loadClass("sun.misc.Unsafe"); diff --git a/test/nashorn/script/trusted/JDK-8008305.js b/test/nashorn/script/trusted/JDK-8008305.js index 7bdd84562..3acd5bb57 100644 --- a/test/nashorn/script/trusted/JDK-8008305.js +++ b/test/nashorn/script/trusted/JDK-8008305.js @@ -49,11 +49,4 @@ if (! res.equals(new File(".").getAbsolutePath())) { } // try same subtest without URLReader and so it runs with null code source -try { - e.eval(new FileReader(scriptFile)); - fail("Expected SecurityException from script!"); -} catch (e) { - if (! (e instanceof SecurityException)) { - fail("Expected SecurityException, but got " + e); - } -} +e.eval(new FileReader(scriptFile)); diff --git a/test/nashorn/script/trusted/JDK-8021129.js b/test/nashorn/script/trusted/JDK-8021129.js index b55c48d39..69471655c 100644 --- a/test/nashorn/script/trusted/JDK-8021129.js +++ b/test/nashorn/script/trusted/JDK-8021129.js @@ -37,7 +37,6 @@ print(r1.toString()) // Can execute public method from a superclass print(r1.restrictedRun === undefined) // Can't see method from a restricted interface print(r1.canNotInvokeThis === undefined) // Can't see any other public methods -print(r1.invisibleProperty === undefined) // Can't see any other properties print(r1.canSeeThisField === undefined) // Can't see fields from superclasses print(r1.canNotSeeThisField === undefined) // Can't see its own fields diff --git a/test/nashorn/script/trusted/JDK-8021129.js.EXPECTED b/test/nashorn/script/trusted/JDK-8021129.js.EXPECTED index df7879339..6caa5de0f 100644 --- a/test/nashorn/script/trusted/JDK-8021129.js.EXPECTED +++ b/test/nashorn/script/trusted/JDK-8021129.js.EXPECTED @@ -1,9 +1,8 @@ InternalRunnable.run() executed! InternalRunnable.toString() executed! +false +false true -true -true -true -true +false 19 diff --git a/test/nashorn/script/trusted/JDK-8021189.js b/test/nashorn/script/trusted/JDK-8021189.js deleted file mode 100644 index f7afd1a6b..000000000 --- a/test/nashorn/script/trusted/JDK-8021189.js +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - * - * 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. - */ - -/** - * JDK-8021189: Prevent access to constructors of restricted classes - * - * @test - * @run - */ -var InternalRunnableSuperclass = Java.type("org.openjdk.nashorn.test.models.InternalRunnableSuperclass"); -try { - new (InternalRunnableSuperclass.getInternalRunnableType())(); -} catch(e) { - print(e) -} diff --git a/test/nashorn/script/trusted/JDK-8021189.js.EXPECTED b/test/nashorn/script/trusted/JDK-8021189.js.EXPECTED deleted file mode 100644 index 8aa5d69ca..000000000 --- a/test/nashorn/script/trusted/JDK-8021189.js.EXPECTED +++ /dev/null @@ -1 +0,0 @@ -java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.org.openjdk.nashorn.internal.test.models") diff --git a/test/nashorn/script/trusted/classfilter_extends.js.EXPECTED b/test/nashorn/script/trusted/classfilter_extends.js.EXPECTED index b122020d2..638a53927 100644 --- a/test/nashorn/script/trusted/classfilter_extends.js.EXPECTED +++ b/test/nashorn/script/trusted/classfilter_extends.js.EXPECTED @@ -12,5 +12,5 @@ java.lang.ClassNotFoundException: java.lang.String TypeError: Java.extend needs Java types as its arguments. in at line number 1 java.lang.NullPointerException java.lang.ClassNotFoundException: java.lang.NullPointerException -java.lang.NullPointerException: library can't be null -java.lang.NullPointerException: library can't be null +java.lang.NullPointerException +java.lang.NullPointerException diff --git a/test/nashorn/src/org/openjdk/nashorn/internal/test/models/InternalRunnable.java b/test/nashorn/src/org/openjdk/nashorn/internal/test/models/InternalRunnable.java index 1a27260e5..4a5ed185f 100644 --- a/test/nashorn/src/org/openjdk/nashorn/internal/test/models/InternalRunnable.java +++ b/test/nashorn/src/org/openjdk/nashorn/internal/test/models/InternalRunnable.java @@ -63,9 +63,4 @@ public void canNotInvokeThis() { // This is a public method in a restricted class; scripts should not see it. throw new AssertionError(); } - - public void getInvisibleProperty() { - // This is a public method in a restricted class; scripts should not see it. - throw new AssertionError(); - } }