test/jdk/tools/jpackage/macosx/SigningPackageTest.java
author herrick
Fri, 04 Oct 2019 14:56:02 -0400
branchJDK-8200758-branch
changeset 58464 d82489644b15
child 58648 3bf53ffa9ae7
permissions -rw-r--r--
8215895: Verify and create tests for Mac installer specific signing options Submitted-by: almatvee Reviewed-by: herrick, asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58464
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     1
/*
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     4
 *
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     8
 *
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    13
 * accompanied this code).
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    14
 *
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    18
 *
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    21
 * questions.
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    22
 */
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    23
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    24
import java.nio.file.Path;
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    25
import java.nio.file.Paths;
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    26
import jdk.jpackage.test.*;
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    27
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    28
/**
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    29
 * Tests generation of dmg and pkg with --mac-sign and related arguments. Test will
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    30
 * generate pkg and verifies its signature. It verifies that dmg is not signed, but app
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    31
 * image inside dmg is signed. This test requires that machine is configured with test
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    32
 * certificate for "Developer ID Installer: jpackage.openjdk.java.net" in jpackagerTest
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    33
 * keychain with always allowed access to this keychain for user which runs test.
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    34
 */
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    35
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    36
/*
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    37
 * @test
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    38
 * @summary jpackage with --package-type pkg,dmg --mac-sign
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    39
 * @library ../helpers
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    40
 * @library /test/lib
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    41
 * @library base
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    42
 * @build SigningBase
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    43
 * @build SigningCheck
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    44
 * @build jtreg.SkippedException
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    45
 * @build jdk.jpackage.test.*
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    46
 * @modules jdk.jpackage/jdk.jpackage.internal
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    47
 * @requires (os.family == "mac")
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    48
 * @run main/othervm -Xmx512m SigningPackageTest
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    49
 */
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    50
public class SigningPackageTest {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    51
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    52
    private static void verifyPKG(JPackageCommand cmd) {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    53
        Path outputBundle = cmd.outputBundle();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    54
        SigningBase.verifyPkgutil(outputBundle);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    55
        SigningBase.verifySpctl(outputBundle, "install");
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    56
    }
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    57
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    58
    private static void verifyDMG(JPackageCommand cmd) {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    59
        Path outputBundle = cmd.outputBundle();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    60
        SigningBase.verifyCodesign(outputBundle, false);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    61
    }
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    62
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    63
    private static void verifyAppImageInDMG(JPackageCommand cmd) throws Exception {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    64
        Path disk = Paths.get("/Volumes", cmd.name());
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    65
        try {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    66
            new Executor()
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    67
                    .setExecutable("/usr/bin/hdiutil")
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    68
                    .addArgument("attach").addArgument(cmd.outputBundle())
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    69
                    .execute().assertExitCodeIsZero();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    70
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    71
            Path appImageInDMG = disk.resolve(cmd.name() + ".app");
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    72
            Path launcherPath = appImageInDMG.resolve(Path.of("Contents", "MacOS", cmd.name()));
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    73
            SigningBase.verifyCodesign(launcherPath, true);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    74
            SigningBase.verifyCodesign(appImageInDMG, true);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    75
            SigningBase.verifySpctl(appImageInDMG, "exec");
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    76
        } finally {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    77
            new Executor()
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    78
                    .setExecutable("/usr/bin/hdiutil")
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    79
                    .addArgument("detach").addArgument(disk)
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    80
                    .execute().assertExitCodeIsZero();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    81
        }
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    82
    }
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    83
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    84
    public static void main(String[] args) throws Exception {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    85
        TKit.run(args, () -> {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    86
            SigningCheck.checkCertificates();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    87
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    88
            new PackageTest()
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    89
                    .configureHelloApp()
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    90
                    .forTypes(PackageType.MAC)
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    91
                    .addInitializer(cmd -> {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    92
                        cmd.addArguments("--mac-sign",
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    93
                                "--mac-signing-key-user-name", SigningBase.DEV_NAME,
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    94
                                "--mac-signing-keychain", "jpackagerTest.keychain");
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    95
                    })
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    96
                    .forTypes(PackageType.MAC_PKG)
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    97
                    .addBundleVerifier(cmd -> {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    98
                        verifyPKG(cmd);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    99
                    })
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   100
                    .forTypes(PackageType.MAC_DMG)
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   101
                    .addBundleVerifier(cmd -> {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   102
                        verifyDMG(cmd);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   103
                        verifyAppImageInDMG(cmd);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   104
                    })
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   105
                    .run();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   106
        });
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   107
    }
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
   108
}