4949
5050import javax .net .ssl .SSLContext ;
5151import javax .net .ssl .SSLException ;
52- import javax .net .ssl .SSLHandshakeException ;
5352import javax .ws .rs .GET ;
5453import javax .ws .rs .Path ;
5554import javax .ws .rs .Produces ;
@@ -73,7 +72,7 @@ public class SslTest {
7372
7473 public static final String SSL_PASSWORD = "test1234" ;
7574 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 ;
7776
7877 @ Before
7978 public void setUp () throws Exception {
@@ -116,6 +115,15 @@ private void configServerTruststore(Properties props) {
116115 props .put (RestConfig .SSL_TRUSTSTORE_PASSWORD_CONFIG , SSL_PASSWORD );
117116 }
118117
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+
119127 private void enableSslClientAuth (Properties props ) {
120128 props .put (RestConfig .SSL_CLIENT_AUTH_CONFIG , true );
121129 }
@@ -271,6 +279,45 @@ public void testHttpsWithNoClientCertAndNoServerTruststore() throws Exception {
271279 }
272280 }
273281
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+
274321 @ Test (expected = SocketException .class )
275322 public void testHttpsWithAuthAndBadClientCert () throws Exception {
276323 Properties props = new Properties ();
0 commit comments