[jboss-remoting-commits] JBoss Remoting SVN: r5890 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Sat Jul 3 13:24:44 EDT 2010


Author: ron.sigal at jboss.com
Date: 2010-07-03 13:24:44 -0400 (Sat, 03 Jul 2010)
New Revision: 5890

Added:
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistryCaller.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistrySecurityTestCase.java
Log:
JBREM-1231: New unit tests.

Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistryCaller.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistryCaller.java	                        (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistryCaller.java	2010-07-03 17:24:44 UTC (rev 5890)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * by the @author tags. 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.test.remoting.security;
+
+import java.util.Map;
+
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.ServerInvoker;
+
+/**
+ * Used by InvokerRegistrySecurityTestCase.
+ * 
+ * @author <a href="mailto:ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Jul 1, 2010
+ * </p>
+ */
+public class InvokerRegistryCaller
+{
+   public static void registerInvokerFactories(String transport, Class clientFactory, Class serverFactory)
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.registerInvokerFactories(transport, clientFactory, serverFactory);
+   }
+   
+   public static void unregisterInvokerFactories(String transport)
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.unregisterInvokerFactories(transport);
+   }
+   
+   public static void unregisterLocator(InvokerLocator locator)
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.unregisterLocator(locator);
+   }
+   
+   public static void destroyClientInvoker(InvokerLocator locator, Map map)
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.destroyClientInvoker(locator, map);
+   }   
+
+   public static void createClientInvoker(InvokerLocator locator, Map map) throws Exception
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.createClientInvoker(locator, map);
+   }
+   
+   public static void createServerInvoker(InvokerLocator locator, Map map) throws Exception
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.createServerInvoker(locator, map);
+   }
+   
+   public static void destroyServerInvoker(ServerInvoker invoker) throws Exception
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.destroyServerInvoker(invoker);
+   }
+   
+   public static void updateServerInvokerLocator(InvokerLocator locator, InvokerLocator newLocator)
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.updateServerInvokerLocator(locator, newLocator);
+   }
+   
+   public static void isSSLSupported(String transport) throws Exception
+   {
+      new Exception("InvokerRegistryCaller stacktrace").printStackTrace();
+      InvokerRegistry.isSSLSupported(transport);
+   }
+}

Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistrySecurityTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistrySecurityTestCase.java	                        (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistrySecurityTestCase.java	2010-07-03 17:24:44 UTC (rev 5890)
@@ -0,0 +1,399 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.test.remoting.security;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.transport.ClientFactory;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.ServerFactory;
+import org.jboss.remoting.transport.socket.SocketClientInvoker;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+public class InvokerRegistrySecurityTestCase extends TestCase
+{
+   private static Logger log = Logger.getLogger(InvokerRegistrySecurityTestCase.class);
+   private static boolean firstTime = true;
+
+   public void setUp() throws Exception
+   {
+      if (firstTime)
+      {
+         firstTime = false;
+         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+         PatternLayout layout = new PatternLayout(pattern);
+         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+         Logger.getRootLogger().addAppender(consoleAppender);  
+      }
+   }
+
+
+   public void tearDown()
+   {
+   }
+
+
+   public void testRegisterUnregisterInvokerFactories() throws Throwable
+   {
+      log.info("entering " + getName());
+
+      // Call from code with proper privileges.
+      InvokerRegistry.registerInvokerFactories("test", TestClientFactory.class, TestServerFactory.class);
+      InvokerRegistry.unregisterInvokerFactories("test");
+
+      // Call from code without proper privileges.
+      if (System.getSecurityManager() == null)
+      {
+         InvokerRegistryCaller.registerInvokerFactories("test", TestClientFactory.class, TestServerFactory.class);
+         InvokerRegistryCaller.unregisterInvokerFactories("test"); 
+      }
+      else
+      {
+         try
+         {
+            InvokerRegistryCaller.registerInvokerFactories("test", TestClientFactory.class, TestServerFactory.class); 
+            fail("expected SecurityException");
+         }
+         catch (SecurityException e)
+         {
+            log.info("got expected SecurityException");
+         }
+         try
+         {
+            InvokerRegistryCaller.unregisterInvokerFactories("test");
+            fail("expected SecurityException");
+         }
+         catch (SecurityException e)
+         {
+            log.info("got expected SecurityException");
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+
+   public void testUnregisterLocator() throws Throwable
+   {
+      log.info("entering " + getName());
+      Connector connector = null;
+
+      try
+      {
+         // Create server, which stores InvokerLocator in InvokerRegistry.
+         InvokerLocator locator = new InvokerLocator("socket://localhost");
+         connector = new Connector(locator);
+         connector.start();
+         InvokerLocator updatedLocator = connector.getLocator();
+
+         // Call from code with proper privileges.
+         InvokerRegistry.unregisterLocator(updatedLocator);
+
+         // Call from code without proper privileges.
+         if (System.getSecurityManager() == null)
+         {
+            InvokerRegistryCaller.unregisterLocator(updatedLocator);  
+         }
+         else
+         {
+            try
+            {
+               InvokerRegistryCaller.unregisterLocator(updatedLocator); 
+               fail("expected SecurityException");
+            }
+            catch (SecurityException e)
+            {
+               log.info("got expected SecurityException");
+            }
+         }
+      }
+      finally
+      {
+         if (connector != null)
+         {
+            connector.stop();
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+
+   public void testDestroyClientInvoker() throws Throwable
+   {
+      log.info("entering " + getName());
+      Client client = null;
+
+      try
+      {
+         // Create client.
+         InvokerLocator locator = new InvokerLocator("socket://localhost");
+         client = new Client(locator);
+         client.connect();
+
+         // Call from code with proper privileges.
+         InvokerRegistry.destroyClientInvoker(locator, new HashMap());
+
+         // Call from code without proper privileges.
+         if (System.getSecurityManager() == null)
+         {
+            InvokerRegistryCaller.destroyClientInvoker(locator, new HashMap()); 
+         }
+         else
+         {
+            try
+            {
+               InvokerRegistryCaller.destroyClientInvoker(locator, new HashMap()); 
+               fail("expected SecurityException");
+            }
+            catch (SecurityException e)
+            {
+               log.info("got expected SecurityException");
+            }
+         }
+      }
+      finally
+      {
+         if (client != null)
+         {
+            client.disconnect();
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+
+   public void testCreateClientInvoker() throws Throwable
+   {
+      log.info("entering " + getName());
+      InvokerLocator locator = new InvokerLocator("socket://localhost");
+
+      // Call from code with proper privileges.
+      ClientInvoker invoker = InvokerRegistry.createClientInvoker(locator, new HashMap());;
+
+      try
+      {
+         // Call from code without proper privileges.
+         if (System.getSecurityManager() == null)
+         {
+            InvokerRegistryCaller.createClientInvoker(locator, new HashMap());
+         }
+         else
+         {
+            try
+            {
+               InvokerRegistryCaller.createClientInvoker(locator, new HashMap());
+               fail("expected SecurityException");
+            }
+            catch (SecurityException e)
+            {
+               log.info("got expected SecurityException");
+            }
+         }
+      }
+      finally
+      {
+         if (invoker != null)
+         {
+            InvokerRegistry.destroyClientInvoker(locator, new HashMap());
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+
+   public void testCreateServerInvoker() throws Throwable
+   {
+      log.info("entering " + getName());
+      InvokerLocator locator = new InvokerLocator("socket://localhost");
+
+      // Call from code with proper privileges.
+      ServerInvoker invoker = InvokerRegistry.createServerInvoker(locator, new HashMap());;
+
+      try
+      {
+         // Call from code without proper privileges.
+         if (System.getSecurityManager() == null)
+         {
+            InvokerRegistryCaller.createServerInvoker(locator, new HashMap());
+         }
+         else
+         {
+            try
+            {
+               InvokerRegistryCaller.createServerInvoker(locator, new HashMap());
+               fail("expected SecurityException");
+            }
+            catch (SecurityException e)
+            {
+               log.info("got expected SecurityException");
+            }
+         }
+      }
+      finally
+      {
+         if (invoker != null)
+         {
+            InvokerRegistry.destroyServerInvoker(invoker);
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+
+   public void testDestroyServerInvoker() throws Throwable
+   {
+      log.info("entering " + getName());
+      InvokerLocator locator = new InvokerLocator("socket://localhost");
+      ServerInvoker invoker = InvokerRegistry.createServerInvoker(locator, new HashMap());;
+
+      // Call from code with proper privileges.
+      InvokerRegistry.destroyServerInvoker(invoker);
+
+      // Call from code without proper privileges.
+      if (System.getSecurityManager() == null)
+      {
+         InvokerRegistryCaller.destroyServerInvoker(invoker);
+      }
+      else
+      {
+         try
+         {
+            InvokerRegistryCaller.destroyServerInvoker(invoker);
+            fail("expected SecurityException");
+         }
+         catch (SecurityException e)
+         {
+            log.info("got expected SecurityException");
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+
+   public void testUpdateServerInvokerLocator() throws Throwable
+   {
+      log.info("entering " + getName());
+      InvokerLocator oldLocator = new InvokerLocator("socket://localhost");
+      InvokerLocator newLocator = new InvokerLocator("socket://localhost");
+      ServerInvoker invoker = InvokerRegistry.createServerInvoker(oldLocator, new HashMap());;
+
+      try 
+      {
+         // Call from code with proper privileges.
+         InvokerRegistry.updateServerInvokerLocator(oldLocator, newLocator);
+
+         // Call from code without proper privileges.
+         if (System.getSecurityManager() == null)
+         {
+            InvokerRegistryCaller.updateServerInvokerLocator(oldLocator, newLocator);
+         }
+         else
+         {
+            try
+            {
+               InvokerRegistryCaller.updateServerInvokerLocator(oldLocator, newLocator);
+               fail("expected SecurityException");
+            }
+            catch (SecurityException e)
+            {
+               log.info("got expected SecurityException");
+            }
+         }
+      }
+      finally
+      {
+         if (invoker != null)
+         {
+            InvokerRegistry.destroyServerInvoker(invoker);
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+
+   public void testIsSSLSupported() throws Throwable
+   {
+      log.info("entering " + getName());
+
+      // Call from code with proper privileges.
+      InvokerRegistry.isSSLSupported("bisocket");
+
+      // Call from code without proper privileges.
+      if (System.getSecurityManager() == null)
+      {
+         InvokerRegistryCaller.isSSLSupported("http");
+      }
+      else
+      {
+         try
+         {
+            InvokerRegistryCaller.isSSLSupported("http");
+            fail("expected SecurityException");
+         }
+         catch (SecurityException e)
+         {
+            log.info("got expected SecurityException");
+         }
+      }
+
+      log.info(getName() + " PASSES");
+   }
+   
+   static class TestServerFactory implements ServerFactory
+   {
+      public ServerInvoker createServerInvoker(InvokerLocator locator, Map config)
+      {
+         return new SocketServerInvoker(locator, config);
+      }
+      public boolean supportsSSL()
+      {
+         return false;
+      }
+   }
+
+   static class TestClientFactory implements ClientFactory
+   {
+      public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
+      {
+         return new SocketClientInvoker(locator, config);
+      }
+      public boolean supportsSSL()
+      {
+         return false;
+      }
+   }
+}
\ No newline at end of file


Property changes on: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/security/InvokerRegistrySecurityTestCase.java
___________________________________________________________________
Name: svn:executable
   + *



More information about the jboss-remoting-commits mailing list