You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by co...@apache.org on 2019/05/24 19:39:31 UTC
[camel] 09/21: Adding more CoAP TLS tests
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 27b5f7f230a8ecc4e5ef4c28046f99bc784d2cec
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri Apr 19 13:04:09 2019 +0100
Adding more CoAP TLS tests
---
.../apache/camel/coap/CoAPComponentTLSTest.java | 137 ++++++++++++++++++++-
.../camel-coap/src/test/resources/selfsigned.jks | Bin 0 -> 701 bytes
.../camel-coap/src/test/resources/truststore2.jks | Bin 0 -> 717 bytes
3 files changed, 132 insertions(+), 5 deletions(-)
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java
index d515e8e..f78bcb5 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTLSTest.java
@@ -17,6 +17,8 @@
package org.apache.camel.coap;
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
@@ -30,20 +32,80 @@ import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.junit.Test;
public class CoAPComponentTLSTest extends CamelTestSupport {
-
+
protected static final int PORT = AvailablePortFinder.getNextAvailable();
+ protected static final int PORT2 = AvailablePortFinder.getNextAvailable();
+ protected static final int PORT3 = AvailablePortFinder.getNextAvailable();
+ protected static final int PORT4 = AvailablePortFinder.getNextAvailable();
@Produce(uri = "direct:start")
protected ProducerTemplate sender;
+
+ @Test
+ public void testSuccessfulCall() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ mock.expectedBodiesReceived("Hello Camel CoAP");
+ mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, MediaTypeRegistry.toString(MediaTypeRegistry.APPLICATION_OCTET_STREAM));
+ mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString());
+ sendBodyAndHeader("direct:start", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testNoTruststore() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(0);
+ sendBodyAndHeader("direct:notruststore", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testTrustValidationFailed() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(0);
+ sendBodyAndHeader("direct:failedtrust", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testSelfSigned() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ mock.expectedBodiesReceived("Hello Camel CoAP");
+ mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, MediaTypeRegistry.toString(MediaTypeRegistry.APPLICATION_OCTET_STREAM));
+ mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString());
+ sendBodyAndHeader("direct:selfsigned", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testClientAuthentication() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ mock.expectedBodiesReceived("Hello Camel CoAP");
+ mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, MediaTypeRegistry.toString(MediaTypeRegistry.APPLICATION_OCTET_STREAM));
+ mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString());
+ sendBodyAndHeader("direct:clientauth", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testFailedClientAuthentication() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(0);
+ sendBodyAndHeader("direct:failedclientauth", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ assertMockEndpointsSatisfied();
+ }
@Test
- public void testTLS() throws Exception {
+ public void testCipherSuites() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
mock.expectedBodiesReceived("Hello Camel CoAP");
mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, MediaTypeRegistry.toString(MediaTypeRegistry.APPLICATION_OCTET_STREAM));
mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString());
- sender.sendBodyAndHeader("Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ sendBodyAndHeader("direct:ciphersuites", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
assertMockEndpointsSatisfied();
}
@@ -54,13 +116,28 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
KeyStoreParameters keystoreParameters = new KeyStoreParameters();
keystoreParameters.setResource("service.jks");
keystoreParameters.setPassword("security");
-
+
+ KeyStoreParameters keystoreParameters2 = new KeyStoreParameters();
+ keystoreParameters2.setResource("selfsigned.jks");
+ keystoreParameters2.setPassword("security");
+
+ KeyStoreParameters keystoreParameters3 = new KeyStoreParameters();
+ keystoreParameters3.setResource("client.jks");
+ keystoreParameters3.setPassword("security");
+
KeyStoreParameters truststoreParameters = new KeyStoreParameters();
truststoreParameters.setResource("truststore.jks");
truststoreParameters.setPassword("storepass");
-
+
+ KeyStoreParameters truststoreParameters2 = new KeyStoreParameters();
+ truststoreParameters2.setResource("truststore2.jks");
+ truststoreParameters2.setPassword("storepass");
+
registry.bind("keyParams", keystoreParameters);
+ registry.bind("keyParams2", keystoreParameters2);
+ registry.bind("keyParams3", keystoreParameters3);
registry.bind("trustParams", truststoreParameters);
+ registry.bind("trustParams2", truststoreParameters2);
return registry;
}
@@ -75,10 +152,60 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
+ "keyStoreParameters=#keyParams", PORT)
.transform(body().prepend("Hello "));
+ fromF("coaps://localhost:%d/TestResource?alias=selfsigned&password=security&"
+ + "keyStoreParameters=#keyParams2", PORT2)
+ .transform(body().prepend("Hello "));
+
+ fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
+ + "trustStoreParameters=#trustParams&"
+ + "keyStoreParameters=#keyParams&clientAuthentication=REQUIRE", PORT3)
+ .transform(body().prepend("Hello "));
+
+ fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
+ + "keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
+ .transform(body().prepend("Hello "));
+
from("direct:start")
.toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams", PORT)
.to("mock:result");
+
+ from("direct:notruststore")
+ .toF("coaps://localhost:%d/TestResource", PORT)
+ .to("mock:result");
+
+ from("direct:failedtrust")
+ .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams2", PORT)
+ .to("mock:result");
+
+ from("direct:selfsigned")
+ .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#keyParams2", PORT2)
+ .to("mock:result");
+
+ from("direct:clientauth")
+ .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
+ + "keyStoreParameters=#keyParams3&alias=client&password=security", PORT3)
+ .to("mock:result");
+
+ from("direct:failedclientauth")
+ .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
+ + "keyStoreParameters=#keyParams2&alias=selfsigned&password=security", PORT3)
+ .to("mock:result");
+
+ from("direct:ciphersuites")
+ .toF("coaps://localhost:%d/TestResource?trustStoreParameters=#trustParams&"
+ + "cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
+ .to("mock:result");
}
};
}
+
+ protected void sendBodyAndHeader(String endpointUri, final Object body, String headerName, String headerValue) {
+ template.send(endpointUri, new Processor() {
+ public void process(Exchange exchange) {
+ Message in = exchange.getIn();
+ in.setBody(body);
+ in.setHeader(headerName, headerValue);
+ }
+ });
+ }
}
diff --git a/components/camel-coap/src/test/resources/selfsigned.jks b/components/camel-coap/src/test/resources/selfsigned.jks
new file mode 100644
index 0000000..ee745ff
Binary files /dev/null and b/components/camel-coap/src/test/resources/selfsigned.jks differ
diff --git a/components/camel-coap/src/test/resources/truststore2.jks b/components/camel-coap/src/test/resources/truststore2.jks
new file mode 100644
index 0000000..94249d6
Binary files /dev/null and b/components/camel-coap/src/test/resources/truststore2.jks differ