Мне нужно написать контрольный тест Cucumber, чтобы проверить, поддерживает ли веб-сайт двусторонний SSL в Java. Я не уверен, как именно это сделать после бесчисленного прочтения различных статей и ответов. Я создал самозаверяющий сертификат для клиентской части тестового примера и добавляю его в запрос, но я не уверен, как именно проверить, что веб-сайт, к которому я обращаюсь, поддерживает двусторонний SSL. До сих пор это мой код, который я получил, используя различные фрагменты ответов и статей в Интернете.
org.apache.log4j.BasicConfigurator.configure();
try {
String CERT_PASSWORD = "somePass";
KeyStore identityKeyStore = KeyStore.getInstance("jks");
FileInputStream identityKeyStoreFile = new FileInputStream(new File(System.getProperty("user.dir") + "/src/main/resources/files-for-testcases/ultimate.jks"));
identityKeyStore.load(identityKeyStoreFile, CERT_PASSWORD.toCharArray());
SSLContext sslContext = SSLContexts.custom()
// load identity keystore
.loadKeyMaterial(identityKeyStore, CERT_PASSWORD.toCharArray(), (aliases, socket) -> "bddsecurity")
.build();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
new String[]{"TLSv1.2", "TLSv1.1"},
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
CloseableHttpClient client = HttpClients.custom()
.setSSLSocketFactory(sslConnectionSocketFactory)
.build();
// Call a SSL-endpoint
return callEndPoint (client, url);
} catch (Exception ex) {
System.out.println("Boom, we failed: " + ex);
ex.printStackTrace();
}
return 404;
}
private static int callEndPoint (CloseableHttpClient aHTTPClient, String aEndPointURL) {
try {
HttpGet httpGet = new HttpGet(aEndPointURL);
LOG.info("**GET** request Url: " + httpGet.getURI());
HttpResponse response = aHTTPClient.execute(httpGet);
int responseCode = response.getStatusLine().getStatusCode();
LOG.info("Response Code: " + responseCode);
return responseCode;
} catch (Exception ex) {
System.out.println("Boom, we failed: " + ex);
ex.printStackTrace();
}
return 404;
}