Search in sources :

Example 6 with VertxDynamicGraphQLClientBuilder

use of io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder in project smallrye-graphql by smallrye.

the class DynamicClientSSLTest method clientAuthentication_badKeystore.

/**
 * Server requests client authentication, and the client's certificate is untrusted.
 */
@Test
public void clientAuthentication_badKeystore() throws Exception {
    HttpServer server = tools.runServer("classpath:ssl/server.pkcs12.keystore", "serverkeystorepassword", "classpath:ssl/server.pkcs12.truststore", "servertruststorepassword");
    try {
        System.setProperty("myclient4/mp-graphql/keystore", "classpath:ssl/client.pkcs12.wrong.keystore");
        System.setProperty("myclient4/mp-graphql/keystorePassword", "clientwrongkeystorepassword");
        System.setProperty("myclient4/mp-graphql/keystoreType", "PKCS12");
        WebClientOptions options = new WebClientOptions();
        // don't require server auth
        options.setTrustAll(true);
        DynamicGraphQLClient client = null;
        try {
            client = new VertxDynamicGraphQLClientBuilder().configKey("myclient4").options(options).url("https://127.0.0.1:" + server.actualPort()).build();
            client.executeAsync("asd").await().atMost(Duration.ofSeconds(1));
            Assertions.fail("Connection to server should fail");
        } catch (Exception e) {
            // verify that the server rejected the client's certificate
            assertHasCauseContainingMessage(e, "Received fatal alert: bad_certificate");
        } finally {
            if (client != null) {
                client.close();
            }
        }
    } finally {
        server.close();
    }
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpServer(io.vertx.core.http.HttpServer) VertxDynamicGraphQLClientBuilder(io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicGraphQLClient (io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient)6 VertxDynamicGraphQLClientBuilder (io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder)6 Response (io.smallrye.graphql.client.Response)4 HttpServer (io.vertx.core.http.HttpServer)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 WebClientOptions (io.vertx.ext.web.client.WebClientOptions)2