|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import static jdk.jpackage.internal.util.PListWriter.writeDict; |
| 25 | +import static jdk.jpackage.internal.util.PListWriter.writePList; |
| 26 | +import static jdk.jpackage.internal.util.PListWriter.writeBoolean; |
| 27 | +import static jdk.jpackage.internal.util.XmlUtils.createXml; |
| 28 | +import static jdk.jpackage.internal.util.XmlUtils.toXmlConsumer; |
| 29 | + |
| 30 | +import java.io.IOException; |
| 31 | +import java.nio.file.Path; |
| 32 | +import java.util.Date; |
| 33 | + |
| 34 | +import jdk.jpackage.test.JPackageCommand; |
| 35 | +import jdk.jpackage.test.TKit; |
| 36 | +import jdk.jpackage.test.Annotations.Test; |
| 37 | +import jdk.jpackage.test.Annotations.Parameter; |
| 38 | + |
| 39 | +/* |
| 40 | + * Test generates signed app-image with custom entitlements file from the |
| 41 | + * "--mac-entitlements" parameter and the resource directory. Following cases |
| 42 | + * are covered: |
| 43 | + * - Custom entitlements file in the resource directory. |
| 44 | + * - Custom entitlements file specified with the "--mac-entitlements" parameter. |
| 45 | + * - Custom entitlements file in the resource directory and specified with the |
| 46 | + * "--mac-entitlements" parameter. |
| 47 | + */ |
| 48 | + |
| 49 | +/* |
| 50 | + * @test |
| 51 | + * @summary jpackage with --type app-image "--mac-entitlements" parameter |
| 52 | + * @library /test/jdk/tools/jpackage/helpers |
| 53 | + * @library base |
| 54 | + * @build SigningBase |
| 55 | + * @build jdk.jpackage.test.* |
| 56 | + * @build EntitlementsTest |
| 57 | + * @requires (jpackage.test.MacSignTests == "run") |
| 58 | + * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main |
| 59 | + * --jpt-run=EntitlementsTest |
| 60 | + * --jpt-before-run=SigningBase.verifySignTestEnvReady |
| 61 | + */ |
| 62 | +public class EntitlementsTest { |
| 63 | + |
| 64 | + void createEntitlementsFile(Path file, boolean microphone) throws IOException { |
| 65 | + createXml(file, xml -> { |
| 66 | + writePList(xml, toXmlConsumer(() -> { |
| 67 | + writeDict(xml, toXmlConsumer(() -> { |
| 68 | + writeBoolean(xml, "com.apple.security.cs.allow-jit", true); |
| 69 | + writeBoolean(xml, "com.apple.security.cs.allow-unsigned-executable-memory", true); |
| 70 | + writeBoolean(xml, "com.apple.security.cs.disable-library-validation", true); |
| 71 | + writeBoolean(xml, "com.apple.security.cs.allow-dyld-environment-variables", true); |
| 72 | + writeBoolean(xml, "com.apple.security.cs.debugger", true); |
| 73 | + writeBoolean(xml, "com.apple.security.device.audio-input", true); |
| 74 | + writeBoolean(xml, "com.apple.security.device.microphone", microphone); |
| 75 | + })); |
| 76 | + })); |
| 77 | + }); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + // ({"--mac-app-store", doMacEntitlements", "doResources"}) |
| 82 | + @Parameter({"false", "true", "false"}) |
| 83 | + @Parameter({"false", "false", "true"}) |
| 84 | + @Parameter({"false", "true", "true"}) |
| 85 | + @Parameter({"true", "true", "false"}) |
| 86 | + @Parameter({"true", "false", "true"}) |
| 87 | + @Parameter({"true", "true", "true"}) |
| 88 | + public void test(boolean appStore, boolean doMacEntitlements, boolean doResources) throws Exception { |
| 89 | + final Path macEntitlementsFile; |
| 90 | + final Path resourcesDir; |
| 91 | + |
| 92 | + if (doMacEntitlements) { |
| 93 | + macEntitlementsFile = TKit.createTempFile("EntitlementsTest.plist"); |
| 94 | + createEntitlementsFile(macEntitlementsFile, true); |
| 95 | + } else { |
| 96 | + macEntitlementsFile = null; |
| 97 | + } |
| 98 | + |
| 99 | + if (doResources) { |
| 100 | + resourcesDir = TKit.createTempDirectory("resources"); |
| 101 | + createEntitlementsFile(resourcesDir.resolve("EntitlementsTest.entitlements"), false); |
| 102 | + } else { |
| 103 | + resourcesDir = null; |
| 104 | + } |
| 105 | + |
| 106 | + JPackageCommand cmd = JPackageCommand.helloAppImage() |
| 107 | + .addArguments("--mac-sign", "--mac-signing-keychain", |
| 108 | + SigningBase.getKeyChain(), "--mac-app-image-sign-identity", |
| 109 | + SigningBase.getAppCert(SigningBase.CertIndex.ASCII_INDEX.value())); |
| 110 | + if (appStore) { |
| 111 | + cmd.addArguments("--mac-app-store"); |
| 112 | + } |
| 113 | + if (doMacEntitlements) { |
| 114 | + cmd.addArguments("--mac-entitlements", |
| 115 | + macEntitlementsFile.toAbsolutePath().toString()); |
| 116 | + } |
| 117 | + if (doResources) { |
| 118 | + cmd.addArguments("--resource-dir", |
| 119 | + resourcesDir.toAbsolutePath().toString()); |
| 120 | + } |
| 121 | + |
| 122 | + cmd.executeAndAssertHelloAppImageCreated(); |
| 123 | + } |
| 124 | +} |
0 commit comments