portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/test/org/apache/jetspeed/services/security/registry TestSecurityCaching.java
Date Mon, 03 May 2004 22:23:47 GMT
taylor      2004/05/03 15:23:47

  Added:       src/test/org/apache/jetspeed/services/security/registry
                        TestSecurityCaching.java
  Log:
  New unit test for testing AccessController Security Cache
  Used in finding bugs for 
  
  http://nagoya.apache.org/jira/browse/JS1-466
  
  PR:
  Obtained from:
  Submitted by:	
  Reviewed by:	
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/test/org/apache/jetspeed/services/security/registry/TestSecurityCaching.java
  
  Index: TestSecurityCaching.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.services.security.registry;
  
  import java.util.Vector;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.awtui.TestRunner;
  
  import org.apache.jetspeed.om.registry.SecurityAccess;
  import org.apache.jetspeed.om.registry.SecurityAllow;
  import org.apache.jetspeed.om.registry.SecurityEntry;
  import org.apache.jetspeed.om.registry.base.BaseSecurityAccess;
  import org.apache.jetspeed.om.registry.base.BaseSecurityAllow;
  import org.apache.jetspeed.om.registry.base.BaseSecurityEntry;
  import org.apache.jetspeed.test.JetspeedTestCase;
  
  /**
   * TestSecurityCaching
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: TestSecurityCaching.java,v 1.1 2004/05/03 22:23:47 taylor Exp $
   */
  public class TestSecurityCaching extends JetspeedTestCase
  {    
      public TestSecurityCaching( String name )
      {
          super( name );
      }
      
      public static void main(String args[])
      {
          TestRunner.main( new String[]
          { TestSecurityCaching.class.getName() } );
      }
      
      public void setUp()
      {
          System.out.println("Setup: ");
      }
      
      public void tearDown()
      {
          System.out.println("Teardown");
      }
      
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite()
      {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite( TestSecurityCaching.class );
      }
      
      public void testGroupCache()
      throws Exception
      {
          System.out.println("Testing Group Security Registry Cache...");
          
          SecurityEntry entry = createSecurityEntry("test-group-security");
          entry.grantGroupAccess("view", "users");
          entry.grantGroupAccess("view", "hackers");
          entry.grantGroupAccess("edit", "managers");
          entry.grantGroupAccess("view", "managers");
          
          assertTrue("group-assert: view/users", entry.allowsGroup("users", "view"));
          assertTrue("group-assert: view/hackers", entry.allowsGroup("hackers", "view"));
          assertTrue("group-assert: view/managers", entry.allowsGroup("managers", "view"));
          assertTrue("group-assert: edit/managers", entry.allowsGroup("managers", "edit"));
          
          assertTrue("false group-assert: edit/hackers", !entry.allowsGroup("hackers", "edit"));
          
          entry.revokeGroupAccess("view", "hackers");
  
          assertTrue("false group-revoked-assert: view/hackers", !entry.allowsGroup("hackers",
"view"));
          assertTrue("group-assert: view/users", entry.allowsGroup("users", "view"));
  
          assertTrue("group-specific: view/managers", entry.allowsSpecificGroup("view", "managers"));
          
          System.out.println("Security Group Registry Cache Test done.");        
      }
  
      private SecurityEntry createSecurityEntry(String name)
      {
          BaseSecurityEntry securityEntry = new BaseSecurityEntry();
          securityEntry.setName(name);
          return securityEntry;        
      }
      
      public void testRoleCache()
      throws Exception
      {
          System.out.println("Testing Role Security Registry Cache...");
          
          SecurityEntry entry = createSecurityEntry("test-role-security");
          entry.grantRoleAccess("view", "users");
          entry.grantRoleAccess("view", "hackers");
          entry.grantRoleAccess("edit", "managers");
          entry.grantRoleAccess("view", "managers");
          
          assertTrue("Role-assert: view/users", entry.allowsRole("users", "view"));
          assertTrue("Role-assert: view/hackers", entry.allowsRole("hackers", "view"));
          assertTrue("Role-assert: view/managers", entry.allowsRole("managers", "view"));
          assertTrue("Role-assert: edit/managers", entry.allowsRole("managers", "edit"));
          
          assertTrue("false Role-assert: edit/hackers", !entry.allowsRole("hackers", "edit"));
          
          entry.revokeRoleAccess("view", "hackers");
  
          assertTrue("false Role-revoked-assert: view/hackers", !entry.allowsRole("hackers",
"view"));
          assertTrue("Role-assert: view/users", entry.allowsRole("users", "view"));
  
          assertTrue("Role-specific: view/managers", entry.allowsSpecificRole("view", "managers"));
          
          System.out.println("Security Role Registry Cache Test done.");        
      }
  
      public void testUserCache()
      throws Exception
      {
          System.out.println("Testing User Security Registry Cache...");
          
          SecurityEntry entry = createSecurityEntry("test-user-security");
          entry.grantUserAccess("view", "joey");
          entry.grantUserAccess("view", "deedee");
          entry.grantUserAccess("edit", "johnny");
          entry.grantUserAccess("view", "johnny");
          
          assertTrue("User-assert: view/joey", entry.allowsUser("joey", "view"));
          assertTrue("User-assert: view/deedee", entry.allowsUser("deedee", "view"));
          assertTrue("User-assert: view/johnny", entry.allowsUser("johnny", "view"));
          assertTrue("User-assert: edit/johnny", entry.allowsUser("johnny", "edit"));
          
          assertTrue("false User-assert: edit/deedee", !entry.allowsUser("deedee", "edit"));
          
          entry.revokeUserAccess("view", "deedee");
  
          assertTrue("false User-revoked-assert: view/deedee", !entry.allowsUser("deedee",
"view"));
          assertTrue("User-assert: view/joey", entry.allowsUser("joey", "view"));
  
          assertTrue("User-specific: view/johnny", entry.allowsSpecificUser("view", "johnny"));
          
          System.out.println("Security User Registry Cache Test done.");        
      }
      
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message