1818package org .apache .hadoop .hbase .security ;
1919
2020import static org .apache .hadoop .hbase .ipc .TestProtobufRpcServiceImpl .SERVICE ;
21- import static org .hamcrest .MatcherAssert .assertThat ;
22- import static org .hamcrest .Matchers .instanceOf ;
23- import static org .junit .Assert .assertThrows ;
21+ import static org .junit .jupiter .api .Assertions .assertThrows ;
22+ import static org .junit .jupiter .api .Assertions .fail ;
2423
2524import java .io .File ;
2625import java .io .IOException ;
5049import org .bouncycastle .asn1 .x500 .style .BCStyle ;
5150import org .bouncycastle .jce .provider .BouncyCastleProvider ;
5251import org .bouncycastle .operator .OperatorCreationException ;
53- import org .junit .After ;
54- import org .junit .AfterClass ;
55- import org .junit .Before ;
56- import org .junit .BeforeClass ;
57- import org .junit .Test ;
58- import org .junit .runners .Parameterized ;
52+ import org .junit .jupiter .api .AfterAll ;
53+ import org .junit .jupiter .api .AfterEach ;
54+ import org .junit .jupiter .api .BeforeAll ;
55+ import org .junit .jupiter .api .BeforeEach ;
56+ import org .junit .jupiter .api .TestTemplate ;
5957
58+ import org .apache .hbase .thirdparty .com .google .common .base .Throwables ;
6059import org .apache .hbase .thirdparty .com .google .common .collect .Lists ;
6160import org .apache .hbase .thirdparty .com .google .common .io .Closeables ;
6261import org .apache .hbase .thirdparty .com .google .protobuf .ServiceException ;
@@ -76,24 +75,20 @@ public abstract class AbstractTestMutualTls {
7675 protected RpcServer rpcServer ;
7776
7877 protected RpcClient rpcClient ;
78+
7979 private TestRpcServiceProtos .TestProtobufRpcProto .BlockingInterface stub ;
8080
81- @ Parameterized .Parameter (0 )
82- public X509KeyType caKeyType ;
81+ protected X509KeyType caKeyType ;
82+
83+ protected X509KeyType certKeyType ;
8384
84- @ Parameterized .Parameter (1 )
85- public X509KeyType certKeyType ;
85+ protected String keyPassword ;
8686
87- @ Parameterized .Parameter (2 )
88- public String keyPassword ;
89- @ Parameterized .Parameter (3 )
90- public boolean expectSuccess ;
87+ protected boolean expectSuccess ;
9188
92- @ Parameterized .Parameter (4 )
93- public boolean validateHostnames ;
89+ protected boolean validateHostnames ;
9490
95- @ Parameterized .Parameter (5 )
96- public CertConfig certConfig ;
91+ protected CertConfig certConfig ;
9792
9893 public enum CertConfig {
9994 // For no cert, we literally pass no certificate to the server. It's possible (assuming server
@@ -112,7 +107,17 @@ public enum CertConfig {
112107 VERIFIABLE_CERT_WITH_BAD_HOST
113108 }
114109
115- @ BeforeClass
110+ protected AbstractTestMutualTls (X509KeyType caKeyType , X509KeyType certKeyType ,
111+ String keyPassword , boolean expectSuccess , boolean validateHostnames , CertConfig certConfig ) {
112+ this .caKeyType = caKeyType ;
113+ this .certKeyType = certKeyType ;
114+ this .keyPassword = keyPassword ;
115+ this .expectSuccess = expectSuccess ;
116+ this .validateHostnames = validateHostnames ;
117+ this .certConfig = certConfig ;
118+ }
119+
120+ @ BeforeAll
116121 public static void setUpBeforeClass () throws IOException {
117122 UTIL = new HBaseCommonTestingUtility ();
118123 Security .addProvider (new BouncyCastleProvider ());
@@ -131,7 +136,7 @@ public static void setUpBeforeClass() throws IOException {
131136 PROVIDER = new X509TestContextProvider (conf , DIR );
132137 }
133138
134- @ AfterClass
139+ @ AfterAll
135140 public static void cleanUp () {
136141 Security .removeProvider (BouncyCastleProvider .PROVIDER_NAME );
137142 UTIL .cleanupTestDir ();
@@ -140,7 +145,7 @@ public static void cleanUp() {
140145 protected abstract void initialize (Configuration serverConf , Configuration clientConf )
141146 throws IOException , GeneralSecurityException , OperatorCreationException ;
142147
143- @ Before
148+ @ BeforeEach
144149 public void setUp () throws Exception {
145150 x509TestContext = PROVIDER .get (caKeyType , certKeyType , keyPassword .toCharArray ());
146151 x509TestContext .setConfigurations (KeyStoreFileType .JKS , KeyStoreFileType .JKS );
@@ -192,7 +197,7 @@ protected void handleCertConfig(Configuration confToSet)
192197 }
193198 }
194199
195- @ After
200+ @ AfterEach
196201 public void tearDown () throws IOException {
197202 if (rpcServer != null ) {
198203 rpcServer .stop ();
@@ -208,14 +213,23 @@ public void tearDown() throws IOException {
208213 Security .setProperty ("com.sun.security.enableCRLDP" , Boolean .FALSE .toString ());
209214 }
210215
211- @ Test
216+ @ TestTemplate
212217 public void testClientAuth () throws Exception {
213218 if (expectSuccess ) {
214219 // we expect no exception, so if one is thrown the test will fail
215220 submitRequest ();
216221 } else {
217222 ServiceException se = assertThrows (ServiceException .class , this ::submitRequest );
218- assertThat (se .getCause (), instanceOf (SSLHandshakeException .class ));
223+ // The SSLHandshakeException is encapsulated differently depending on the TLS version
224+ Throwable current = se ;
225+ do {
226+ if (current instanceof SSLHandshakeException ) {
227+ return ;
228+ }
229+ current = current .getCause ();
230+ } while (current != null );
231+ fail ("Exception chain does not include SSLHandshakeException: "
232+ + Throwables .getStackTraceAsString (se ));
219233 }
220234 }
221235
0 commit comments