[exo-jcr-commits] exo-jcr SVN: r2549 - kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jun 11 04:59:54 EDT 2010


Author: natasha.vakulenko
Date: 2010-06-11 04:59:52 -0400 (Fri, 11 Jun 2010)
New Revision: 2549

Added:
   kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/AbstractSecureCollectionsTest.java
   kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsList.java
   kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsSet.java
   kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecutiryManager.java
Removed:
   kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollections.java
Log:
EXOJCR-770: Tests were added to the popular methods of list and set in the files TestSecureCollectionList.java and TestSecureCollectionSet.java. File TestSecureCollection.java was replaced by AbstractSecureCollectionsTest, which contains abstract parent class for previous tests.
Test testSecurityManagerExists moved from file TestSecureCollection.java to file SecurityManagerTest.java.

Added: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/AbstractSecureCollectionsTest.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/AbstractSecureCollectionsTest.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/AbstractSecureCollectionsTest.java	2010-06-11 08:59:52 UTC (rev 2549)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.commons.utils.secure;
+
+import junit.framework.TestCase;
+
+import java.net.URL;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.Permissions;
+import java.security.PrivilegedExceptionAction;
+import java.security.ProtectionDomain;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: TestSecureSet.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ */
+
+public abstract class AbstractSecureCollectionsTest extends TestCase
+{
+   // permission for testing purposes
+   public static final Permission MODIFY_PERMISSION = new RuntimePermission("modifyPermisssion");
+
+   /**
+    * Run privileged action with given privileges.
+    */
+   protected <T> T doActionWithPermissions(PrivilegedExceptionAction<T> action, Permission... permissions)
+      throws Exception
+   {
+      Permissions allPermissions = new Permissions();
+      for (Permission permission : permissions)
+      {
+         if (permission != null)
+         {
+            allPermissions.add(permission);
+         }
+      }
+      ProtectionDomain[] protectionDomains =
+         new ProtectionDomain[]{new ProtectionDomain(new CodeSource(getCodeSource(),
+            (java.security.cert.Certificate[])null), allPermissions)};
+      return AccessController.doPrivileged(action, new AccessControlContext(protectionDomains));
+   }
+
+   protected URL getCodeSource()
+   {
+      return getClass().getProtectionDomain().getCodeSource().getLocation();
+   }
+}


Property changes on: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/AbstractSecureCollectionsTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollections.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollections.java	2010-06-11 08:50:27 UTC (rev 2548)
+++ kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollections.java	2010-06-11 08:59:52 UTC (rev 2549)
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * 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.exoplatform.commons.utils.secure;
-
-import junit.framework.TestCase;
-
-import java.net.URL;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.CodeSource;
-import java.security.Permission;
-import java.security.Permissions;
-import java.security.PrivilegedExceptionAction;
-import java.security.ProtectionDomain;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: TestSecureSet.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public class TestSecureCollections extends TestCase
-{
-   // permission for testing purposes
-   public static final Permission MODIFY_PERMISSION = new RuntimePermission("modifyPermisssion");
-
-   public void testSecurityManagerExists()
-   {
-      // check if SM is installed
-      assertNotNull("Security Manager is not installed", System.getSecurityManager());
-   }
-
-   public void testSecureSetAddPermitted()
-   {
-      final Set<String> set = SecureCollections.secureSet(new HashSet<String>(), MODIFY_PERMISSION);
-      try
-      {
-         // giving MODIFY_PERMISSION
-         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               set.add("string");
-               return null;
-            }
-         }, MODIFY_PERMISSION);
-      }
-      catch (Exception e)
-      {
-         fail("Modification should be permitted.");
-      }
-   }
-
-   public void testSecureSetAddDenied()
-   {
-      final Set<String> set = SecureCollections.secureSet(new HashSet<String>(), MODIFY_PERMISSION);
-      try
-      {
-         // giving no permissions
-         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
-         {
-            public Object run() throws Exception
-            {
-               set.add("string");
-               return null;
-            }
-         });
-         fail("Modification should be denied.");
-      }
-      catch (Exception e)
-      {
-      }
-   }
-
-   /**
-    * Run privileged action with given privileges.
-    */
-   private <T> T doActionWithPermissions(PrivilegedExceptionAction<T> action, Permission... permissions)
-      throws Exception
-   {
-      Permissions allPermissions = new Permissions();
-      for (Permission permission : permissions)
-      {
-         if (permission != null)
-         {
-            allPermissions.add(permission);
-         }
-      }
-      ProtectionDomain[] protectionDomains =
-         new ProtectionDomain[]{new ProtectionDomain(new CodeSource(getCodeSource(),
-            (java.security.cert.Certificate[])null), allPermissions)};
-      return AccessController.doPrivileged(action, new AccessControlContext(protectionDomains));
-   }
-
-   private URL getCodeSource()
-   {
-      return getClass().getProtectionDomain().getCodeSource().getLocation();
-   }
-}

