This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit e8e5dc4732d1a7057df5b4585942550bb72f8454 Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Tue Feb 11 07:52:52 2020 +0100 Fix #696 Test HTTPS with the HTTP clients --- .../quarkus/component/http/it/HttpResource.java | 30 +++++++++++ .../camel/quarkus/component/http/it/HttpTest.java | 29 +++++++++++ .../camel/quarkus/test/TrustStoreResource.java | 58 ++++++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java b/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java index 871fc1a..732a8e1 100644 --- a/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java +++ b/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java @@ -55,6 +55,16 @@ public class HttpResource { .request(String.class); } + @Path("/ahc/get-https") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getHttps() { + return producerTemplate + .to("ahc:https://restcountries.eu/rest/v2/alpha/cz?bridgeEndpoint=true") + .withHeader(Exchange.HTTP_METHOD, "GET") + .request(String.class); + } + @Path("/ahc/post") @POST @Consumes(MediaType.TEXT_PLAIN) @@ -102,6 +112,16 @@ public class HttpResource { .request(String.class); } + @Path("/http/get-https") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String httpGetHttps() { + return producerTemplate + .to("https://restcountries.eu/rest/v2/alpha/cz?bridgeEndpoint=true") + .withHeader(Exchange.HTTP_METHOD, "GET") + .request(String.class); + } + @Path("/http/post") @POST @Consumes(MediaType.TEXT_PLAIN) @@ -131,6 +151,16 @@ public class HttpResource { .request(String.class); } + @Path("/netty-http/get-https") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String nettyHttpGetHttps() { + return producerTemplate + .to("netty-http:https://restcountries.eu/rest/v2/alpha/cz") + .withHeader(Exchange.HTTP_METHOD, "GET") + .request(String.class); + } + @Path("/netty-http/post") @POST @Consumes(MediaType.TEXT_PLAIN) diff --git a/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java b/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java index 8423014..ab048c3 100644 --- a/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java +++ b/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java @@ -19,14 +19,17 @@ package org.apache.camel.quarkus.component.http.it; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; +import org.apache.camel.quarkus.test.TrustStoreResource; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; @QuarkusTest @QuarkusTestResource(HttpTestResource.class) +@QuarkusTestResource(TrustStoreResource.class) class HttpTest { @ParameterizedTest @ValueSource(strings = { "ahc", "http", "netty-http" }) @@ -49,6 +52,32 @@ class HttpTest { .body(is("MESSAGE")); } + @ParameterizedTest + @ValueSource(strings = { "ahc", + "http" /*, "netty-http" disabled because of https://github.com/apache/camel-quarkus/issues/695 */ }) + public void httpsProducer(String component) { + RestAssured + .given() + .when() + .get("/test/client/{component}/get-https", component) + .then() + .body(containsString("Czech Republic")); + } + + @Test + public void restcountries() throws Exception { + RestAssured + .given() + .baseUri("https://restcountries.eu") + .port(443) + .when() + .accept("application/json") + .get("/rest/v2/alpha/cz") + .then() + .statusCode(200) + .body(containsString("Czech Republic")); + } + @Test public void basicNettyHttpServer() throws Exception { final int port = Integer.getInteger("camel.netty-http.test-port"); diff --git a/integration-tests/support/test-support/src/main/java/org/apache/camel/quarkus/test/TrustStoreResource.java b/integration-tests/support/test-support/src/main/java/org/apache/camel/quarkus/test/TrustStoreResource.java new file mode 100644 index 0000000..32c48c2 --- /dev/null +++ b/integration-tests/support/test-support/src/main/java/org/apache/camel/quarkus/test/TrustStoreResource.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.test; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.Map; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + +/** + * Native images built using a docker container end up with {@code javax.net.ssl.trustStore} system property + * pointing to a non-existing file; see https://quarkus.io/guides/native-and-ssl For that case, we have to set + * {@code javax.net.ssl.trustStore} to an existing path explicitly. + */ +public class TrustStoreResource implements QuarkusTestResourceLifecycleManager { + + @Override + public Map<String, String> start() { + final String graalVmHome = System.getenv("GRAALVM_HOME"); + final String javaHome = System.getenv("JAVA_HOME"); + Path trustStorePath = null; + final String CACERTS_REL_PATH = "jre/lib/security/cacerts"; + if (graalVmHome != null && !graalVmHome.isEmpty() + && Files.exists(trustStorePath = Paths.get(graalVmHome).resolve(CACERTS_REL_PATH))) { + } else if (javaHome != null && !javaHome.isEmpty() + && Files.exists(trustStorePath = Paths.get(javaHome).resolve(CACERTS_REL_PATH))) { + } else { + throw new IllegalStateException( + "Could not find any existing file to set javax.net.ssl.trustStore; tried $GRAALVM_HOME/" + CACERTS_REL_PATH + + " and $JAVA_HOME/" + CACERTS_REL_PATH + + ". You may need to set GRAALVM_HOME or JAVA_HOME properly. Found $GRAALVM_HOME = " + graalVmHome + + " and $JAVA_HOME = " + graalVmHome); + } + return Collections.singletonMap("javax.net.ssl.trustStore", trustStorePath.toString()); + } + + @Override + public void stop() { + } + +}