test/jdk/java/util/TimeZone/TimeZoneDatePermissionCheckRun.java
author yzhou
Mon, 15 Jul 2019 10:21:33 +0800
changeset 55680 cd48f8f260c8
parent 52423 00db205006c9
permissions -rw-r--r--
8227289: Enable assertions for some shell to java conversion tests after JDK-8218960 Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52423
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     1
/*
55680
cd48f8f260c8 8227289: Enable assertions for some shell to java conversion tests after JDK-8218960
yzhou
parents: 52423
diff changeset
     2
 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
52423
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     4
 *
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     8
 *
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    13
 * accompanied this code).
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    14
 *
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    18
 *
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    21
 * questions.
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    22
 */
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    23
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    24
/*
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    25
 * @test
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    26
 * @bug 6584033
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    27
 * @summary Stackoverflow error with security manager, signed jars and debug.
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    28
 * @library /test/lib
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    29
 * @build TimeZoneDatePermissionCheck
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    30
 * @run main TimeZoneDatePermissionCheckRun
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    31
 */
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    32
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    33
import java.io.File;
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    34
import java.util.List;
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    35
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    36
import jdk.test.lib.JDKToolLauncher;
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    37
import jdk.test.lib.Utils;
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    38
import jdk.test.lib.process.ProcessTools;
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    39
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    40
public class TimeZoneDatePermissionCheckRun {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    41
    private static String storePath = Utils.TEST_CLASSES + File.separator
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    42
            + "timezonedatetest.store";
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    43
    private static String jarPath = Utils.TEST_CLASSES + File.separator
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    44
            + "timezonedatetest.jar";
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    45
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    46
    public static void main(String[] args) throws Throwable {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    47
        try {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    48
            //create a test keystore and dummy cert. Note that we use the COMPILEJAVA
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    49
            //as this test is a TimeZone test, it doesn't test keytool
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    50
            runJavaCmd("keytool",
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    51
                    List.of("-genkeypair", "-alias", "testcert", "-keystore",
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    52
                            storePath, "-storepass", "testpass", "-validity",
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    53
                            "360", "-keyalg", "rsa", "-dname",
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    54
                            "cn=Mark Wildebeest, ou=FreeSoft, o=Red Hat, c=NL",
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    55
                            "-keypass", "testpass"));
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    56
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    57
            //create a jar file to sign with the test class in it.
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    58
            runJavaCmd("jar", List.of("cf", jarPath, "-C", Utils.TEST_CLASSES,
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    59
                    "TimeZoneDatePermissionCheck.class"));
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    60
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    61
            //sign it
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    62
            runJavaCmd("jarsigner",
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    63
                    List.of("-keystore", storePath, "-storepass", "testpass",
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    64
                            jarPath, "testcert"));
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    65
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    66
            //run it with the security manager on, plus accesscontroller debugging
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    67
            //will go into infinite recursion trying to get enough permissions for
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    68
            //printing Date of failing certificate unless fix is applied.
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    69
            JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("java");
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    70
            launcher.addToolArg("-Djava.security.manager")
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    71
                    .addToolArg("-Djava.security.debug=access,failure,policy")
55680
cd48f8f260c8 8227289: Enable assertions for some shell to java conversion tests after JDK-8218960
yzhou
parents: 52423
diff changeset
    72
                    .addToolArg("-ea")
cd48f8f260c8 8227289: Enable assertions for some shell to java conversion tests after JDK-8218960
yzhou
parents: 52423
diff changeset
    73
                    .addToolArg("-esa")
52423
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    74
                    .addToolArg("-cp")
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    75
                    .addToolArg(jarPath)
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    76
                    .addToolArg("TimeZoneDatePermissionCheck");
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    77
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    78
            int exitCode = ProcessTools.executeCommand(launcher.getCommand())
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    79
                    .getExitValue();
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    80
            if (exitCode != 0) {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    81
                throw new RuntimeException("Unexpected exit code: " + exitCode);
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    82
            }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    83
        } finally {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    84
            //clean up the test files
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    85
            File storeFile = new File(storePath);
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    86
            if (storeFile.exists()) {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    87
                storeFile.delete();
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    88
            }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    89
            File jarFile = new File(jarPath);
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    90
            if (jarFile.exists()) {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    91
                jarFile.delete();
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    92
            }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    93
        }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    94
    }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    95
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    96
    private static void runJavaCmd(String cmd, List<String> javaParam)
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    97
            throws Throwable{
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    98
        JDKToolLauncher launcher = JDKToolLauncher.create(cmd);
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
    99
        for (String para: javaParam) {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   100
            launcher.addToolArg(para);
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   101
        }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   102
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   103
        System.out.println(launcher.getCommand());
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   104
        int exitCode = ProcessTools.executeCommand(launcher.getCommand())
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   105
                .getExitValue();
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   106
        if (exitCode != 0) {
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   107
            throw new RuntimeException("Unexpected exit code: " + exitCode);
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   108
        }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   109
    }
00db205006c9 8210409: Refactor java.util.TimeZone:i18n shell tests to plain java tests
mli
parents:
diff changeset
   110
}