Skip to content

Commit 3fa8488

Browse files
committedJan 25, 2024
8313575: Refactor PKCS11Test tests
Backport-of: 7a08e6bdd63c2b4d6283c0c45820024199a4614e
1 parent 0b44cd0 commit 3fa8488

File tree

4 files changed

+4
-98
lines changed

4 files changed

+4
-98
lines changed
 

‎test/jdk/sun/security/pkcs11/PKCS11Test.java

+2-80
Original file line numberDiff line numberDiff line change
@@ -178,45 +178,14 @@ public static void main(PKCS11Test test, String[] args) throws Exception {
178178
Provider[] oldProviders = Security.getProviders();
179179
try {
180180
System.out.println("Beginning test run " + test.getClass().getName() + "...");
181-
boolean skippedDefault = false;
182-
boolean skippedNSS = false;
183-
boolean skippedDeimos = false;
184-
185-
// Use separate try-catch for each test to allow all test run
186-
try {
187-
testDefault(test);
188-
} catch (SkippedException se) {
189-
System.out.println("testDefault: Skipped");
190-
skippedDefault = true;
191-
se.printStackTrace(System.out);
192-
}
193-
194-
try {
195-
testNSS(test);
196-
} catch (SkippedException se) {
197-
System.out.println("testNSS: Skipped");
198-
skippedNSS = true;
199-
se.printStackTrace(System.out);
200-
}
201-
202-
try {
203-
testDeimos(test);
204-
} catch (SkippedException se) {
205-
System.out.println("testDeimos: Skipped");
206-
skippedDeimos = true;
207-
se.printStackTrace(System.out);
208-
}
209-
210-
if (skippedDefault && skippedNSS && skippedDeimos) {
211-
throw new SkippedException("All tests are skipped, check logs");
212-
}
181+
testNSS(test);
213182

214183
} finally {
215184
// NOTE: Do not place a 'return' in any finally block
216185
// as it will suppress exceptions and hide test failures.
217186
Provider[] newProviders = Security.getProviders();
218187
boolean found = true;
219-
// Do not restore providers if nothing changed. This is especailly
188+
// Do not restore providers if nothing changed. This is especially
220189
// useful for ./Provider/Login.sh, where a SecurityManager exists.
221190
if (oldProviders.length == newProviders.length) {
222191
found = false;
@@ -238,51 +207,6 @@ public static void main(PKCS11Test test, String[] args) throws Exception {
238207
}
239208
}
240209

241-
public static void testDeimos(PKCS11Test test) throws Exception {
242-
System.out.println("===> testDeimos: Starting test run");
243-
if ("true".equals(System.getProperty("NO_DEIMOS"))) {
244-
System.out.println("Skip Deimos software as test configured with NO_DEIMOS");
245-
return;
246-
}
247-
248-
if (!new File("/opt/SUNWconn/lib/libpkcs11.so").isFile()) {
249-
throw new SkippedException("testDeimos: \"/opt/SUNWconn/lib/libpkcs11.so\" " +
250-
"file required for Deimos not found");
251-
}
252-
253-
String base = getBase();
254-
String p11config = base + SEP + "nss" + SEP + "p11-deimos.txt";
255-
Provider p = getSunPKCS11(p11config);
256-
test.premain(p);
257-
System.out.println("testDeimos: Completed");
258-
}
259-
260-
// Run test for default configured PKCS11 providers (if any)
261-
public static void testDefault(PKCS11Test test) throws Exception {
262-
System.out.println("===> testDefault: Starting test run");
263-
boolean foundPKCS11 = false;
264-
265-
if ("true".equals(System.getProperty("NO_DEFAULT"))) {
266-
System.out.println("Skip default provider as test configured with NO_DEFAULT");
267-
return;
268-
}
269-
270-
Provider[] providers = Security.getProviders();
271-
for (Provider p : providers) {
272-
if (p.getName().startsWith("SunPKCS11-")) {
273-
foundPKCS11 = true;
274-
test.premain(p);
275-
}
276-
}
277-
278-
if (!foundPKCS11) {
279-
throw new SkippedException("testDefault: Skip default test as SunPKCS11 " +
280-
"provider is not configured");
281-
}
282-
283-
System.out.println("testDefault: Completed");
284-
}
285-
286210
public static String getBase() throws Exception {
287211
if (PKCS11_BASE != null) {
288212
return PKCS11_BASE;
@@ -913,8 +837,6 @@ <T> T[] concat(T[] a, T[] b) {
913837

914838
protected void setCommonSystemProps() {
915839
System.setProperty("java.security.debug", "true");
916-
System.setProperty("NO_DEIMOS", "true");
917-
System.setProperty("NO_DEFAULT", "true");
918840
System.setProperty("CUSTOM_DB_DIR", TEST_CLASSES);
919841
}
920842

‎test/jdk/sun/security/pkcs11/Provider/MultipleLogins.sh

-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ TEST_ARGS="${TESTVMOPTS} -classpath ${TESTCLASSPATH} \
120120
--add-exports jdk.crypto.cryptoki/sun.security.pkcs11=ALL-UNNAMED \
121121
-DCUSTOM_DB_DIR=${TESTCLASSES} \
122122
-DCUSTOM_P11_CONFIG=${TESTSRC}${FS}MultipleLogins-nss.txt \
123-
-DNO_DEFAULT=true \
124-
-DNO_DEIMOS=true \
125123
-Dtest.src=${TESTSRC} \
126124
-Dtest.classes=${TESTCLASSES} \
127125
-Djava.security.debug=${DEBUG}"

‎test/jdk/sun/security/pkcs11/nss/p11-deimos.txt

-14
This file was deleted.

‎test/jdk/sun/security/pkcs11/rsa/TestP11KeyFactoryGetRSAKeySpec.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2021, Amazon.com, Inc. or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -39,7 +39,7 @@
3939
* @library /test/lib ..
4040
* @run main/othervm TestP11KeyFactoryGetRSAKeySpec
4141
* @run main/othervm -Djava.security.manager=allow TestP11KeyFactoryGetRSAKeySpec sm rsakeys.ks.policy
42-
* @run main/othervm -DCUSTOM_P11_CONFIG_NAME=p11-nss-sensitive.txt -DNO_DEIMOS=true -DNO_DEFAULT=true TestP11KeyFactoryGetRSAKeySpec
42+
* @run main/othervm -DCUSTOM_P11_CONFIG_NAME=p11-nss-sensitive.txt TestP11KeyFactoryGetRSAKeySpec
4343
* @modules jdk.crypto.cryptoki
4444
*/
4545

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jan 25, 2024

@openjdk-notifier[bot]
Please sign in to comment.