8313575: Refactor PKCS11Test tests
Reviewed-by: valeriep
This commit is contained in:
parent
d3ee704b28
commit
7a08e6bdd6
@ -183,45 +183,14 @@ public abstract class PKCS11Test {
|
||||
Provider[] oldProviders = Security.getProviders();
|
||||
try {
|
||||
System.out.println("Beginning test run " + test.getClass().getName() + "...");
|
||||
boolean skippedDefault = false;
|
||||
boolean skippedNSS = false;
|
||||
boolean skippedDeimos = false;
|
||||
|
||||
// Use separate try-catch for each test to allow all test run
|
||||
try {
|
||||
testDefault(test);
|
||||
} catch (SkippedException se) {
|
||||
System.out.println("testDefault: Skipped");
|
||||
skippedDefault = true;
|
||||
se.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
try {
|
||||
testNSS(test);
|
||||
} catch (SkippedException se) {
|
||||
System.out.println("testNSS: Skipped");
|
||||
skippedNSS = true;
|
||||
se.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
try {
|
||||
testDeimos(test);
|
||||
} catch (SkippedException se) {
|
||||
System.out.println("testDeimos: Skipped");
|
||||
skippedDeimos = true;
|
||||
se.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
if (skippedDefault && skippedNSS && skippedDeimos) {
|
||||
throw new SkippedException("All tests are skipped, check logs");
|
||||
}
|
||||
|
||||
} finally {
|
||||
// NOTE: Do not place a 'return' in any finally block
|
||||
// as it will suppress exceptions and hide test failures.
|
||||
Provider[] newProviders = Security.getProviders();
|
||||
boolean found = true;
|
||||
// Do not restore providers if nothing changed. This is especailly
|
||||
// Do not restore providers if nothing changed. This is especially
|
||||
// useful for ./Provider/Login.sh, where a SecurityManager exists.
|
||||
if (oldProviders.length == newProviders.length) {
|
||||
found = false;
|
||||
@ -243,51 +212,6 @@ public abstract class PKCS11Test {
|
||||
}
|
||||
}
|
||||
|
||||
public static void testDeimos(PKCS11Test test) throws Exception {
|
||||
System.out.println("===> testDeimos: Starting test run");
|
||||
if ("true".equals(System.getProperty("NO_DEIMOS"))) {
|
||||
System.out.println("Skip Deimos software as test configured with NO_DEIMOS");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!new File("/opt/SUNWconn/lib/libpkcs11.so").isFile()) {
|
||||
throw new SkippedException("testDeimos: \"/opt/SUNWconn/lib/libpkcs11.so\" " +
|
||||
"file required for Deimos not found");
|
||||
}
|
||||
|
||||
String base = getBase();
|
||||
String p11config = base + SEP + "nss" + SEP + "p11-deimos.txt";
|
||||
Provider p = getSunPKCS11(p11config);
|
||||
test.premain(p);
|
||||
System.out.println("testDeimos: Completed");
|
||||
}
|
||||
|
||||
// Run test for default configured PKCS11 providers (if any)
|
||||
public static void testDefault(PKCS11Test test) throws Exception {
|
||||
System.out.println("===> testDefault: Starting test run");
|
||||
boolean foundPKCS11 = false;
|
||||
|
||||
if ("true".equals(System.getProperty("NO_DEFAULT"))) {
|
||||
System.out.println("Skip default provider as test configured with NO_DEFAULT");
|
||||
return;
|
||||
}
|
||||
|
||||
Provider[] providers = Security.getProviders();
|
||||
for (Provider p : providers) {
|
||||
if (p.getName().startsWith("SunPKCS11-")) {
|
||||
foundPKCS11 = true;
|
||||
test.premain(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundPKCS11) {
|
||||
throw new SkippedException("testDefault: Skip default test as SunPKCS11 " +
|
||||
"provider is not configured");
|
||||
}
|
||||
|
||||
System.out.println("testDefault: Completed");
|
||||
}
|
||||
|
||||
public static String getBase() throws Exception {
|
||||
if (PKCS11_BASE != null) {
|
||||
return PKCS11_BASE;
|
||||
@ -973,8 +897,6 @@ public abstract class PKCS11Test {
|
||||
|
||||
protected void setCommonSystemProps() {
|
||||
System.setProperty("java.security.debug", "true");
|
||||
System.setProperty("NO_DEIMOS", "true");
|
||||
System.setProperty("NO_DEFAULT", "true");
|
||||
System.setProperty("CUSTOM_DB_DIR", TEST_CLASSES);
|
||||
}
|
||||
|
||||
|
@ -120,8 +120,6 @@ TEST_ARGS="${TESTVMOPTS} -classpath ${TESTCLASSPATH} \
|
||||
--add-exports jdk.crypto.cryptoki/sun.security.pkcs11=ALL-UNNAMED \
|
||||
-DCUSTOM_DB_DIR=${TESTCLASSES} \
|
||||
-DCUSTOM_P11_CONFIG=${TESTSRC}${FS}MultipleLogins-nss.txt \
|
||||
-DNO_DEFAULT=true \
|
||||
-DNO_DEIMOS=true \
|
||||
-Dtest.src=${TESTSRC} \
|
||||
-Dtest.classes=${TESTCLASSES} \
|
||||
-Djava.security.debug=${DEBUG}"
|
||||
|
@ -1,14 +0,0 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
# Configuration to run unit tests with the Deimos (SCA1000) software
|
||||
#
|
||||
|
||||
name = Deimos
|
||||
|
||||
#showInfo = true
|
||||
|
||||
library = /opt/SUNWconn/lib/libpkcs11.so
|
||||
|
||||
attributes = compatibility
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -39,7 +39,7 @@ import java.security.spec.*;
|
||||
* @library /test/lib ..
|
||||
* @run main/othervm TestP11KeyFactoryGetRSAKeySpec
|
||||
* @run main/othervm -Djava.security.manager=allow TestP11KeyFactoryGetRSAKeySpec sm rsakeys.ks.policy
|
||||
* @run main/othervm -DCUSTOM_P11_CONFIG_NAME=p11-nss-sensitive.txt -DNO_DEIMOS=true -DNO_DEFAULT=true TestP11KeyFactoryGetRSAKeySpec
|
||||
* @run main/othervm -DCUSTOM_P11_CONFIG_NAME=p11-nss-sensitive.txt TestP11KeyFactoryGetRSAKeySpec
|
||||
* @modules jdk.crypto.cryptoki
|
||||
*/
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user