public void testWithSsl(RestService restService) throws KeyStoreException {
System.setProperty("javax.net.debug", "ssl,handshake");
CookieFilter cookieFilter = new CookieFilter();
RestAssuredConfig sslConfig = SslConfiguration.getP12Config();
Response response = restService.restClient()
.get(spec -> spec
.filter(cookieFilter)
.config(sslConfig)
.log().all(),
AuthConfiguration.AUTH_URL)
.toResponse();
response.then().log().all();
}
public class SslConfiguration {
public static RestAssuredConfig getP12Config() {
return RestAssuredConfig.config()
.sslConfig(new SSLConfig()
.keyStore(
AuthConfiguration.CERTIFICATE_PATH,
AuthConfiguration.CERTIFICATE_PASSWORD)
.keystoreType("PKCS12"))
.redirect(RedirectConfig.redirectConfig()
.followRedirects(true)
.allowCircularRedirects(true)
.maxRedirects(20));
}
}
public class CertificateLoader {
private CertificateLoader() {}
public static KeyStore load() {
try {
InputStream is = Files.newInputStream(
Paths.get(AuthConfiguration.CERTIFICATE_PATH));
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(is, AuthConfiguration.CERTIFICATE_PASSWORD.toCharArray());
return keyStore;
} catch (Exception e) {
throw new AuthException("Не могу загрузить сертификат, ошибка: ", e);
}
}
}