Skip to content

Commit 166ef5e

Browse files
myankelevwangweij
authored andcommitted
8366159: SkippedException is treated as a pass for pkcs11/KeyStore, pkcs11/SecretKeyFactory and pkcs11/SecureRandom
Reviewed-by: weijun
1 parent bcff857 commit 166ef5e

File tree

5 files changed

+52
-34
lines changed

5 files changed

+52
-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, 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: 34 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,10 +30,14 @@
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;
38+
import java.util.ArrayList;
3639
import java.util.Arrays;
40+
import java.util.List;
3741
import javax.crypto.SecretKeyFactory;
3842
import javax.crypto.SecretKey;
3943
import javax.crypto.spec.SecretKeySpec;
@@ -57,8 +61,11 @@ private void test(String algorithm, SecretKey key, Provider p,
5761
try {
5862
skf = SecretKeyFactory.getInstance(algorithm, p);
5963
} catch (NoSuchAlgorithmException e) {
60-
System.out.println("Not supported, skipping: " + e);
61-
return;
64+
throw new SkippedException("[algorithm: " + algorithm +
65+
", key: " + key.getAlgorithm() + "]" +
66+
", provider: " + p.getName() + "]" +
67+
", expectedTestResult: " + expected + "]" +
68+
"Not supported, skipping: " + e);
6269
}
6370
try {
6471
SecretKey key2 = skf.translateKey(key);
@@ -99,21 +106,31 @@ public void main(Provider p) throws Exception {
99106
SecretKey bf_128Key = new SecretKeySpec(rawBytes, 0, 16, "Blowfish");
100107
SecretKey cc20Key = new SecretKeySpec(rawBytes, 0, 32, "ChaCha20");
101108

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);
109+
List<String> skippedList = new ArrayList<>();
110+
try {
111+
// fixed key length
112+
test("AES", aes_128Key, p, TestResult.PASS);
113+
test("AES", aes_256Key, p, TestResult.PASS);
114+
test("AES", cc20Key, p, TestResult.FAIL);
106115

107-
test("ChaCha20", aes_128Key, p, TestResult.FAIL);
108-
test("ChaCha20", aes_256Key, p, TestResult.FAIL);
109-
test("ChaCha20", cc20Key, p, TestResult.PASS);
116+
test("ChaCha20", aes_128Key, p, TestResult.FAIL);
117+
test("ChaCha20", aes_256Key, p, TestResult.FAIL);
118+
test("ChaCha20", cc20Key, p, TestResult.PASS);
110119

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);
120+
// variable key length
121+
// Different PKCS11 impls may have different ranges
122+
// of supported key sizes for variable-key-length
123+
// algorithms.
124+
test("Blowfish", aes_128Key, p, TestResult.FAIL);
125+
test("Blowfish", cc20Key, p, TestResult.FAIL);
126+
test("Blowfish", bf_128Key, p, TestResult.PASS);
127+
} catch (SkippedException skippedException){
128+
skippedException.printStackTrace();
129+
skippedList.add(skippedException.getMessage());
130+
}
131+
132+
if (!skippedList.isEmpty()) {
133+
throw new SkippedException("One or more tests skipped " + skippedList);
134+
}
118135
}
119136
}

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", e);
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)