[jboss-cvs] JBoss Messaging SVN: r3815 - in trunk/tests/src/org/jboss/messaging/core/remoting: ssl and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 27 08:24:07 EST 2008


Author: jmesnil
Date: 2008-02-27 08:24:07 -0500 (Wed, 27 Feb 2008)
New Revision: 3815

Added:
   trunk/tests/src/org/jboss/messaging/core/remoting/ssl/
   trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/
   trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java
   trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java
Log:
* rewrote SSL tests using JBM 2 core API (instead of JMS)

Added: trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java	2008-02-27 13:24:07 UTC (rev 3815)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.remoting.ssl.integration;
+
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+import static org.jboss.messaging.core.remoting.ssl.integration.CoreClientOverSSLTest.MESSAGE_TEXT_FROM_CLIENT;
+import static org.jboss.messaging.core.remoting.ssl.integration.CoreClientOverSSLTest.QUEUE;
+
+import java.util.Arrays;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessageImpl;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+
+/**
+ * This client will open a connection, send a message to a queue over SSL and
+ * exit.
+ * 
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class CoreClientOverSSL
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(CoreClientOverSSL.class);
+
+   // Static --------------------------------------------------------
+
+   public static void main(String[] args)
+   {
+      try
+      {
+         log.info("args = " + Arrays.asList(args));
+
+         if (args.length != 3)
+         {
+            log.fatal("unexpected number of args (should be 3)");
+            System.exit(1);
+         }
+
+         boolean sslEnabled = Boolean.parseBoolean(args[0]);
+         String keyStorePath = args[1];
+         String keyStorePassword = args[2];
+
+         RemotingConfiguration remotingConf = new RemotingConfiguration(TCP,
+               "localhost", CoreClientOverSSLTest.SSL_PORT);
+         remotingConf.setSSLEnabled(sslEnabled);
+         remotingConf.setKeyStorePath(keyStorePath);
+         remotingConf.setKeyStorePassword(keyStorePassword);
+
+         // FIXME there should be another way to get a meaningful Version on the
+         // client side...
+         MessagingServer server = new MessagingServerImpl();
+         ClientConnectionFactory cf = new ClientConnectionFactoryImpl(0,
+               remotingConf, server.getVersion(), false, 0);
+         ClientConnection conn = cf.createConnection(null, null);
+         ClientSession session = conn.createClientSession(false, true, true, 0,
+               false);
+         ClientProducer producer = session.createProducer(QUEUE);
+
+         MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
+               System.currentTimeMillis(), (byte) 1);
+         message.setPayload(MESSAGE_TEXT_FROM_CLIENT.getBytes());
+         producer.send(message);
+
+         conn.close();
+
+         System.exit(0);
+      } catch (Throwable t)
+      {
+         log.error(t.getMessage(), t);
+         System.exit(1);
+      }
+   }
+
+   // Attributes ----------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Added: trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java	2008-02-27 13:24:07 UTC (rev 3815)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.remoting.ssl.integration;
+
+import static java.lang.Boolean.FALSE;
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
+import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.test.messaging.jms.SerializedClientSupport;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision: 3716 $</tt>
+ * 
+ */
+public class CoreClientOverSSLTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   public static final String MESSAGE_TEXT_FROM_CLIENT = "CoreClientOverSSLTest from client";
+   public static final String QUEUE = "QueueOverSSL";
+   public static final int SSL_PORT = 5402;
+
+   // Static --------------------------------------------------------
+
+   private static final Logger log = Logger
+         .getLogger(CoreClientOverSSLTest.class);
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingServer server;
+
+   private ClientConnection connection;
+
+   private ClientConsumer consumer;
+   
+   // Constructors --------------------------------------------------
+
+   public CoreClientOverSSLTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+
+   public void testSSL() throws Exception
+   {
+      Process p = SerializedClientSupport.spawnVM(CoreClientOverSSL.class
+            .getName(), Boolean.TRUE.toString(), "messaging.keystore",
+            "secureexample");
+
+      Message m = consumer.receive(10000);
+      assertNotNull(m);
+      assertEquals(MESSAGE_TEXT_FROM_CLIENT, new String(m.getPayload()));
+
+      log.info("waiting for the client VM to exit ...");
+      p.waitFor();
+
+      assertEquals(0, p.exitValue());
+   }
+
+   public void testSSLWithIncorrectKeyStorePassword() throws Exception
+   {
+      Process p = SerializedClientSupport.spawnVM(CoreClientOverSSL.class
+            .getName(), Boolean.TRUE.toString(), "messaging.keystore",
+            "incorrectKeyStorePassword");
+
+      Message m = consumer.receive(5000);
+      assertNull(m);
+
+      log.info("waiting for the client VM to exit ...");
+      p.waitFor();
+
+      // client VM must have exited on an error
+      assertNotSame(0, p.exitValue());
+   }
+
+   public void testPlainConnectionToSSLEndpoint() throws Exception
+   {
+      Process p = SerializedClientSupport.spawnVM(CoreClientOverSSL.class
+            .getName(), FALSE.toString(), null, null);
+
+      Message m = consumer.receive(5000);
+      assertNull(m);
+
+      log.info("waiting for the client VM to exit ...");
+      p.waitFor();
+
+      // client VM must have exited on an error
+      assertNotSame(0, p.exitValue());
+   }
+
+   // Package protected ---------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      RemotingConfiguration remotingConf = new RemotingConfiguration(TCP,
+            "localhost", SSL_PORT);
+      remotingConf.setSSLEnabled(true);
+      remotingConf.setKeyStorePath("messaging.keystore");
+      remotingConf.setKeyStorePassword("secureexample");
+      remotingConf.setTrustStorePath("messaging.truststore");
+      remotingConf.setTrustStorePassword("secureexample");
+
+      server = new MessagingServerImpl(remotingConf);
+      server.start();
+
+      ClientConnectionFactory cf = new ClientConnectionFactoryImpl(0,
+            remotingConf, server.getVersion(), false, 0);
+      connection = cf.createConnection(null, null);
+      ClientSession session = connection.createClientSession(false, true, true,
+            0, false);
+      session.createQueue(QUEUE, QUEUE, null, false, false);
+      consumer = session.createConsumer(QUEUE, null, false, false, true);
+      connection.start();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      consumer.close();
+      connection.close();
+
+      server.stop();
+
+      super.tearDown();
+   }
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list