2558N/A/*
3909N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
2558N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2558N/A *
2558N/A * This code is free software; you can redistribute it and/or modify it
2558N/A * under the terms of the GNU General Public License version 2 only, as
2558N/A * published by the Free Software Foundation.
2558N/A *
2558N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2558N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2558N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2558N/A * version 2 for more details (a copy is included in the LICENSE file that
2558N/A * accompanied this code).
2558N/A *
2558N/A * You should have received a copy of the GNU General Public License version
2558N/A * 2 along with this work; if not, write to the Free Software Foundation,
2558N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2558N/A *
2558N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2558N/A * or visit www.oracle.com if you need additional information or have any
2558N/A * questions.
2558N/A */
2558N/A
2558N/A/*
2558N/A * @test
3754N/A * @bug 6856415
3754N/A * @summary Miscellaneous tests, Exceptions
2733N/A * @compile -XDignore.symbol.file MiscTests.java TestHelper.java
2733N/A * @run main MiscTests
2558N/A */
2558N/A
2558N/A
2558N/Aimport java.io.File;
2558N/Aimport java.io.FileNotFoundException;
2558N/A
2733N/Apublic class MiscTests {
2558N/A
2733N/A // 6856415: Checks to ensure that proper exceptions are thrown by java
2558N/A static void test6856415() {
2558N/A // No pkcs library on win-x64, so we bail out.
2558N/A if (TestHelper.is64Bit && TestHelper.isWindows) {
2558N/A return;
2558N/A }
2558N/A StringBuilder sb = new StringBuilder();
2558N/A sb.append("public static void main(String... args) {\n");
2558N/A sb.append("java.security.Provider p = new sun.security.pkcs11.SunPKCS11(args[0]);\n");
2558N/A sb.append("java.security.Security.insertProviderAt(p, 1);\n");
2558N/A sb.append("}");
2558N/A File testJar = new File("Foo.jar");
2558N/A testJar.delete();
2558N/A try {
2558N/A TestHelper.createJar(testJar, sb.toString());
2558N/A } catch (FileNotFoundException fnfe) {
2558N/A throw new RuntimeException(fnfe);
2558N/A }
2733N/A TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd,
2558N/A "-Djava.security.manager", "-jar", testJar.getName(), "foo.bak");
2733N/A for (String s : tr.testOutput) {
2733N/A System.out.println(s);
2733N/A }
2733N/A if (!tr.contains("java.security.AccessControlException:" +
2733N/A " access denied (\"java.lang.RuntimePermission\"" +
2733N/A " \"accessClassInPackage.sun.security.pkcs11\")")) {
2733N/A System.out.println(tr.status);
2733N/A }
2558N/A }
3754N/A
2558N/A public static void main(String... args) {
2558N/A test6856415();
2733N/A if (TestHelper.testExitValue != 0) {
2733N/A throw new Error(TestHelper.testExitValue + " tests failed");
2558N/A }
2558N/A}
2733N/A}