|
| 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 java.io.IOException; |
| 25 | +import java.nio.file.Files; |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.List; |
| 28 | +import jdk.jpackage.test.Annotations.Test; |
| 29 | +import jdk.jpackage.test.CannedFormattedString; |
| 30 | +import jdk.jpackage.test.JPackageCommand; |
| 31 | +import jdk.jpackage.test.JPackageStringBundle; |
| 32 | +import jdk.jpackage.test.MacHelper; |
| 33 | +import jdk.jpackage.test.TKit; |
| 34 | + |
| 35 | +/* |
| 36 | + * @test |
| 37 | + * @summary jpackage with --mac-sign |
| 38 | + * @library /test/jdk/tools/jpackage/helpers |
| 39 | + * @library base |
| 40 | + * @build SigningBase |
| 41 | + * @build jdk.jpackage.test.* |
| 42 | + * @build MacSignTest |
| 43 | + * @requires (jpackage.test.MacSignTests == "run") |
| 44 | + * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main |
| 45 | + * --jpt-run=MacSignTest |
| 46 | + * --jpt-before-run=SigningBase.verifySignTestEnvReady |
| 47 | + */ |
| 48 | +public class MacSignTest { |
| 49 | + |
| 50 | + @Test |
| 51 | + public static void testAppContentWarning() throws IOException { |
| 52 | + |
| 53 | + // Create app content directory with the name known to fail signing. |
| 54 | + // This will trigger jpackage exit with status code "1". |
| 55 | + final var appContent = TKit.createTempDirectory("app-content").resolve("foo.1"); |
| 56 | + Files.createDirectory(appContent); |
| 57 | + Files.createFile(appContent.resolve("file")); |
| 58 | + |
| 59 | + final List<CannedFormattedString> expectedStrings = new ArrayList<>(); |
| 60 | + expectedStrings.add(JPackageStringBundle.MAIN.cannedFormattedString("message.codesign.failed.reason.app.content")); |
| 61 | + |
| 62 | + final var xcodeWarning = JPackageStringBundle.MAIN.cannedFormattedString("message.codesign.failed.reason.xcode.tools"); |
| 63 | + if (!MacHelper.isXcodeDevToolsInstalled()) { |
| 64 | + expectedStrings.add(xcodeWarning); |
| 65 | + } |
| 66 | + |
| 67 | + // --app-content and --type app-image |
| 68 | + // Expect `message.codesign.failed.reason.app.content` message in the log. |
| 69 | + // This is not a fatal error, just a warning. |
| 70 | + // To make jpackage fail, specify bad additional content. |
| 71 | + final var cmd = JPackageCommand.helloAppImage() |
| 72 | + .ignoreDefaultVerbose(true) |
| 73 | + .validateOutput(expectedStrings.toArray(CannedFormattedString[]::new)) |
| 74 | + .addArguments("--app-content", appContent) |
| 75 | + .addArguments("--mac-sign") |
| 76 | + .addArguments("--mac-signing-keychain", SigningBase.StandardKeychain.MAIN.spec().keychain().name()) |
| 77 | + .addArguments("--mac-app-image-sign-identity", SigningBase.StandardCertificateRequest.APP_IMAGE.spec().name()); |
| 78 | + |
| 79 | + if (MacHelper.isXcodeDevToolsInstalled()) { |
| 80 | + // Check there is no warning about missing xcode command line developer tools. |
| 81 | + cmd.validateOutput(TKit.assertTextStream(xcodeWarning.getValue()).negate()); |
| 82 | + } |
| 83 | + |
| 84 | + cmd.execute(1); |
| 85 | + } |
| 86 | +} |
0 commit comments