Search in sources :

Example 11 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient 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)

Example 12 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient in project smallrye-graphql by smallrye.

the class DynamicClientSSLTest method serverAuthentication_badKeystoreOnServer.

/**
 * Client requests server authentication, and server's certificate is untrusted.
 */
@Test
public void serverAuthentication_badKeystoreOnServer() throws Exception {
    HttpServer server = tools.runServer("classpath:ssl/server.pkcs12.wrong.keystore", "serverwrongkeystorepassword", null, null);
    try {
        System.setProperty("myclient2/mp-graphql/truststore", "classpath:ssl/client.pkcs12.truststore");
        System.setProperty("myclient2/mp-graphql/truststorePassword", "clienttruststorepassword");
        System.setProperty("myclient2/mp-graphql/truststoreType", "PKCS12");
        DynamicGraphQLClient client = null;
        try {
            client = DynamicGraphQLClientBuilder.newBuilder().configKey("myclient2").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 client rejected the server's certificate
            assertHasCauseContainingMessage(e, "unable to find valid certification path to requested target");
        } finally {
            if (client != null) {
                client.close();
            }
        }
    } finally {
        server.close();
    }
}
Also used : HttpServer(io.vertx.core.http.HttpServer) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.jupiter.api.Test)

Example 13 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient in project smallrye-graphql by smallrye.

the class NamedDynamicClients method getClient.

@Produces
@Default
@Dependent
DynamicGraphQLClient getClient(InjectionPoint ip) {
    GraphQLClient annotation = ip.getAnnotated().getAnnotation(GraphQLClient.class);
    String clientName = annotation != null ? annotation.value() : DEFAULT_CLIENT_NAME;
    return createdClients.computeIfAbsent(clientName, name -> DynamicGraphQLClientBuilder.newBuilder().configKey(name).build());
}
Also used : DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) GraphQLClient(io.smallrye.graphql.client.GraphQLClient) Produces(javax.enterprise.inject.Produces) Dependent(javax.enterprise.context.Dependent) Default(javax.enterprise.inject.Default)

Aggregations

DynamicGraphQLClient (io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient)13 VertxDynamicGraphQLClientBuilder (io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder)6 HttpServer (io.vertx.core.http.HttpServer)5 Test (org.junit.jupiter.api.Test)5 Response (io.smallrye.graphql.client.Response)4 Test (org.junit.Test)3 GitHubEvent (io.quarkiverse.githubapp.GitHubEvent)2 EventAnnotation (io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotation)2 EventDispatchingConfiguration (io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventDispatchingConfiguration)2 ConfigFileReader (io.quarkiverse.githubapp.runtime.ConfigFileReader)2 MultiplexedEvent (io.quarkiverse.githubapp.runtime.MultiplexedEvent)2 ErrorHandlerBridgeFunction (io.quarkiverse.githubapp.runtime.error.ErrorHandlerBridgeFunction)2 GitHubService (io.quarkiverse.githubapp.runtime.github.GitHubService)2 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)2 BytecodeCreator (io.quarkus.gizmo.BytecodeCreator)2 CatchBlockCreator (io.quarkus.gizmo.CatchBlockCreator)2 ClassCreator (io.quarkus.gizmo.ClassCreator)2 FieldCreator (io.quarkus.gizmo.FieldCreator)2 MethodCreator (io.quarkus.gizmo.MethodCreator)2 ResultHandle (io.quarkus.gizmo.ResultHandle)2