This is an automated email from the ASF dual-hosted git repository.

ppalaga pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 12426cf54ce77a6cffbde4e238d9f35de321208f
Author: Peter Palaga <[email protected]>
AuthorDate: Fri May 12 17:59:13 2023 +0200

    Make the LDAP test runnable in Quarkus Platform
---
 integration-tests/ldap/build.xml                   |  67 -------------
 integration-tests/ldap/pom.xml                     | 108 ++++++++++++++++-----
 .../camel/quarkus/component/ldap/it/LdapTest.java  |  24 ++++-
 3 files changed, 104 insertions(+), 95 deletions(-)

diff --git a/integration-tests/ldap/build.xml b/integration-tests/ldap/build.xml
deleted file mode 100644
index b41f7e2aea..0000000000
--- a/integration-tests/ldap/build.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<!--
-
-    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.
-
--->
-<project name="camel-quarkus-ldap" basedir=".">
-    <target name="generate-keys">
-        <exec executable="keytool">
-            <arg value="-genkey" />
-            <arg value="-alias" />
-            <arg value="ldap" />
-            <arg value="-keyalg" />
-            <arg value="RSA" />
-            <arg value="-keysize" />
-            <arg value="2048" />
-            <arg value="-validity" />
-            <arg value="1" />
-            <arg value="-keystore" />
-            <arg value="${basedir}/target/keystore.jks" />
-            <arg value="-storepass" />
-            <arg value="ldapPass" />
-            <arg value="-dname" />
-            <arg value="CN=127.0.0.1, OU=Camel Quarkus, O=Apache" />
-            <arg value="-ext" />
-            <arg value="SAN=IP:127.0.0.1" />
-            <arg value="-noprompt" />
-        </exec>
-    </target>
-    <target name="export-certificate" depends="generate-keys">
-        <exec executable="keytool">
-            <arg value="-export" />
-            <arg value="-keystore" />
-            <arg value="${basedir}/target/keystore.jks" />
-            <arg value="-storepass" />
-            <arg value="ldapPass" />
-            <arg value="-alias" />
-            <arg value="ldap" />
-            <arg value="-file" />
-            <arg value="${basedir}/target/ldap-cert" />
-        </exec>
-    </target>
-    <target name="import-certificate" depends="export-certificate">
-        <exec executable="keytool">
-            <arg value="-import" />
-            <arg value="-keystore" />
-            <arg value="${basedir}/target/truststore.jks" />
-            <arg value="-storepass" />
-            <arg value="ldapPass" />
-            <arg value="-file" />
-            <arg value="${basedir}/target/ldap-cert" />
-            <arg value="-noprompt" />
-        </exec>
-    </target>
-</project>
\ No newline at end of file
diff --git a/integration-tests/ldap/pom.xml b/integration-tests/ldap/pom.xml
index 04a42a5888..c4474bc88e 100644
--- a/integration-tests/ldap/pom.xml
+++ b/integration-tests/ldap/pom.xml
@@ -32,9 +32,6 @@
     <name>Camel Quarkus :: Integration Tests :: LDAP</name>
     <description>Integration tests for Camel Quarkus LDAP 
extension</description>
 
-    <properties>
-        <unboundid-version>6.0.8</unboundid-version>
-    </properties>
     <dependencies>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
@@ -72,31 +69,90 @@
         </dependency>
     </dependencies>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-antrun-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>generate-keystore</id>
-                        <phase>generate-resources</phase>
+    <profiles>
+        <profile>
+            <id>full</id>
+            <activation>
+                <property>
+                    <name>!quickly</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>keytool-maven-plugin</artifactId>
                         <configuration>
-                            <target>
-                                <ant antfile="build.xml">
-                                    <target name="import-certificate"/>
-                                </ant>
-                            </target>
+                            <validity>3650</validity>
+                            <keyalg>RSA</keyalg>
+                            <storepass>ldapPass</storepass>
+                            <noprompt>true</noprompt>
                         </configuration>
