This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push:
new c29e757b Ref #453: Add crypto integration test (#454)
c29e757b is described below
commit c29e757b4fd8c8a81f0e9053d3181c314bcac7c2
Author: Stefan Tataru <[email protected]>
AuthorDate: Mon Jul 22 09:05:50 2024 +0200
Ref #453: Add crypto integration test (#454)
---
tests/features/camel-crypto/pom.xml | 42 ++++++++++++++
.../karaf/camel/test/CamelCryptoRouteSupplier.java | 67 ++++++++++++++++++++++
.../apache/karaf/camel/itest/CamelCryptoITest.java | 60 +++++++++++++++++++
tests/features/pom.xml | 1 +
4 files changed, 170 insertions(+)
diff --git a/tests/features/camel-crypto/pom.xml
b/tests/features/camel-crypto/pom.xml
new file mode 100644
index 00000000..1c4c9506
--- /dev/null
+++ b/tests/features/camel-crypto/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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 xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.karaf</groupId>
+ <artifactId>camel-karaf-features-test</artifactId>
+ <version>4.7.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-crypto-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: Crypto</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-crypto</artifactId>
+ <version>${camel-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git
a/tests/features/camel-crypto/src/main/java/org/apache/karaf/camel/test/CamelCryptoRouteSupplier.java
b/tests/features/camel-crypto/src/main/java/org/apache/karaf/camel/test/CamelCryptoRouteSupplier.java
new file mode 100644
index 00000000..fadf8a97
--- /dev/null
+++
b/tests/features/camel-crypto/src/main/java/org/apache/karaf/camel/test/CamelCryptoRouteSupplier.java
@@ -0,0 +1,67 @@
+/*
+ * 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.karaf.camel.test;
+
+import static org.apache.camel.builder.Builder.constant;
+
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.crypto.DigitalSignatureConstants;
+import org.apache.camel.model.RouteDefinition;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+ name = "karaf-camel-crypto-test",
+ immediate = true,
+ service = CamelCryptoRouteSupplier.class
+)
+public class CamelCryptoRouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ @Override
+ protected boolean consumerEnabled() {
+ return false;
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition
producerRoute) {
+ KeyPair keys = getKeyPair();
+
+ producerRoute.log("Will sign: ${body}")
+ .setHeader(DigitalSignatureConstants.SIGNATURE_PRIVATE_KEY,
constant(keys.getPrivate()))
+ .to("crypto:sign:bobsPizzaSignature")
+ .log("Signature:
${header.%s}".formatted(DigitalSignatureConstants.SIGNATURE))
+ .log("Will verify:
${header.%s}".formatted(DigitalSignatureConstants.SIGNATURE))
+ .setHeader(DigitalSignatureConstants.SIGNATURE_PUBLIC_KEY_OR_CERT,
constant(keys.getPublic()))
+ .to("crypto:verify:bobsPizzaSignature?clearHeaders=false")
+ .log("Verified: ${body}")
+ .toF("mock:%s", getResultMockName());
+ }
+
+ private KeyPair getKeyPair() {
+ try {
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
+ keyGen.initialize(512, new SecureRandom());
+ return keyGen.generateKeyPair();
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
diff --git
a/tests/features/camel-crypto/src/test/java/org/apache/karaf/camel/itest/CamelCryptoITest.java
b/tests/features/camel-crypto/src/test/java/org/apache/karaf/camel/itest/CamelCryptoITest.java
new file mode 100644
index 00000000..81783331
--- /dev/null
+++
b/tests/features/camel-crypto/src/test/java/org/apache/karaf/camel/itest/CamelCryptoITest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed 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.karaf.camel.itest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.crypto.DigitalSignatureConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelCryptoITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ private static final String PAYLOAD = "I, Bob, solemnly swear that
pineapple DOES belong on pizza.";
+
+ @Override
+ public String getBodyToSend() {
+ return PAYLOAD;
+ }
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived(PAYLOAD);
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint();
+ List<Exchange> exchanges = endpoint.getExchanges();
+ assertNotNull(exchanges);
+ assertEquals(1, exchanges.size());
+ Exchange ex = exchanges.get(0);
+
+ String signature =
ex.getIn().getHeader(DigitalSignatureConstants.SIGNATURE, String.class);
+ assertNotNull(signature);
+
+ assertMockEndpointsSatisfied();
+ }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index cbbb522d..955584a9 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -58,6 +58,7 @@
<module>camel-caffeine</module>
<module>camel-cbor</module>
<module>camel-core</module>
+ <module>camel-crypto</module>
<module>camel-csv</module>
<module>camel-dns</module>
<!-- TODO: Fix the integration test and re-add it
https://github.com/apache/camel-karaf/issues/438 -->