- }\r
- \r
- @Test\r
- public void validateSslCertClient_withHostAndCertChainValidation() throws Exception {\r
- \r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
- \r
- restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
- restClientBuilder.setConnectTimeoutInMs(12345);\r
- restClientBuilder.setReadTimeoutInMs(54321);\r
- restClientBuilder.setValidateServerCertChain(true);\r
- restClientBuilder.setValidateServerHostname(true);\r
- restClientBuilder.setClientCertPassword("password");\r
- restClientBuilder.setTruststoreFilename("truststore");\r
- \r
- Client client = restClientBuilder.getClient();\r
- \r
- Object sslPropertiesObj = client.getProperties().get(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES);\r
- HTTPSProperties sslProps = null;\r
- if ( sslPropertiesObj instanceof HTTPSProperties ) {\r
- sslProps = (HTTPSProperties)sslPropertiesObj;\r
- assertNull(sslProps.getHostnameVerifier());\r
- } else {\r
- fail("Unexpected value for https properties object");\r
- } }\r
- \r
- @Test (expected=IllegalArgumentException.class)\r
- public void validateSslCertClient_illegalArgumentExceptionWhenTruststoreIsNull() throws Exception {\r
- \r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
- \r
- restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
- restClientBuilder.setConnectTimeoutInMs(12345);\r
- restClientBuilder.setReadTimeoutInMs(54321);\r
- restClientBuilder.setValidateServerCertChain(true);\r
- restClientBuilder.setValidateServerHostname(true);\r
- restClientBuilder.setTruststoreFilename(null);\r
- \r
- /*\r
- * Creating the client in this scenario will cause an IllegalArgumentException caused by the\r
- * truststore being null\r
- */\r
- Client client = restClientBuilder.getClient();\r
- \r
- }\r
- \r
- @Test\r
- public void validateSslProtocolConfiguration() throws Exception {\r
- \r
- RestClientBuilder restClientBuilder = new RestClientBuilder();\r
- assertEquals(RestClientBuilder.DEFAULT_SSL_PROTOCOL, restClientBuilder.getSslProtocol());\r
- \r
- restClientBuilder.setSslProtocol("TLSv1.2");\r
- assertEquals("TLSv1.2", restClientBuilder.getSslProtocol());\r
- \r
- }\r
- \r
+\r
+ @Test\r
+ public void validateNoAuthClientCreation() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.HTTP_NOAUTH);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+\r
+ Client client = restClientBuilder.getClient();\r
+ assertNotNull(client);\r
+ }\r
+\r
+\r
+ @Test\r
+ public void validateUnknownModeCreateNoAuthClient() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+\r
+ Client client = restClientBuilder.getClient();\r
+ assertNotNull(client);\r
+ }\r
+\r
+ @Test\r
+ public void validateBasicAuthSslClient() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+ restClientBuilder.setBasicAuthUsername("username");\r
+ restClientBuilder.setBasicAuthPassword("password");\r
+ restClientBuilder.setTruststoreFilename("truststore");\r
+\r
+ Client client = restClientBuilder.getClient();\r
+ assertNotNull(client.getHostnameVerifier());\r
+ assertEquals("truststore", System.getProperty("javax.net.ssl.trustStore"));\r
+ }\r
+\r
+ @Test(expected = IllegalArgumentException.class)\r
+ public void validateSslCertClient_noHostOrCertChainValidation() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+ restClientBuilder.setValidateServerCertChain(false);\r
+ restClientBuilder.setValidateServerHostname(false);\r
+\r
+ restClientBuilder.getClient();\r
+ }\r
+\r
+ @Test(expected = IllegalArgumentException.class)\r
+ public void validateSslCertClient_hostOnlyValidation() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+ restClientBuilder.setValidateServerCertChain(false);\r
+ restClientBuilder.setValidateServerHostname(true);\r
+\r
+ restClientBuilder.getClient();\r
+\r
+ }\r
+\r
+ @Test\r
+ public void validateSslCertClient_certChainOnlyValidation() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+ restClientBuilder.setValidateServerCertChain(true);\r
+ restClientBuilder.setValidateServerHostname(false);\r
+ restClientBuilder.setTruststoreFilename("truststore");\r
+ restClientBuilder.setClientCertPassword(null);\r
+\r
+ Client client = restClientBuilder.getClient();\r
+ // TODO\r
+ assertNotNull(client.getHostnameVerifier());\r
+ assertEquals("truststore", System.getProperty("javax.net.ssl.trustStore"));\r
+ }\r
+\r
+ @Test\r
+ public void validateSslCertClient_withHostAndCertChainValidation() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+ restClientBuilder.setValidateServerCertChain(true);\r
+ restClientBuilder.setValidateServerHostname(true);\r
+ restClientBuilder.setClientCertPassword("password");\r
+ restClientBuilder.setTruststoreFilename("truststore");\r
+\r
+ Client client = restClientBuilder.getClient();\r
+ // TODO\r
+ assertNull(client.getHostnameVerifier());\r
+ assertEquals("truststore", System.getProperty("javax.net.ssl.trustStore"));\r
+ }\r
+\r
+ @Test(expected = IllegalArgumentException.class)\r
+ public void validateSslCertClient_illegalArgumentExceptionWhenTruststoreIsNull() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+\r
+ restClientBuilder.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);\r
+ restClientBuilder.setConnectTimeoutInMs(12345);\r
+ restClientBuilder.setReadTimeoutInMs(54321);\r
+ restClientBuilder.setValidateServerCertChain(true);\r
+ restClientBuilder.setValidateServerHostname(true);\r
+ restClientBuilder.setTruststoreFilename(null);\r
+\r
+ /*\r
+ * Creating the client in this scenario will cause an IllegalArgumentException caused by the truststore being\r
+ * null\r
+ */\r
+ restClientBuilder.getClient();\r
+\r
+ }\r
+\r
+ @Test\r
+ public void validateSslProtocolConfiguration() throws Exception {\r
+\r
+ RestClientBuilder restClientBuilder = new RestClientBuilder();\r
+ assertEquals(RestClientBuilder.DEFAULT_SSL_PROTOCOL, restClientBuilder.getSslProtocol());\r
+\r
+ restClientBuilder.setSslProtocol("TLSv1.2");\r
+ assertEquals("TLSv1.2", restClientBuilder.getSslProtocol());\r
+\r
+ }\r
+\r