test/jdk/tools/jpackage/macosx/SigningPackageTest.java
author herrick
Wed, 16 Oct 2019 10:32:08 -0400
branchJDK-8200758-branch
changeset 58648 3bf53ffa9ae7
parent 58464 d82489644b15
child 58761 88e2753a2334
permissions -rw-r--r--
8232279 : Improve test helpers #2 Submitted-by: asemenyuk Reviewed-by: aherrick, almatvee
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
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    63
    private static void verifyAppImageInDMG(JPackageCommand cmd) {
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    64
        MacHelper.withExplodedDmg(cmd, disk -> {
58464
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    65
            Path appImageInDMG = disk.resolve(cmd.name() + ".app");
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    66
            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
    67
            SigningBase.verifyCodesign(launcherPath, true);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    68
            SigningBase.verifyCodesign(appImageInDMG, true);
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    69
            SigningBase.verifySpctl(appImageInDMG, "exec");
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    70
        });
58464
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    71
    }
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    72
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    73
    public static void main(String[] args) throws Exception {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    74
        TKit.run(args, () -> {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    75
            SigningCheck.checkCertificates();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    76
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    77
            new PackageTest()
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    78
                    .configureHelloApp()
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    79
                    .forTypes(PackageType.MAC)
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    80
                    .addInitializer(cmd -> {
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    81
                        cmd.addArguments("--mac-sign",
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    82
                                "--mac-signing-key-user-name", SigningBase.DEV_NAME,
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    83
                                "--mac-signing-keychain", "jpackagerTest.keychain");
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    84
                    })
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    85
                    .forTypes(PackageType.MAC_PKG)
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    86
                    .addBundleVerifier(SigningPackageTest::verifyPKG)
58464
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    87
                    .forTypes(PackageType.MAC_DMG)
58648
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    88
                    .addBundleVerifier(SigningPackageTest::verifyDMG)
3bf53ffa9ae7 8232279 : Improve test helpers #2
herrick
parents: 58464
diff changeset
    89
                    .addBundleVerifier(SigningPackageTest::verifyAppImageInDMG)
58464
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    90
                    .run();
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    91
        });
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    92
    }
d82489644b15 8215895: Verify and create tests for Mac installer specific signing options
herrick
parents:
diff changeset
    93
}