Skip to content

Commit 3c446d7

Browse files
authored
HBASE-30260 Polish X509TestContext to make it more stable (#8426)
Signed-off-by: Xiao Liu <liuxiaocs@apache.org>
1 parent ed4e64b commit 3c446d7

13 files changed

Lines changed: 89 additions & 156 deletions

hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/AbstractTestX509Parameterized.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.hadoop.hbase.io.crypto.tls;
1919

2020
import java.io.File;
21-
import java.io.IOException;
2221
import java.security.Security;
2322
import java.util.ArrayList;
2423
import java.util.List;
@@ -104,7 +103,7 @@ public static void cleanUpBaseClass() {
104103
}
105104

106105
@BeforeEach
107-
public void setUp() throws IOException {
106+
public void setUp() throws Exception {
108107
x509TestContext = PROVIDER.get(caKeyType, certKeyType, keyPassword);
109108
x509TestContext.setConfigurations(KeyStoreFileType.JKS, KeyStoreFileType.JKS);
110109
conf = new Configuration(UTIL.getConfiguration());

hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestBCFKSFileLoader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testLoadKeyStore() throws Exception {
5252
}
5353

5454
@TestTemplate
55-
public void testLoadKeyStoreWithWrongPassword() throws IOException {
55+
public void testLoadKeyStoreWithWrongPassword() throws Exception {
5656
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
5757
assertThrows(IOException.class, () -> {
5858
new BCFKSFileLoader.Builder().setKeyStorePath(path)
@@ -61,7 +61,7 @@ public void testLoadKeyStoreWithWrongPassword() throws IOException {
6161
}
6262

6363
@TestTemplate
64-
public void testLoadKeyStoreWithWrongFilePath() throws IOException {
64+
public void testLoadKeyStoreWithWrongFilePath() throws Exception {
6565
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
6666
assertThrows(IOException.class, () -> {
6767
new BCFKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
@@ -78,7 +78,7 @@ public void testLoadKeyStoreWithNullFilePath() {
7878
}
7979

8080
@TestTemplate
81-
public void testLoadKeyStoreWithWrongFileType() throws IOException {
81+
public void testLoadKeyStoreWithWrongFileType() throws Exception {
8282
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
8383
assertThrows(IOException.class, () -> {
8484
// Trying to load a PEM file with BCFKS loader should fail
@@ -96,7 +96,7 @@ public void testLoadTrustStore() throws Exception {
9696
}
9797

9898
@TestTemplate
99-
public void testLoadTrustStoreWithWrongPassword() throws IOException {
99+
public void testLoadTrustStoreWithWrongPassword() throws Exception {
100100
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
101101
assertThrows(IOException.class, () -> {
102102

@@ -106,7 +106,7 @@ public void testLoadTrustStoreWithWrongPassword() throws IOException {
106106
}
107107

108108
@TestTemplate
109-
public void testLoadTrustStoreWithWrongFilePath() throws IOException {
109+
public void testLoadTrustStoreWithWrongFilePath() throws Exception {
110110
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.BCFKS).getAbsolutePath();
111111
assertThrows(IOException.class, () -> {
112112
new BCFKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")
@@ -123,7 +123,7 @@ public void testLoadTrustStoreWithNullFilePath() {
123123
}
124124

125125
@TestTemplate
126-
public void testLoadTrustStoreWithWrongFileType() throws IOException {
126+
public void testLoadTrustStoreWithWrongFileType() throws Exception {
127127
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
128128
assertThrows(IOException.class, () -> {
129129
// Trying to load a PEM file with BCFKS loader should fail

hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestJKSFileLoader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testLoadKeyStore() throws Exception {
5252
}
5353

5454
@TestTemplate
55-
public void testLoadKeyStoreWithWrongPassword() throws IOException {
55+
public void testLoadKeyStoreWithWrongPassword() throws Exception {
5656
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
5757
assertThrows(IOException.class, () -> {
5858
new JKSFileLoader.Builder().setKeyStorePath(path)
@@ -61,7 +61,7 @@ public void testLoadKeyStoreWithWrongPassword() throws IOException {
6161
}
6262

6363
@TestTemplate
64-
public void testLoadKeyStoreWithWrongFilePath() throws IOException {
64+
public void testLoadKeyStoreWithWrongFilePath() throws Exception {
6565
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
6666
assertThrows(IOException.class, () -> {
6767
new JKSFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
@@ -78,7 +78,7 @@ public void testLoadKeyStoreWithNullFilePath() {
7878
}
7979

8080
@TestTemplate
81-
public void testLoadKeyStoreWithWrongFileType() throws IOException {
81+
public void testLoadKeyStoreWithWrongFileType() throws Exception {
8282
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
8383
assertThrows(IOException.class, () -> {
8484
// Trying to load a PEM file with JKS loader should fail
@@ -96,7 +96,7 @@ public void testLoadTrustStore() throws Exception {
9696
}
9797

9898
@TestTemplate
99-
public void testLoadTrustStoreWithWrongPassword() throws IOException {
99+
public void testLoadTrustStoreWithWrongPassword() throws Exception {
100100
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
101101
assertThrows(IOException.class, () -> {
102102
new JKSFileLoader.Builder().setTrustStorePath(path)
@@ -105,7 +105,7 @@ public void testLoadTrustStoreWithWrongPassword() throws IOException {
105105
}
106106

107107
@TestTemplate
108-
public void testLoadTrustStoreWithWrongFilePath() throws IOException {
108+
public void testLoadTrustStoreWithWrongFilePath() throws Exception {
109109
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
110110
assertThrows(IOException.class, () -> {
111111
new JKSFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")

hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPEMFileLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testLoadKeyStore() throws Exception {
5353
}
5454

5555
@TestTemplate
56-
public void testLoadKeyStoreWithWrongPassword() throws IOException {
56+
public void testLoadKeyStoreWithWrongPassword() throws Exception {
5757
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
5858
assertThrows(Exception.class, () -> {
5959
new PEMFileLoader.Builder().setKeyStorePath(path)
@@ -62,7 +62,7 @@ public void testLoadKeyStoreWithWrongPassword() throws IOException {
6262
}
6363

6464
@TestTemplate
65-
public void testLoadKeyStoreWithWrongFilePath() throws IOException {
65+
public void testLoadKeyStoreWithWrongFilePath() throws Exception {
6666
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
6767
assertThrows(IOException.class, () -> {
6868
new PEMFileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
@@ -79,7 +79,7 @@ public void testLoadKeyStoreWithNullFilePath() {
7979
}
8080

8181
@TestTemplate
82-
public void testLoadKeyStoreWithWrongFileType() throws IOException {
82+
public void testLoadKeyStoreWithWrongFileType() throws Exception {
8383
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS).getAbsolutePath();
8484
assertThrows(KeyStoreException.class, () -> {
8585
// Trying to load a JKS file with PEM loader should fail
@@ -97,7 +97,7 @@ public void testLoadTrustStore() throws Exception {
9797
}
9898

9999
@TestTemplate
100-
public void testLoadTrustStoreWithWrongFilePath() throws IOException {
100+
public void testLoadTrustStoreWithWrongFilePath() throws Exception {
101101
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
102102
assertThrows(IOException.class, () -> {
103103
new PEMFileLoader.Builder().setTrustStorePath(path + ".does_not_exist")

hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestPKCS12FileLoader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testLoadKeyStore() throws Exception {
5252
}
5353

5454
@TestTemplate
55-
public void testLoadKeyStoreWithWrongPassword() throws IOException {
55+
public void testLoadKeyStoreWithWrongPassword() throws Exception {
5656
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
5757
assertThrows(IOException.class, () -> {
5858
new PKCS12FileLoader.Builder().setKeyStorePath(path)
@@ -61,7 +61,7 @@ public void testLoadKeyStoreWithWrongPassword() throws IOException {
6161
}
6262

6363
@TestTemplate
64-
public void testLoadKeyStoreWithWrongFilePath() throws IOException {
64+
public void testLoadKeyStoreWithWrongFilePath() throws Exception {
6565
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
6666
assertThrows(IOException.class, () -> {
6767
new PKCS12FileLoader.Builder().setKeyStorePath(path + ".does_not_exist")
@@ -78,7 +78,7 @@ public void testLoadKeyStoreWithNullFilePath() {
7878
}
7979

8080
@TestTemplate
81-
public void testLoadKeyStoreWithWrongFileType() throws IOException {
81+
public void testLoadKeyStoreWithWrongFileType() throws Exception {
8282
String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM).getAbsolutePath();
8383
assertThrows(IOException.class, () -> {
8484
// Trying to load a PEM file with PKCS12 loader should fail
@@ -96,7 +96,7 @@ public void testLoadTrustStore() throws Exception {
9696
}
9797

9898
@TestTemplate
99-
public void testLoadTrustStoreWithWrongPassword() throws IOException {
99+
public void testLoadTrustStoreWithWrongPassword() throws Exception {
100100
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
101101
assertThrows(IOException.class, () -> {
102102
new PKCS12FileLoader.Builder().setTrustStorePath(path)
@@ -105,7 +105,7 @@ public void testLoadTrustStoreWithWrongPassword() throws IOException {
105105
}
106106

107107
@TestTemplate
108-
public void testLoadTrustStoreWithWrongFilePath() throws IOException {
108+
public void testLoadTrustStoreWithWrongFilePath() throws Exception {
109109
String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PKCS12).getAbsolutePath();
110110
assertThrows(IOException.class, () -> {
111111
new PKCS12FileLoader.Builder().setTrustStorePath(path + ".does_not_exist")

0 commit comments

Comments
 (0)