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:36 UTC
[camel] 14/21: Adding X.509 + PSK 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 189104cd6667db7098cfda0e8c1bf822195c8354
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Apr 29 12:35:56 2019 +0100
Adding X.509 + PSK tests
---
.../java/org/apache/camel/coap/CoAPEndpoint.java | 4 +-
.../apache/camel/coap/CoAPComponentTLSTest.java | 43 +++++++++++++++-------
2 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java
index 5186a96..8d5d394 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java
@@ -401,7 +401,9 @@ public class CoAPEndpoint extends DefaultEndpoint {
builder.setIdentity(privateKey, getKeystore().getCertificateChain(getAlias()));
} else if (privateKey != null) {
builder.setIdentity(privateKey, publicKey);
- } else if (pskStore != null) {
+ }
+
+ if (pskStore != null) {
builder.setPskStore(pskStore);
}
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 b6bd4ca..815a392 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
@@ -42,13 +42,14 @@ 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();
- protected static final int PORT5 = AvailablePortFinder.getNextAvailable();
- protected static final int PORT6 = AvailablePortFinder.getNextAvailable();
- protected static final int PORT7 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT = AvailablePortFinder.getNextAvailable();
+ private static final int PORT2 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT3 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT4 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT5 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT6 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT7 = AvailablePortFinder.getNextAvailable();
+ private static final int PORT8 = AvailablePortFinder.getNextAvailable();
@Produce(uri = "direct:start")
protected ProducerTemplate sender;
@@ -181,6 +182,17 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
assertMockEndpointsSatisfied();
}
+ @Test
+ public void testPreSharedKeyX509() 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:pskx509", "Camel CoAP", CoAPConstants.COAP_METHOD, "POST");
+ assertMockEndpointsSatisfied();
+ }
+
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
@@ -254,17 +266,18 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
+ "keyStoreParameters=#keyParams&cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", PORT4)
.transform(body().prepend("Hello "));
- fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
- + "privateKey=#privateKey&publicKey=#publicKey", PORT5)
+ fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey", PORT5)
.transform(body().prepend("Hello "));
- fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
- + "privateKey=#privateKey&publicKey=#publicKey&clientAuthentication=REQUIRE&"
- + "trustedRpkStore=#trustedRpkStore", PORT6)
+ fromF("coaps://localhost:%d/TestResource?privateKey=#privateKey&publicKey=#publicKey&"
+ + "clientAuthentication=REQUIRE&trustedRpkStore=#trustedRpkStore", PORT6)
+ .transform(body().prepend("Hello "));
+
+ fromF("coaps://localhost:%d/TestResource?pskStore=#pskStore", PORT7)
.transform(body().prepend("Hello "));
fromF("coaps://localhost:%d/TestResource?alias=service&password=security&"
- + "pskStore=#pskStore", PORT7)
+ + "keyStoreParameters=#keyParams&pskStore=#pskStore", PORT8)
.transform(body().prepend("Hello "));
from("direct:start")
@@ -323,6 +336,10 @@ public class CoAPComponentTLSTest extends CamelTestSupport {
.toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&"
+ "cipherSuites=TLS_PSK_WITH_AES_128_CBC_SHA256", PORT7)
.to("mock:result");
+
+ from("direct:pskx509")
+ .toF("coaps://localhost:%d/TestResource?pskStore=#pskStore&trustStoreParameters=#trustParams", PORT8)
+ .to("mock:result");
}
};
}