49
49
50
50
import javax .net .ssl .SSLContext ;
51
51
import javax .net .ssl .SSLException ;
52
- import javax .net .ssl .SSLHandshakeException ;
53
52
import javax .ws .rs .GET ;
54
53
import javax .ws .rs .Path ;
55
54
import javax .ws .rs .Produces ;
@@ -73,7 +72,7 @@ public class SslTest {
73
72
74
73
public static final String SSL_PASSWORD = "test1234" ;
75
74
public static final String EXPECTED_200_MSG = "Response status must be 200." ;
76
- public static final int CERT_RELOAD_WAIT_TIME = 20000 ;
75
+ public static final int CERT_RELOAD_WAIT_TIME = 30000 ;
77
76
78
77
@ Before
79
78
public void setUp () throws Exception {
@@ -116,6 +115,15 @@ private void configServerTruststore(Properties props) {
116
115
props .put (RestConfig .SSL_TRUSTSTORE_PASSWORD_CONFIG , SSL_PASSWORD );
117
116
}
118
117
118
+ private void configServerTruststore (Properties props , String password ) {
119
+ props .put (RestConfig .SSL_TRUSTSTORE_LOCATION_CONFIG , trustStore .getAbsolutePath ());
120
+ props .put (RestConfig .SSL_TRUSTSTORE_PASSWORD_CONFIG , password );
121
+ }
122
+
123
+ private void configServerNoTruststorePassword (Properties props ) {
124
+ props .put (RestConfig .SSL_TRUSTSTORE_LOCATION_CONFIG , trustStore .getAbsolutePath ());
125
+ }
126
+
119
127
private void enableSslClientAuth (Properties props ) {
120
128
props .put (RestConfig .SSL_CLIENT_AUTH_CONFIG , true );
121
129
}
@@ -271,6 +279,45 @@ public void testHttpsWithNoClientCertAndNoServerTruststore() throws Exception {
271
279
}
272
280
}
273
281
282
+ @ Test (expected = IOException .class )
283
+ public void testHttpsWithEmptyStringTruststorePassword () throws Exception {
284
+ Properties props = new Properties ();
285
+ String uri = "https://localhost:8080" ;
286
+ props .put (RestConfig .LISTENERS_CONFIG , uri );
287
+ configServerKeystore (props );
288
+ configServerTruststore (props , "" );
289
+ TestRestConfig config = new TestRestConfig (props );
290
+ SslTestApplication app = new SslTestApplication (config );
291
+ try {
292
+ // Empty string is a valid password, but it's not the password the truststore uses
293
+ // The app should fail at startup with:
294
+ // java.io.IOException: Keystore was tampered with, or password was incorrect
295
+ app .start ();
296
+ } finally {
297
+ app .stop ();
298
+ }
299
+ }
300
+
301
+ @ Test
302
+ public void testHttpsWithNoTruststorePassword () throws Exception {
303
+ Properties props = new Properties ();
304
+ String uri = "https://localhost:8080" ;
305
+ props .put (RestConfig .LISTENERS_CONFIG , uri );
306
+ configServerKeystore (props );
307
+ configServerNoTruststorePassword (props );
308
+ TestRestConfig config = new TestRestConfig (props );
309
+ SslTestApplication app = new SslTestApplication (config );
310
+ try {
311
+ // With no password set (null), verification of the truststore is disabled
312
+ app .start ();
313
+
314
+ int statusCode = makeGetRequest (uri + "/test" );
315
+ assertEquals (EXPECTED_200_MSG , 200 , statusCode );
316
+ } finally {
317
+ app .stop ();
318
+ }
319
+ }
320
+
274
321
@ Test (expected = SocketException .class )
275
322
public void testHttpsWithAuthAndBadClientCert () throws Exception {
276
323
Properties props = new Properties ();
0 commit comments