-                        <goals>
-                            <goal>run</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-    <profiles>
+                        <executions>
+                            <execution>
+                                <id>generate-keypair</id>
+                                <phase>generate-test-resources</phase>
+                                <goals>
+                                    <goal>clean</goal>
+                                    <goal>generateKeyPair</goal>
+                                </goals>
+                                <configuration>
+                                    <alias>ldap</alias>
+                                    <keysize>2048</keysize>
+                                    <dname>CN=127.0.0.1, OU=Camel Quarkus, 
O=Apache</dname>
+                                    <exts>
+                                        <ext>SAN=IP:127.0.0.1</ext>
+                                    </exts>
+                                    
<keystore>${project.basedir}/target/test-classes/keystore.jks</keystore>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>export-certificate</id>
+                                <phase>generate-test-resources</phase>
+                                <goals>
+                                    <goal>exportCertificate</goal>
+                                </goals>
+                                <configuration>
+                                    <alias>ldap</alias>
+                                    
<keystore>${project.basedir}/target/test-classes/keystore.jks</keystore>
+                                    
<file>${basedir}/target/test-classes/ldap-cert</file>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>create-trusstore</id>
+                                <phase>generate-test-resources</phase>
+                                <goals>
+                                    <goal>importCertificate</goal>
+                                </goals>
+                                <configuration>
+                                    <alias>localhost</alias>
+                                    <trustcacerts>true</trustcacerts>
+                                    
<keystore>${basedir}/target/test-classes/truststore.jks</keystore>
+                                    
<file>${basedir}/target/test-classes/ldap-cert</file>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>generate-wrong-trusstore</id>
+                                <phase>generate-sources</phase>
+                                <goals>
+                                    <goal>clean</goal>
+                                    <goal>generateKeyPair</goal>
+                                </goals>
+                                <configuration>
+                                    <alias>localhost</alias>
+                                    <dname>CN=localhost, OU=eng, 
O=apache.org</dname>
+                                    <exts>
+                                        
<ext>bc:c=ca:true,pathlen:2147483647</ext>
+                                        
<ext>IssuerAlternativeName=DNS:NOT-FOR-PRODUCTION-USE</ext>
+                                    </exts>
+                                    
<keystore>${project.build.outputDirectory}/truststore-wrong.jks</keystore>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
         <profile>
             <id>virtualDependencies</id>
             <activation>
diff --git 
a/integration-tests/ldap/src/test/java/org/apache/camel/quarkus/component/ldap/it/LdapTest.java
 
b/integration-tests/ldap/src/test/java/org/apache/camel/quarkus/component/ldap/it/LdapTest.java
index 6cbeb72091..672a437f82 100644
--- 
a/integration-tests/ldap/src/test/java/org/apache/camel/quarkus/component/ldap/it/LdapTest.java
+++ 
b/integration-tests/ldap/src/test/java/org/apache/camel/quarkus/component/ldap/it/LdapTest.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.quarkus.component.ldap.it;
 
+import java.io.InputStream;
 import java.net.InetAddress;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -43,6 +47,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 class LdapTest {
 
     private static InMemoryDirectoryServer ldapServer = null;
+    private static final String truststoreFile = 
"target/test-classes/truststore.jks";
 
     @BeforeAll
     public static void setUpLdapServer() throws Exception {
@@ -53,7 +58,22 @@ class LdapTest {
                 InetAddress.getLoopbackAddress(), 0, null);
 
         // The keystore is generated by the build process
-        SSLUtil serverSSLUtil = new SSLUtil(new 
KeyStoreKeyManager("target/keystore.jks", "ldapPass".toCharArray()),
+        Path keystoreFile = Paths.get("target/test-classes/keystore.jks");
+        if (!Files.isRegularFile(keystoreFile)) {
+            /* The test is run from a test-jar within Quarkus Platform, where 
the Ant script was not run
+             * so let's copy the keystore from test-jar to the local folder */
+            Files.createDirectories(keystoreFile.getParent());
+            try (InputStream in = 
LdapTest.class.getClassLoader().getResourceAsStream(keystoreFile.getFileName().toString()))
 {
+                Files.copy(in, keystoreFile);
+            }
+            Path truststorePath = Paths.get(truststoreFile);
+            try (InputStream in = LdapTest.class.getClassLoader()
+                    
.getResourceAsStream(truststorePath.getFileName().toString())) {
+                Files.copy(in, truststorePath);
+            }
+        }
+
+        SSLUtil serverSSLUtil = new SSLUtil(new 
KeyStoreKeyManager(keystoreFile.toFile(), "ldapPass".toCharArray()),
                 null);
         InMemoryListenerConfig sslListenerConfig = 
InMemoryListenerConfig.createLDAPSConfig("ldaps",
                 InetAddress.getLoopbackAddress(), 0, 
serverSSLUtil.createSSLServerSocketFactory(),
@@ -138,7 +158,7 @@ class LdapTest {
         options.put("port", 
String.valueOf(ldapServer.getListenPort(listenerName)));
         options.put("ssl", String.valueOf(useSSL));
         if (useSSL) {
-            options.put("trustStore", "target/truststore.jks");
+            options.put("trustStore", truststoreFile);
             options.put("trustStorePassword", "ldapPass");
         }
 

Reply via email to