Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #696 Test HTTPS with the HTTP clients #697

Merged
merged 2 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
maven-${{ github.sha }}
build-alternative-jvm:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
java: [ '11' , '12' ]
Expand All @@ -68,6 +69,13 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Restore Cache
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: maven-${{ github.sha }}
restore-keys: |
maven-${{ github.sha }}
- name: Build on ${{ matrix.java }}
run: |
./mvnw -V -B ${BRANCH_OPTIONS} \
Expand Down
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() {
}

}