Skip to content

Commit

Permalink
8313575: Refactor PKCS11Test tests
Browse files Browse the repository at this point in the history
Reviewed-by: valeriep
  • Loading branch information
rhalade committed Sep 5, 2023
1 parent d3ee704 commit 7a08e6b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 98 deletions.
82 changes: 2 additions & 80 deletions test/jdk/sun/security/pkcs11/PKCS11Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,45 +183,14 @@ public static void main(PKCS11Test test, String[] args) throws Exception {
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");
}
testNSS(test);

} 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;
Expand All @@ -243,51 +212,6 @@ public static void main(PKCS11Test test, String[] args) throws Exception {
}
}

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;
Expand Down Expand Up @@ -973,8 +897,6 @@ <T> T[] concat(T[] a, T[] b) {

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);
}

Expand Down
2 changes: 0 additions & 2 deletions test/jdk/sun/security/pkcs11/Provider/MultipleLogins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
14 changes: 0 additions & 14 deletions test/jdk/sun/security/pkcs11/nss/p11-deimos.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -39,7 +39,7 @@
* @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
*/

Expand Down

3 comments on commit 7a08e6b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 7a08e6b Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch MBaesken-backport-7a08e6bd in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 7a08e6bd from the openjdk/jdk repository.

The commit being backported was authored by Rajan Halade on 5 Sep 2023 and was reviewed by Valerie Peng.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:

$ git fetch https://github.com/openjdk-bots/jdk21u.git MBaesken-backport-7a08e6bd:MBaesken-backport-7a08e6bd
$ git checkout MBaesken-backport-7a08e6bd
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git MBaesken-backport-7a08e6bd

Please sign in to comment.