Search in sources :

Example 11 with Client

use of javax.ws.rs.client.Client in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfServerCertNotFoundInTruststore.

@Test
public void shouldErrorIfServerCertNotFoundInTruststore() throws Exception {
    tlsConfiguration.setTrustStorePath(new File(ResourceHelpers.resourceFilePath("stores/server/other_cert_truststore.ts")));
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("tls_broken_client");
    assertThatThrownBy(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getLocalPort())).request().get()).isInstanceOf(ProcessingException.class).hasCauseInstanceOf(SSLHandshakeException.class);
}
Also used : Client(javax.ws.rs.client.Client) File(java.io.File) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 12 with Client

use of javax.ws.rs.client.Client in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldNotErrorIfServerCertSelfSignedAndSelfSignedCertsAllowed.

@Test
public void shouldNotErrorIfServerCertSelfSignedAndSelfSignedCertsAllowed() throws Exception {
    tlsConfiguration.setTrustSelfSignedCertificates(true);
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("self_sign_permitted");
    final Response response = client.target(String.format("https://localhost:%d", TLS_APP_RULE.getTestSupport().getPort(1))).request().get();
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 13 with Client

use of javax.ws.rs.client.Client in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfHostnameVerificationOnAndServerHostnameMatchesAndFailVerifierSpecified.

@Test
public void shouldErrorIfHostnameVerificationOnAndServerHostnameMatchesAndFailVerifierSpecified() throws Exception {
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).using(new FailVerifier()).build("bad_host_broken_fail_verifier");
    final Throwable exn = catchThrowable(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getLocalPort())).request().get());
    assertThat(exn).hasCauseExactlyInstanceOf(SSLPeerUnverifiedException.class);
    assertThat(exn.getCause()).hasMessage("Certificate for <localhost> doesn't match any of the subject alternative names: []");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 14 with Client

use of javax.ws.rs.client.Client in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfHostnameVerificationOnAndServerHostnameDoesntMatch.

@Test
public void shouldErrorIfHostnameVerificationOnAndServerHostnameDoesntMatch() throws Exception {
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("bad_host_broken");
    final Throwable exn = catchThrowable(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(3))).request().get());
    assertThat(exn).hasCauseExactlyInstanceOf(SSLPeerUnverifiedException.class);
    assertThat(exn.getCause()).hasMessage("Certificate for <localhost> doesn't match any of the subject alternative names: []");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 15 with Client

use of javax.ws.rs.client.Client in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfClientAuthFails.

@Test
public void shouldErrorIfClientAuthFails() throws Exception {
    tlsConfiguration.setKeyStorePath(new File(ResourceHelpers.resourceFilePath("stores/server/self_sign_keycert.p12")));
    tlsConfiguration.setKeyStorePassword("password");
    tlsConfiguration.setKeyStoreType("PKCS12");
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("client_auth_broken");
    final Throwable exn = catchThrowable(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(2))).request().get());
    assertThat(exn).isInstanceOf(ProcessingException.class);
    assertThat(exn.getCause()).isInstanceOfAny(SocketException.class, SSLHandshakeException.class);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Client(javax.ws.rs.client.Client) File(java.io.File) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Aggregations

Client (javax.ws.rs.client.Client)227 Test (org.junit.Test)160 WebTarget (javax.ws.rs.client.WebTarget)96 Response (javax.ws.rs.core.Response)87 JerseyTest (org.glassfish.jersey.test.JerseyTest)76 ClientConfig (org.glassfish.jersey.client.ClientConfig)71 URL (java.net.URL)20 ClientResponse (org.glassfish.jersey.client.ClientResponse)19 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)18 Before (org.junit.Before)17 Invocation (javax.ws.rs.client.Invocation)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)14 IOException (java.io.IOException)12 ProcessingException (javax.ws.rs.ProcessingException)12 HttpServer (org.glassfish.grizzly.http.server.HttpServer)10 URI (java.net.URI)9 JerseyClient (org.glassfish.jersey.client.JerseyClient)9 PrintWriter (java.io.PrintWriter)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 SSLContext (javax.net.ssl.SSLContext)8