use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.
the class SSLFactoryTestHelper method createSSLFactory.
public static SSLFactory createSSLFactory(boolean oneWayAuthenticationEnabled, boolean twoWayAuthenticationEnabled) {
String keyStorePath = "keystores-for-unit-tests/identity.jks";
String keyStorePassword = "secret";
String trustStorePath = "keystores-for-unit-tests/truststore.jks";
String trustStorePassword = "secret";
SSLFactory.Builder sslFactoryBuilder = SSLFactory.builder();
if (oneWayAuthenticationEnabled) {
sslFactoryBuilder.withTrustMaterial(trustStorePath, trustStorePassword.toCharArray()).withHostnameVerifier(new DefaultHostnameVerifier());
}
if (twoWayAuthenticationEnabled) {
sslFactoryBuilder.withIdentityMaterial(keyStorePath, keyStorePassword.toCharArray()).withTrustMaterial(trustStorePath, trustStorePassword.toCharArray()).withHostnameVerifier(new DefaultHostnameVerifier());
}
return Mockito.spy(sslFactoryBuilder.build());
}
use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.
the class OldJdkHttpClientServiceShould method throwClientExceptionWhenProvidedUrlDoesNotContainHttpOrHttps.
@Test
void throwClientExceptionWhenProvidedUrlDoesNotContainHttpOrHttps() {
SSLFactory sslFactory = mock(SSLFactory.class);
OldJdkHttpClientService victim = spy(new OldJdkHttpClientService(sslFactory));
assertThatThrownBy(() -> victim.executeRequest("www.google.com")).isInstanceOf(ClientException.class).hasMessage("Could not create a http client for one of these reasons: invalid url, security is enable while using an url with http or security is disable while using an url with https");
}
use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.
the class ClientConfigShould method createApache5HttpClient.
@Test
void createApache5HttpClient() {
SSLFactory sslFactory = createSSLFactory(false, true);
org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient = victim.apache5HttpClient(sslFactory);
assertThat(httpClient).isNotNull();
verify(sslFactory, times(1)).getSslContext();
verify(sslFactory, times(1)).getHostnameVerifier();
verify(sslFactory, times(2)).getSslParameters();
}
use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.
the class ClientConfigShould method createApacheHttpClient.
@Test
void createApacheHttpClient() {
SSLFactory sslFactory = createSSLFactory(false, true);
CloseableHttpClient httpClient = victim.apacheHttpClient(sslFactory);
assertThat(httpClient).isNotNull();
verify(sslFactory, times(1)).getSslContext();
verify(sslFactory, times(1)).getHostnameVerifier();
}
use of nl.altindag.ssl.SSLFactory in project mutual-tls-ssl by Hakky54.
the class ClientConfigShould method createGoogleHttpClient.
@Test
void createGoogleHttpClient() throws IOException {
SSLFactory sslFactory = createSSLFactory(false, true);
HttpTransport httpTransport = victim.googleHttpClient(sslFactory);
assertThat(httpTransport).isNotNull();
verify(sslFactory, times(1)).getSslSocketFactory();
verify(sslFactory, times(1)).getHostnameVerifier();
httpTransport.shutdown();
}
Aggregations