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();
}
}
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();
}
}
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());
}
Aggregations