You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/01/26 19:08:09 UTC

qpid-jms git commit: Add tests for trust all and connect fail is no defined trust store and trust all not configured.

Repository: qpid-jms
Updated Branches:
  refs/heads/master f65bb22ae -> ee509a04c


Add tests for trust all and connect fail is no defined trust store and
trust all not configured.

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/ee509a04
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/ee509a04
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/ee509a04

Branch: refs/heads/master
Commit: ee509a04cc4ed8c71c7d916c614a05027a4924fb
Parents: f65bb22
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Jan 26 13:07:59 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Jan 26 13:07:59 2015 -0500

----------------------------------------------------------------------
 .../transports/netty/NettySslTransportTest.java | 79 ++++++++++++++++++++
 .../transports/netty/NettyTcpTransportTest.java |  4 +-
 2 files changed, 81 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/ee509a04/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportTest.java
index d577ef4..d1ecf2f 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettySslTransportTest.java
@@ -16,18 +16,27 @@
  */
 package org.apache.qpid.jms.transports.netty;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.net.URI;
 
 import org.apache.qpid.jms.transports.Transport;
 import org.apache.qpid.jms.transports.TransportListener;
 import org.apache.qpid.jms.transports.TransportOptions;
 import org.apache.qpid.jms.transports.TransportSslOptions;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Test basic functionality of the Netty based SSL Transport.
  */
 public class NettySslTransportTest extends NettyTcpTransportTest {
 
+    private static final Logger LOG = LoggerFactory.getLogger(NettySslTransportTest.class);
+
     public static final String PASSWORD = "password";
     public static final String SERVER_KEYSTORE = "src/test/resources/broker-jks.keystore";
     public static final String SERVER_TRUSTSTORE = "src/test/resources/broker-jks.truststore";
@@ -35,6 +44,54 @@ public class NettySslTransportTest extends NettyTcpTransportTest {
     public static final String CLIENT_TRUSTSTORE = "src/test/resources/client-jks.truststore";
     public static final String KEYSTORE_TYPE = "jks";
 
+    @Test(timeout = 60 * 1000)
+    public void testConnectToServerWithoutTrustStoreFails() throws Exception {
+        try (NettyEchoServer server = new NettyEchoServer(createServerOptions())) {
+            server.start();
+
+            int port = server.getServerPort();
+            URI serverLocation = new URI("tcp://localhost:" + port);
+
+            Transport transport = createTransport(serverLocation, testListener, createClientOptionsTrustNone());
+            try {
+                transport.connect();
+                fail("Should not have connected to the server");
+            } catch (Exception e) {
+                LOG.info("Connection failed to untrusted test server.");
+            }
+
+            assertFalse(transport.isConnected());
+
+            transport.close();
+        }
+
+        assertTrue(exceptions.isEmpty());
+    }
+
+    @Test(timeout = 60 * 1000)
+    public void testConnectToServerClientTrustsAll() throws Exception {
+        try (NettyEchoServer server = new NettyEchoServer(createServerOptions())) {
+            server.start();
+
+            int port = server.getServerPort();
+            URI serverLocation = new URI("tcp://localhost:" + port);
+
+            Transport transport = createTransport(serverLocation, testListener, createClientOptionsTrustAll());
+            try {
+                transport.connect();
+                LOG.info("Connection established to untrusted test server.");
+            } catch (Exception e) {
+                fail("Should have connected to the server");
+            }
+
+            assertTrue(transport.isConnected());
+
+            transport.close();
+        }
+
+        assertTrue(exceptions.isEmpty());
+    }
+
     @Override
     protected Transport createTransport(URI serverLocation, TransportListener listener, TransportOptions options) {
         return new NettySslTransport(listener, serverLocation, options);
@@ -65,4 +122,26 @@ public class NettySslTransportTest extends NettyTcpTransportTest {
 
         return options;
     }
+
+    protected TransportSslOptions createClientOptionsTrustNone() {
+        TransportSslOptions options = TransportSslOptions.INSTANCE.clone();
+
+        options.setKeyStoreLocation(CLIENT_KEYSTORE);
+        options.setKeyStorePassword(PASSWORD);
+        options.setStoreType(KEYSTORE_TYPE);
+        options.setTrustAll(false);
+
+        return options;
+    }
+
+    protected TransportSslOptions createClientOptionsTrustAll() {
+        TransportSslOptions options = TransportSslOptions.INSTANCE.clone();
+
+        options.setKeyStoreLocation(CLIENT_KEYSTORE);
+        options.setKeyStorePassword(PASSWORD);
+        options.setStoreType(KEYSTORE_TYPE);
+        options.setTrustAll(true);
+
+        return options;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/ee509a04/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
index 94de183..833f966 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
@@ -82,7 +82,7 @@ public class NettyTcpTransportTest extends QpidJmsTestCase {
 
     @Test(timeout = 60 * 1000)
     public void testMultipleConnectionsToServer() throws Exception {
-        final int CONNECTION_COUNT = 25;
+        final int CONNECTION_COUNT = 10;
 
         try (NettyEchoServer server = new NettyEchoServer(createServerOptions())) {
             server.start();
@@ -116,7 +116,7 @@ public class NettyTcpTransportTest extends QpidJmsTestCase {
 
     @Test(timeout = 60 * 1000)
     public void testMultipleConnectionsSendReceive() throws Exception {
-        final int CONNECTION_COUNT = 25;
+        final int CONNECTION_COUNT = 10;
         final int FRAME_SIZE = 8;
 
         ByteBuf sendBuffer = Unpooled.buffer(FRAME_SIZE);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org