Skip to content

Commit 1077265

Browse files
author
Alexey Semenyuk
committed
8353321: [macos] ErrorTest.testAppContentWarning test case requires signing environment
Reviewed-by: almatvee
1 parent 52f56e6 commit 1077265

File tree

4 files changed

+116
-38
lines changed

4 files changed

+116
-38
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacSign.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public Builder password(String v) {
287287
}
288288

289289
public Builder addCert(CertificateRequest v) {
290-
certs.add(v);
290+
certs.add(Objects.requireNonNull(v));
291291
return this;
292292
}
293293

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
}

test/jdk/tools/jpackage/macosx/base/SigningBase.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,41 @@
6363

6464
public class SigningBase {
6565

66-
enum StandardKeychain {
67-
MAIN(DEFAULT_KEYCHAIN,
68-
cert().userName(DEV_NAMES[CertIndex.ASCII_INDEX.value()]).create(),
69-
cert().type(CertificateType.INSTALLER).userName(DEV_NAMES[CertIndex.ASCII_INDEX.value()]).create(),
70-
cert().userName(DEV_NAMES[CertIndex.UNICODE_INDEX.value()]).create(),
71-
cert().type(CertificateType.INSTALLER).userName(DEV_NAMES[CertIndex.UNICODE_INDEX.value()]).create());
66+
public enum StandardCertificateRequest {
67+
APP_IMAGE(cert().userName(DEV_NAMES[CertIndex.ASCII_INDEX.value()])),
68+
INSTALLER(cert().type(CertificateType.INSTALLER).userName(DEV_NAMES[CertIndex.ASCII_INDEX.value()])),
69+
APP_IMAGE_UNICODE(cert().userName(DEV_NAMES[CertIndex.UNICODE_INDEX.value()])),
70+
INSTALLER_UNICODE(cert().type(CertificateType.INSTALLER).userName(DEV_NAMES[CertIndex.UNICODE_INDEX.value()]));
71+
72+
StandardCertificateRequest(CertificateRequest.Builder specBuilder) {
73+
this.spec = specBuilder.create();
74+
}
75+
76+
public CertificateRequest spec() {
77+
return spec;
78+
}
79+
80+
private static CertificateRequest.Builder cert() {
81+
return new CertificateRequest.Builder();
82+
}
83+
84+
private final CertificateRequest spec;
85+
}
86+
87+
public enum StandardKeychain {
88+
MAIN(DEFAULT_KEYCHAIN, StandardCertificateRequest.values());
89+
90+
StandardKeychain(String keychainName, StandardCertificateRequest... certs) {
91+
this(keychainName, certs[0].spec(), Stream.of(certs).skip(1).map(StandardCertificateRequest::spec).toArray(CertificateRequest[]::new));
92+
}
7293

7394
StandardKeychain(String keychainName, CertificateRequest cert, CertificateRequest... otherCerts) {
7495
final var builder = keychain(keychainName).addCert(cert);
7596
List.of(otherCerts).forEach(builder::addCert);
7697
this.spec = builder.create();
7798
}
7899

79-
KeychainWithCertsSpec spec() {
100+
public KeychainWithCertsSpec spec() {
80101
return spec;
81102
}
82103

@@ -92,7 +113,7 @@ private static List<KeychainWithCertsSpec> signingEnv() {
92113
return Stream.of(values()).map(StandardKeychain::spec).toList();
93114
}
94115

95-
final KeychainWithCertsSpec spec;
116+
private final KeychainWithCertsSpec spec;
96117
}
97118

98119
public static void setUp() {

test/jdk/tools/jpackage/share/ErrorTest.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import jdk.jpackage.test.CannedFormattedString;
4848
import jdk.jpackage.test.JPackageCommand;
4949
import jdk.jpackage.test.JPackageStringBundle;
50-
import jdk.jpackage.test.MacHelper;
5150
import jdk.jpackage.test.PackageType;
5251
import jdk.jpackage.test.TKit;
5352

@@ -558,34 +557,6 @@ public static Collection<Object[]> testMac() {
558557
return toTestArgs(testCases.stream());
559558
}
560559

561-
@Test(ifOS = MACOS)
562-
public static void testAppContentWarning() {
563-
// --app-content and --type app-image
564-
// Expect `message.codesign.failed.reason.app.content` message in the log.
565-
// This is not a fatal error, just a warning.
566-
// To make jpackage fail, specify invalid signing identity.
567-
final var cmd = JPackageCommand.helloAppImage()
568-
.addArguments("--app-content", TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png"))
569-
.addArguments("--mac-sign", "--mac-app-image-sign-identity", "foo");
570-
571-
final List<CannedFormattedString> expectedStrings = new ArrayList<>();
572-
expectedStrings.add(JPackageStringBundle.MAIN.cannedFormattedString("message.codesign.failed.reason.app.content"));
573-
574-
final var xcodeWarning = JPackageStringBundle.MAIN.cannedFormattedString("message.codesign.failed.reason.xcode.tools");
575-
if (!MacHelper.isXcodeDevToolsInstalled()) {
576-
expectedStrings.add(xcodeWarning);
577-
}
578-
579-
defaultInit(cmd, expectedStrings);
580-
581-
if (MacHelper.isXcodeDevToolsInstalled()) {
582-
// Check there is no warning about missing xcode command line developer tools.
583-
cmd.validateOutput(TKit.assertTextStream(xcodeWarning.getValue()).negate());
584-
}
585-
586-
cmd.execute(1);
587-
}
588-
589560
public static Collection<Object[]> testLinux() {
590561
final List<TestSpec> testCases = new ArrayList<>();
591562

0 commit comments

Comments
 (0)