Added: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsList.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsList.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsList.java	2010-06-11 08:59:52 UTC (rev 2549)
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils.secure;
+
+import java.security.Permission;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.ListIterator;
+
+/**
+ * @author <a href="mailto:natasha.vakulenko at gmail.com">Natasha Vakulenko</a>
+ * @version $Revision$
+ */
+
+public class TestSecureCollectionsList extends AbstractSecureCollectionsTest
+{
+   private List<String> list = SecureCollections.secureList(new ArrayList<String>(), MODIFY_PERMISSION);
+
+   /**
+    * establishment of protected list prior to each test 
+    */
+   protected void setUp()
+   {
+      list = SecureCollections.secureList(new ArrayList<String>(), MODIFY_PERMISSION);
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               list.add("firstString");
+               list.add("secondString");
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   /**
+    * cleaning protected list after each test
+    */
+
+   protected void tearDown()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               list.clear();
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   public void testSecureListAddDenied()
+   {
+      try
+      {
+         // giving no permissions
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               list.add("string");
+               return null;
+            }
+         });
+         fail("Modification should be denied.");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   public void testSecureListAddPermitted()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               list.add(0, "string");
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+         fail("Modification should be permitted.");
+      }
+   }
+
+   public void testSecureListClearDenied()
+   {
+      try
+      {
+         // giving no permissions
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               list.clear();
+               return null;
+            }
+         });
+         fail("Modification should be denied.");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   public void testSecureListIteratorPermitted()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               ListIterator<String> it = list.listIterator();
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+         fail("Modification should be permitted.");
+      }
+   }
+
+   public void testSecureListRemoveDenied()
+   {
+      try
+      {
+         // giving no permissions
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               list.remove(0);
+               return null;
+            }
+         });
+         fail("Modification should be denied.");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   public void testSecureIteratorPermitted()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               Iterator<String> it = list.iterator();
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+         fail("Modification should be permitted.");
+      }
+   }
+}


Property changes on: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsList.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsSet.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsSet.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsSet.java	2010-06-11 08:59:52 UTC (rev 2549)
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils.secure;
+
+import java.security.Permissions;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:natasha.vakulenko at gmail.com">Natasha Vakulenko</a>
+ * @version $Revision$
+ */
+
+public class TestSecureCollectionsSet extends AbstractSecureCollectionsTest
+{
+   private Set<String> set;
+
+   /**
+    * establishment of protected set prior to each test 
+    */
+   protected void setUp()
+   {
+      set = SecureCollections.secureSet(new HashSet<String>(), MODIFY_PERMISSION);
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               set.add("firstString");
+               set.add("secondString");
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   /**
+    * cleaning protected set after each test
+    */
+   protected void tearDown()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               set.clear();
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   public void testSecureSetAddPermitted()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               set.add("string");
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+         fail("Modification should be permitted.");
+      }
+   }
+
+   public void testSecureSetAddDenied()
+   {
+      try
+      {
+         // giving no permissions
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               set.add("string");
+               return null;
+            }
+         });
+         fail("Modification should be denied.");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   public void testSecureSetRemoveDenied()
+   {
+      try
+      {
+         // giving no permissions
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               set.remove(0);
+               return null;
+            }
+         });
+         fail("Modification should be denied.");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+
+   public void testSecureSetRemovePermitted()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               set.remove(0);
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+         fail("Modification should be permitted.");
+      }
+   }
+
+   public void testSecureSetIteratorPermitted()
+   {
+      try
+      {
+         // giving MODIFY_PERMISSION
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               Iterator<String> iterator = set.iterator();
+               return null;
+            }
+         }, MODIFY_PERMISSION);
+      }
+      catch (Exception e)
+      {
+         fail("Modification should be permitted.");
+      }
+   }
+
+   public void testSecureSetClearDenied()
+   {
+      try
+      {
+         // giving no permissions
+         doActionWithPermissions(new PrivilegedExceptionAction<Object>()
+         {
+            public Object run() throws Exception
+            {
+               set.clear();
+               return null;
+            }
+         });
+         fail("Modification should be denied.");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+}


Property changes on: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecureCollectionsSet.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecutiryManager.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecutiryManager.java	                        (rev 0)
+++ kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecutiryManager.java	2010-06-11 08:59:52 UTC (rev 2549)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.commons.utils.secure;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: TestSecureSet.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ */
+
+public class TestSecutiryManager extends TestCase
+{
+
+   public void testSecurityManagerExists()
+   {
+      // check if SM is installed
+      assertNotNull("Security Manager is not installed", System.getSecurityManager());
+   }
+}


Property changes on: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/secure/TestSecutiryManager.java
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the exo-jcr-commits mailing list