Path: blob/master/test/jdk/tools/jpackage/macosx/SigningPackageTest.java
51315 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.nio.file.Path;24import jdk.jpackage.test.JPackageCommand;25import jdk.jpackage.test.PackageTest;26import jdk.jpackage.test.PackageType;27import jdk.jpackage.test.MacHelper;28import jdk.jpackage.test.Annotations.Test;2930/**31* Tests generation of dmg and pkg with --mac-sign and related arguments.32* Test will generate pkg and verifies its signature. It verifies that dmg33* is not signed, but app image inside dmg is signed. This test requires that34* the machine is configured with test certificate for35* "Developer ID Installer: jpackage.openjdk.java.net" in36* jpackagerTest keychain with37* always allowed access to this keychain for user which runs test.38* note:39* "jpackage.openjdk.java.net" can be over-ridden by systerm property40* "jpackage.mac.signing.key.user.name", and41* "jpackagerTest" can be over-ridden by system property42* "jpackage.mac.signing.keychain"43*/4445/*46* @test47* @summary jpackage with --type pkg,dmg --mac-sign48* @library ../helpers49* @library /test/lib50* @library base51* @key jpackagePlatformPackage52* @build SigningBase53* @build SigningCheck54* @build jtreg.SkippedException55* @build jdk.jpackage.test.*56* @build SigningPackageTest57* @modules jdk.jpackage/jdk.jpackage.internal58* @requires (os.family == "mac")59* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main60* --jpt-run=SigningPackageTest61*/62public class SigningPackageTest {6364private static void verifyPKG(JPackageCommand cmd) {65Path outputBundle = cmd.outputBundle();66SigningBase.verifyPkgutil(outputBundle);67SigningBase.verifySpctl(outputBundle, "install");68}6970private static void verifyDMG(JPackageCommand cmd) {71Path outputBundle = cmd.outputBundle();72SigningBase.verifyCodesign(outputBundle, false);73}7475private static void verifyAppImageInDMG(JPackageCommand cmd) {76MacHelper.withExplodedDmg(cmd, dmgImage -> {77Path launcherPath = dmgImage.resolve(Path.of("Contents", "MacOS", cmd.name()));78SigningBase.verifyCodesign(launcherPath, true);79SigningBase.verifyCodesign(dmgImage, true);80SigningBase.verifySpctl(dmgImage, "exec");81});82}8384@Test85public static void test() throws Exception {86SigningCheck.checkCertificates();8788new PackageTest()89.configureHelloApp()90.forTypes(PackageType.MAC)91.addInitializer(cmd -> {92cmd.addArguments("--mac-sign",93"--mac-signing-key-user-name", SigningBase.DEV_NAME,94"--mac-signing-keychain", SigningBase.KEYCHAIN);95})96.forTypes(PackageType.MAC_PKG)97.addBundleVerifier(SigningPackageTest::verifyPKG)98.forTypes(PackageType.MAC_DMG)99.addBundleVerifier(SigningPackageTest::verifyDMG)100.addBundleVerifier(SigningPackageTest::verifyAppImageInDMG)101.run();102}103}104105106