Skip to content

Commit b37d806

Browse files
author
Andy Herrick
committedJun 9, 2020
8246706: [macos] Allow SigningPackageTest to be built with real certificates
Reviewed-by: asemenyuk, almatvee
1 parent 976c469 commit b37d806

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed
 

‎test/jdk/tools/jpackage/macosx/SigningAppImageTest.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@
2929
* Tests generation of app image with --mac-sign and related arguments. Test will
3030
* generate app image and verify signature of main launcher and app bundle itself.
3131
* This test requires that machine is configured with test certificate for
32-
* "Developer ID Application: jpackage.openjdk.java.net" in jpackagerTest keychain with
33-
* always allowed access to this keychain for user which runs test.
32+
* "Developer ID Application: jpackage.openjdk.java.net" or alternately
33+
* "Developer ID Application: " + name specified by system property:
34+
* "jpackage.mac.signing.key.user.name"
35+
* in the jpackagerTest keychain (or alternately the keychain specified with
36+
* the system property "jpackage.mac.signing.keychain".
37+
* If this certificate is self-signed, it must have be set to
38+
* always allowe access to this keychain" for user which runs test.
39+
* (If cert is real (not self signed), the do not set trust to allow.)
3440
*/
3541

3642
/*
@@ -56,7 +62,7 @@ public static void main(String[] args) throws Exception {
5662
JPackageCommand cmd = JPackageCommand.helloAppImage();
5763
cmd.addArguments("--mac-sign", "--mac-signing-key-user-name",
5864
SigningBase.DEV_NAME, "--mac-signing-keychain",
59-
"jpackagerTest.keychain");
65+
SigningBase.KEYCHAIN);
6066
cmd.executeAndAssertHelloAppImageCreated();
6167

6268
Path launcherPath = cmd.appLauncherPath();

‎test/jdk/tools/jpackage/macosx/SigningPackageTest.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@
2626
import jdk.jpackage.test.*;
2727

2828
/**
29-
* Tests generation of dmg and pkg with --mac-sign and related arguments. Test will
30-
* generate pkg and verifies its signature. It verifies that dmg is not signed, but app
31-
* image inside dmg is signed. This test requires that machine is configured with test
32-
* certificate for "Developer ID Installer: jpackage.openjdk.java.net" in jpackagerTest
33-
* keychain with always allowed access to this keychain for user which runs test.
29+
* Tests generation of dmg and pkg with --mac-sign and related arguments.
30+
* Test will generate pkg and verifies its signature. It verifies that dmg
31+
* is not signed, but app image inside dmg is signed. This test requires that
32+
* the machine is configured with test certificate for
33+
* "Developer ID Installer: jpackage.openjdk.java.net" in
34+
* jpackagerTest keychain with
35+
* always allowed access to this keychain for user which runs test.
36+
* note:
37+
* "jpackage.openjdk.java.net" can be over-ridden by systerm property
38+
* "jpackage.mac.signing.key.user.name", and
39+
* "jpackagerTest" can be over-ridden by system property
40+
* "jpackage.mac.signing.keychain"
3441
*/
3542

3643
/*
@@ -80,7 +87,7 @@ public static void main(String[] args) throws Exception {
8087
.addInitializer(cmd -> {
8188
cmd.addArguments("--mac-sign",
8289
"--mac-signing-key-user-name", SigningBase.DEV_NAME,
83-
"--mac-signing-keychain", "jpackagerTest.keychain");
90+
"--mac-signing-keychain", SigningBase.KEYCHAIN);
8491
})
8592
.forTypes(PackageType.MAC_PKG)
8693
.addBundleVerifier(SigningPackageTest::verifyPKG)

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

+14-10
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,22 @@
3030

3131
public class SigningBase {
3232

33-
public static String DEV_NAME = "jpackage.openjdk.java.net";
34-
public static String APP_CERT
35-
= "Developer ID Application: " + DEV_NAME;
36-
public static String INSTALLER_CERT
37-
= "Developer ID Installer: " + DEV_NAME;
38-
public static String KEYCHAIN = "jpackagerTest.keychain";
33+
public static String DEV_NAME;
34+
public static String APP_CERT;
35+
public static String INSTALLER_CERT;
36+
public static String KEYCHAIN;
37+
static {
38+
String value = System.getProperty("jpackage.mac.signing.key.user.name");
39+
DEV_NAME = (value == null) ? "jpackage.openjdk.java.net" : value;
40+
APP_CERT = "Developer ID Application: " + DEV_NAME;
41+
INSTALLER_CERT = "Developer ID Installer: " + DEV_NAME;
42+
value = System.getProperty("jpackage.mac.signing.keychain");
43+
KEYCHAIN = (value == null) ? "jpackagerTest.keychain" : value;
44+
}
3945

4046
private static void checkString(List<String> result, String lookupString) {
4147
TKit.assertTextStream(lookupString).predicate(
42-
(line, what) -> line.trim().equals(what)).apply(result.stream());
48+
(line, what) -> line.trim().contains(what)).apply(result.stream());
4349
}
4450

4551
private static List<String> codesignResult(Path target, boolean signed) {
@@ -92,8 +98,6 @@ private static void verifySpctlResult(List<String> output, Path target,
9298
if (exitCode == 0) {
9399
lookupString = target.toString() + ": accepted";
94100
checkString(output, lookupString);
95-
lookupString = "source=" + DEV_NAME;
96-
checkString(output, lookupString);
97101
} else if (exitCode == 3) {
98102
// allow failure purely for not being notarized
99103
lookupString = target.toString() + ": rejected";
@@ -120,7 +124,7 @@ private static List<String> pkgutilResult(Path target) {
120124

121125
private static void verifyPkgutilResult(List<String> result) {
122126
result.stream().forEachOrdered(TKit::trace);
123-
String lookupString = "Status: signed by a certificate trusted for current user";
127+
String lookupString = "Status: signed by";
124128
checkString(result, lookupString);
125129
lookupString = "1. " + INSTALLER_CERT;
126130
checkString(result, lookupString);

0 commit comments

Comments
 (0)
Please sign in to comment.