Skip to content

Commit ed4c20a

Browse files
committed
JDK-8366159: SkippedException is treated as a pass for pkcs11/KeyStore, pkcs11/SecretKeyFactory and pkcs11/SecureRandom
1 parent 0ad919c commit ed4c20a

File tree

5 files changed

+44
-34
lines changed

5 files changed

+44
-34
lines changed

test/jdk/sun/security/pkcs11/KeyStore/CertChainRemoval.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,15 +28,17 @@
2828
* @run testng/othervm CertChainRemoval
2929
*/
3030
import jdk.test.lib.SecurityTools;
31-
import java.io.*;
31+
import java.io.File;
32+
import java.io.FileInputStream;
3233
import java.nio.file.Path;
33-
import java.util.*;
3434

3535
import java.security.Key;
3636
import java.security.KeyStore;
3737
import java.security.KeyStoreException;
3838
import java.security.Provider;
3939
import java.security.cert.Certificate;
40+
import java.util.Arrays;
41+
import java.util.Enumeration;
4042

4143
import jtreg.SkippedException;
4244
import org.testng.SkipException;
@@ -125,8 +127,7 @@ public void main(Provider p) throws Exception {
125127
p11ks.load(null, PKCS11KS.passwd);
126128
printKeyStore("Initial PKCS11 KeyStore: ", p11ks);
127129
} catch (Exception e) {
128-
System.out.println("Skip test, due to " + e);
129-
return;
130+
throw new SkippedException("Skip test, due to " + e);
130131
}
131132

132133
// get the necessary keys from the temp keystore

test/jdk/sun/security/pkcs11/KeyStore/ClientAuth.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -260,8 +260,7 @@ public void main(Provider p) throws Exception {
260260
try {
261261
javax.crypto.Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
262262
} catch (GeneralSecurityException e) {
263-
System.out.println("Not supported by provider, skipping");
264-
return;
263+
throw new SkippedException("Not supported by provider, skipping");
265264
}
266265

267266
this.provider = p;

test/jdk/sun/security/pkcs11/SecretKeyFactory/TestGeneral.java

Lines changed: 26 additions & 17 deletions
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, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,6 +30,8 @@
3030
* @run main/othervm TestGeneral
3131
*/
3232

33+
import jtreg.SkippedException;
34+
3335
import java.security.NoSuchAlgorithmException;
3436
import java.security.Provider;
3537
import java.security.SecureRandom;
@@ -57,8 +59,11 @@ private void test(String algorithm, SecretKey key, Provider p,
5759
try {
5860
skf = SecretKeyFactory.getInstance(algorithm, p);
5961
} catch (NoSuchAlgorithmException e) {
60-
System.out.println("Not supported, skipping: " + e);
61-
return;
62+
throw new SkippedException("[algorithm: " + algorithm +
63+
", key: " + key.getAlgorithm() + "]" +
64+
", provider: " + p.getName() + "]" +
65+
", expectedTestResult: " + expected + "]" +
66+
"Not supported, skipping: " + e);
6267
}
6368
try {
6469
SecretKey key2 = skf.translateKey(key);
@@ -99,21 +104,25 @@ public void main(Provider p) throws Exception {
99104
SecretKey bf_128Key = new SecretKeySpec(rawBytes, 0, 16, "Blowfish");
100105
SecretKey cc20Key = new SecretKeySpec(rawBytes, 0, 32, "ChaCha20");
101106

102-
// fixed key length
103-
test("AES", aes_128Key, p, TestResult.PASS);
104-
test("AES", aes_256Key, p, TestResult.PASS);
105-
test("AES", cc20Key, p, TestResult.FAIL);
107+
try {
108+
// fixed key length
109+
test("AES", aes_128Key, p, TestResult.PASS);
110+
test("AES", aes_256Key, p, TestResult.PASS);
111+
test("AES", cc20Key, p, TestResult.FAIL);
106112

107-
test("ChaCha20", aes_128Key, p, TestResult.FAIL);
108-
test("ChaCha20", aes_256Key, p, TestResult.FAIL);
109-
test("ChaCha20", cc20Key, p, TestResult.PASS);
113+
test("ChaCha20", aes_128Key, p, TestResult.FAIL);
114+
test("ChaCha20", aes_256Key, p, TestResult.FAIL);
115+
test("ChaCha20", cc20Key, p, TestResult.PASS);
110116

111-
// variable key length
112-
// Different PKCS11 impls may have different ranges
113-
// of supported key sizes for variable-key-length
114-
// algorithms.
115-
test("Blowfish", aes_128Key, p, TestResult.FAIL);
116-
test("Blowfish", cc20Key, p, TestResult.FAIL);
117-
test("Blowfish", bf_128Key, p, TestResult.PASS);
117+
// variable key length
118+
// Different PKCS11 impls may have different ranges
119+
// of supported key sizes for variable-key-length
120+
// algorithms.
121+
test("Blowfish", aes_128Key, p, TestResult.FAIL);
122+
test("Blowfish", cc20Key, p, TestResult.FAIL);
123+
test("Blowfish", bf_128Key, p, TestResult.PASS);
124+
} catch (SkippedException skippedException){
125+
throw new SkippedException("One or more tests skipped");
126+
}
118127
}
119128
}

test/jdk/sun/security/pkcs11/SecureRandom/Basic.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,8 @@
3232
* @run main/othervm Basic
3333
*/
3434

35+
import jtreg.SkippedException;
36+
3537
import java.security.NoSuchAlgorithmException;
3638
import java.security.Provider;
3739
import java.security.SecureRandom;
@@ -44,9 +46,8 @@ public void main(Provider p) throws Exception {
4446
try {
4547
random = SecureRandom.getInstance("PKCS11");
4648
} catch (NoSuchAlgorithmException e) {
47-
System.out.println("Provider " + p + " does not support SecureRandom, skipping");
4849
e.printStackTrace();
49-
return;
50+
throw new SkippedException("Provider " + p + " does not support SecureRandom, skipping");
5051
}
5152
byte[] b = new byte[32];
5253
random.nextBytes(b);

test/jdk/sun/security/pkcs11/SecureRandom/TestDeserialization.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,8 @@
2929
* @modules jdk.crypto.cryptoki
3030
*/
3131

32+
import jtreg.SkippedException;
33+
3234
import java.io.ByteArrayInputStream;
3335
import java.io.ByteArrayOutputStream;
3436
import java.io.ObjectInputStream;
@@ -43,18 +45,16 @@ public class TestDeserialization extends PKCS11Test {
4345
public void main(Provider p) throws Exception {
4446
// Skip this test for providers not found by java.security.Security
4547
if (Security.getProvider(p.getName()) != p) {
46-
System.out.println("Skip test for provider " + p.getName());
47-
return;
48+
throw new SkippedException("Skip test for provider " + p.getName());
4849
}
4950
SecureRandom r;
5051
try {
5152
r = SecureRandom.getInstance("PKCS11", p);
5253
System.out.println("SecureRandom instance " + r);
5354
} catch (NoSuchAlgorithmException e) {
54-
System.out.println("Provider " + p +
55-
" does not support SecureRandom, skipping");
5655
e.printStackTrace();
57-
return;
56+
throw new SkippedException("Provider " + p +
57+
" does not support SecureRandom, skipping");
5858
}
5959
r.setSeed(System.currentTimeMillis());
6060
byte[] buf = new byte[16];

0 commit comments

Comments
 (0)