|
39 | 39 | import jdk.jpackage.test.MacHelper; |
40 | 40 | import jdk.jpackage.test.MacSign; |
41 | 41 | import jdk.jpackage.test.MacSign.CertificateRequest; |
| 42 | +import jdk.jpackage.test.MacSign.CertificateType; |
42 | 43 | import jdk.jpackage.test.MacSignVerify; |
43 | 44 | import jdk.jpackage.test.PackageType; |
44 | 45 | import jdk.jpackage.test.TKit; |
@@ -155,30 +156,33 @@ public static void testExpiredCertificate(PackageType type, SignOption... option |
155 | 156 | } |
156 | 157 |
|
157 | 158 | @Test |
158 | | - // Case "--mac-signing-key-user-name": jpackage selects first certificate |
159 | | - // found with warning message. Certificate hash is pass to "codesign" in this |
160 | | - // case. |
161 | | - @Parameter({"IMAGE", "0", "GOOD_SIGNING_KEY_USER_NAME"}) |
162 | | - @Parameter({"MAC_DMG", "0", "GOOD_SIGNING_KEY_USER_NAME"}) |
163 | | - @Parameter({"MAC_PKG", "0", "GOOD_SIGNING_KEY_USER_NAME_PKG", "GOOD_SIGNING_KEY_USER_NAME"}) |
164 | | - |
165 | | - // Case "--mac-app-image-sign-identity": sign identity will be pass to |
166 | | - // "codesign" and "codesign" should fail due to multiple certificates with |
167 | | - // same common name found. |
168 | | - @Parameter({"IMAGE", "1", "GOOD_CODESIGN_SIGN_IDENTITY"}) |
169 | | - @Parameter({"MAC_PKG", "1", "GOOD_CODESIGN_SIGN_IDENTITY", "GOOD_PKG_SIGN_IDENTITY"}) |
170 | | - @Parameter({"MAC_PKG", "1", "GOOD_PKG_SIGN_IDENTITY"}) |
171 | | - public static void testMultipleCertificates(PackageType type, int jpackageExitCode, SignOption... options) { |
| 159 | + @Parameter({"IMAGE", "GOOD_SIGNING_KEY_USER_NAME"}) |
| 160 | + @Parameter({"MAC_DMG", "GOOD_SIGNING_KEY_USER_NAME"}) |
| 161 | + @Parameter({"MAC_PKG", "GOOD_SIGNING_KEY_USER_NAME_PKG", "GOOD_SIGNING_KEY_USER_NAME"}) |
| 162 | + @Parameter({"IMAGE", "GOOD_CODESIGN_SIGN_IDENTITY"}) |
| 163 | + @Parameter({"MAC_PKG", "GOOD_CODESIGN_SIGN_IDENTITY", "GOOD_PKG_SIGN_IDENTITY"}) |
| 164 | + @Parameter({"MAC_PKG", "GOOD_PKG_SIGN_IDENTITY"}) |
| 165 | + public static void testMultipleCertificates(PackageType type, SignOption... options) { |
172 | 166 |
|
173 | 167 | MacSign.withKeychain(keychain -> { |
174 | 168 | final var cmd = MacHelper.useKeychain(JPackageCommand.helloAppImage(), keychain) |
175 | 169 | .ignoreDefaultVerbose(true) |
176 | 170 | .addArguments(Stream.of(options).map(SignOption::args).flatMap(List::stream).toList()) |
177 | 171 | .setPackageType(type); |
178 | 172 |
|
179 | | - SignOption.configureOutputValidation(cmd, List.of(options), opt -> { |
| 173 | + Predicate<SignOption> filter = opt -> { |
| 174 | + if (type == PackageType.MAC_PKG && options.length > 1) { |
| 175 | + // Only the first error will be reported and it should always be |
| 176 | + // for the app image signing, not for the PKG signing. |
| 177 | + return opt.identityType() == CertificateType.CODE_SIGN; |
| 178 | + } else { |
| 179 | + return true; |
| 180 | + } |
| 181 | + }; |
| 182 | + |
| 183 | + SignOption.configureOutputValidation(cmd, Stream.of(options).filter(filter).toList(), opt -> { |
180 | 184 | return JPackageStringBundle.MAIN.cannedFormattedString("error.multiple.certs.found", opt.identityName(), keychain.name()); |
181 | | - }).execute(jpackageExitCode); |
| 185 | + }).execute(1); |
182 | 186 | }, MacSign.Keychain.UsageBuilder::addToSearchList, SigningBase.StandardKeychain.DUPLICATE.keychain()); |
183 | 187 | } |
184 | 188 |
|
@@ -244,6 +248,10 @@ String identityName() { |
244 | 248 | return cert.name(); |
245 | 249 | } |
246 | 250 |
|
| 251 | + CertificateType identityType() { |
| 252 | + return cert.type(); |
| 253 | + } |
| 254 | + |
247 | 255 | List<String> args() { |
248 | 256 | return List.of(option, shortName ? cert.shortName() : cert.name()); |
249 | 257 | } |
|
0 commit comments