Skip to content

Commit

Permalink
Fix #696 Test HTTPS with the HTTP clients
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Feb 12, 2020
1 parent ca39d37 commit bcf1262
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public String get(@QueryParam("test-port") int port) {
.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)
Expand Down Expand Up @@ -102,6 +112,16 @@ public String httpGet(@QueryParam("test-port") int port) {
.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)
Expand Down Expand Up @@ -131,6 +151,16 @@ public String nettyHttpGet(@QueryParam("test-port") int port) {
.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
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" })
Expand All @@ -49,6 +52,32 @@ public void basicProducer(String component) {
.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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
}

}

0 comments on commit bcf1262

Please sign in to comment.