Skip to content

Commit

Permalink
Replace manual certificate generation with camel-quarkus-integration-…
Browse files Browse the repository at this point in the history
…tests-support-certificate-generator

fixes #5967
fixes #6125
fixes #6126
fixes #6127
  • Loading branch information
JiriOndrusek committed Jun 3, 2024
1 parent 3e817e2 commit 4188a3a
Show file tree
Hide file tree
Showing 112 changed files with 325 additions and 863 deletions.
7 changes: 0 additions & 7 deletions integration-test-groups/http/README.adoc

This file was deleted.

67 changes: 0 additions & 67 deletions integration-test-groups/http/common/generate-certs.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class CommonProducers {
@Named
public SSLContextParameters sslContextParameters() {
KeyStoreParameters keystoreParameters = new KeyStoreParameters();
keystoreParameters.setResource("/jsse/localhost-keystore.pkcs12");
keystoreParameters.setResource("/certs/localhost-keystore.p12");
keystoreParameters.setPassword("localhost-keystore-password");

KeyStoreParameters truststoreParameters = new KeyStoreParameters();
truststoreParameters.setResource("/jsse/client-truststore.pkcs12");
truststoreParameters.setPassword("client-truststore-password");
truststoreParameters.setResource("/certs/localhost-truststore.p12");
truststoreParameters.setPassword("localhost-keystore-password");

TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
trustManagersParameters.setKeyStore(truststoreParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# Quarkus
#
quarkus.native.resources.includes = jsse/*,restcountries/*
quarkus.native.resources.includes = certs/*,restcountries/*
quarkus.native.add-all-charsets = true
quarkus.camel.native.reflection.serialization-enabled = true

Expand All @@ -31,7 +31,7 @@ quarkus.security.users.embedded.roles.admin=admin
quarkus.security.users.embedded.roles.noadmin=user

quarkus.http.insecure-requests=enabled
quarkus.http.ssl.certificate.key-store-file=jsse/localhost-keystore.pkcs12
quarkus.http.ssl.certificate.key-store-file=certs/localhost-keystore.p12
quarkus.http.ssl.certificate.key-store-password=localhost-keystore-password
quarkus.resteasy.gzip.enabled=true

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@

public class HttpTestResource implements QuarkusTestResourceLifecycleManager {
private static final Logger LOG = Logger.getLogger(HttpTestResource.class);

public static final String KEYSTORE_NAME = "localhost";
public static final String KEYSTORE_PASSWORD = "localhost-keystore-password";

private ProxyServer server;

@Override
Expand Down
3 changes: 0 additions & 3 deletions integration-test-groups/http/common/v3.ext

This file was deleted.

5 changes: 5 additions & 0 deletions integration-test-groups/http/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-support-certificate-generator</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import me.escoffier.certs.Format;
import me.escoffier.certs.junit5.Certificate;
import org.apache.camel.quarkus.component.http.common.AbstractHttpTest;
import org.apache.camel.quarkus.component.http.common.HttpTestResource;
import org.apache.camel.quarkus.test.support.certificate.TestCertificates;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

@TestCertificates(certificates = {
@Certificate(name = HttpTestResource.KEYSTORE_NAME, formats = {
Format.PKCS12 }, password = HttpTestResource.KEYSTORE_PASSWORD) })
@QuarkusTest
@QuarkusTestResource(HttpTestResource.class)
public class HttpTest extends AbstractHttpTest {
Expand Down
5 changes: 5 additions & 0 deletions integration-test-groups/http/netty-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-support-certificate-generator</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import me.escoffier.certs.Format;
import me.escoffier.certs.junit5.Certificate;
import org.apache.camel.quarkus.component.http.common.HttpTestResource;
import org.apache.camel.quarkus.test.support.certificate.TestCertificates;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

@TestCertificates(certificates = {
@Certificate(name = HttpTestResource.KEYSTORE_NAME, formats = {
Format.PKCS12 }, password = HttpTestResource.KEYSTORE_PASSWORD) })
@QuarkusTest
@QuarkusTestResource(NettyHttpJaasTestResource.class)
public class NettyHttpJaasTest {
Expand Down
5 changes: 5 additions & 0 deletions integration-test-groups/http/vertx-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-support-certificate-generator</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import me.escoffier.certs.Format;
import me.escoffier.certs.junit5.Certificate;
import org.apache.camel.quarkus.component.http.common.AbstractHttpTest;
import org.apache.camel.quarkus.component.http.common.HttpTestResource;
import org.apache.camel.quarkus.test.support.certificate.TestCertificates;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

@TestCertificates(certificates = {
@Certificate(name = HttpTestResource.KEYSTORE_NAME, formats = {
Format.PKCS12 }, password = HttpTestResource.KEYSTORE_PASSWORD) })
@QuarkusTest
@QuarkusTestResource(HttpTestResource.class)
public class VertxHttpTest extends AbstractHttpTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.support.certificate;

public class CertificatesUtil {
public static final String DEFAULT_CERTS_BASEDIR = "target/classes/certs";

private CertificatesUtil() {
}

public static String keystoreFile(String name, String extension) {
return DEFAULT_CERTS_BASEDIR + "/" + name + "-keystore." + extension;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* based on docker host (required for usage with external docker host)
* Therefore I created a new annotation 'TestCertificates' which would use this new extension.
*/
public class TestCertificateGenerationExtension implements BeforeAllCallback, ParameterResolver {
public class TestCertificateGenerationExtension implements BeforeAllCallback {
private static final Logger LOGGER = Logger.getLogger(TestCertificateGenerationExtension.class);

public static TestCertificateGenerationExtension getInstance(ExtensionContext extensionContext) {
Expand All @@ -65,8 +65,12 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception {
var annotation = maybe.get();

//cn and alternativeSubjectName might be different (to reflect docker host)
Optional<String> cn = resolveDockerHost();
Optional<String> altSubName = cn.stream().map(h -> "IP:%s".formatted(h)).findAny();
Optional<String> cn = Optional.empty();
Optional<String> altSubName = Optional.empty();
if (annotation.docker()) {
cn = resolveDockerHost();
altSubName = cn.stream().map(h -> "IP:%s".formatted(h)).findAny();
}

for (Certificate certificate : annotation.certificates()) {
String baseDir = annotation.baseDir();
Expand Down Expand Up @@ -113,15 +117,4 @@ private Optional<String> resolveDockerHost() {
return Optional.empty();
}

@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
throw new IllegalArgumentException("Not supported!");
}

@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
throw new IllegalArgumentException("Not supported!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@

/**
* The base directory in which certificates will be generated.
* Default value is `target/classes/certs`
*/
String baseDir();
String baseDir() default CertificatesUtil.DEFAULT_CERTS_BASEDIR;

/**
* The certificates to generate.
Expand All @@ -52,4 +53,10 @@
* Whether to replace the certificates if they already exist.
*/
boolean replaceIfExists() default false;

/**
* Whether certificate is used in docker container. If so, the cn and subject alt name has to equal docker host
* (which might differ in case of external docker host)
*/
boolean docker() default false;
}
5 changes: 5 additions & 0 deletions integration-tests/ftp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
<artifactId>sshd-scp</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-support-certificate-generator</artifactId>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ public Map<String, String> start() {

ListenerFactory factory = createListenerFactory(port);

FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userMgr);
serverFactory.setFileSystem(fsf);
serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
serverFactory.addListener("default", factory.createListener());

FtpServerFactory ftpServerFactory = serverFactory;
ftpServer = ftpServerFactory.createServer();
ftpServer.start();
if (factory != null) {
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userMgr);
serverFactory.setFileSystem(fsf);
serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());

serverFactory.addListener("default", factory.createListener());

FtpServerFactory ftpServerFactory = serverFactory;
ftpServer = ftpServerFactory.createServer();
ftpServer.start();
}

return CollectionHelper.mapOf(
"camel." + componentName + ".test-port", Integer.toString(port),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import me.escoffier.certs.Format;
import me.escoffier.certs.junit5.Certificate;
import org.apache.camel.quarkus.test.support.certificate.CertificatesUtil;
import org.apache.camel.quarkus.test.support.certificate.TestCertificates;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;

@TestCertificates(certificates = {
@Certificate(name = "ftp", formats = {
Format.PKCS12 }, password = "password") })
@Disabled //https://github.com/apache/camel-quarkus/issues/4089
@QuarkusTest
@QuarkusTestResource(FtpsTestResource.class)
class FtpsTest {
static final String CERTIFICATE_KEYSTORE_FILE = CertificatesUtil.keystoreFile("ftp", "p12");

@Test
public void testFtpsComponent() {
// Create a new file on the FTPS server
Expand Down
Loading

0 comments on commit 4188a3a

Please sign in to comment.