db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r430872 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util: BaseTestCase.java SecurityManagerSetup.java TestConfiguration.java
Date Fri, 11 Aug 2006 19:36:04 GMT
Author: djd
Date: Fri Aug 11 12:36:04 2006
New Revision: 430872

URL: http://svn.apache.org/viewvc?rev=430872&view=rev
Log:
Junit improvements - setup security manager (not yet enabled for standalone tests) to be driven
by the test configuration, add openTestResource method in BaseTestCase that works with a security
manager.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SecurityManagerSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java?rev=430872&r1=430871&r2=430872&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseTestCase.java
Fri Aug 11 12:36:04 2006
@@ -20,8 +20,9 @@
 package org.apache.derbyTesting.functionTests.util;
 
 import junit.framework.TestCase;
-import java.io.InputStream;
+
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Reader;
 import java.io.PrintStream;
 import java.net.URL;
@@ -76,10 +77,20 @@
      * setUp, tearDown methods and decorators.
      */
     public final void runBare() throws Throwable {
-    	// Not ready for prime time!
-    	// SecurityManagerSetup.installSecurityManager();
+        // still not ready for prime time
+    	//if (getTestConfiguration().defaultSecurityManagerSetup())
+    	//	assertSecurityManager();
+    	
     	super.runBare();
     }
+
+    /**
+     * Return the current configuration for the test.
+     */
+    public final TestConfiguration getTestConfiguration()
+    {
+    	return CONFIG;
+    }
     
     /**
      * Print alarm string
@@ -204,6 +215,27 @@
 		}
 	     );
     }  
+  
+    /**
+     * Open the URL for a a test resource, e.g. a policy
+     * file or a SQL script.
+     * @param url URL obtained from getTestResource
+     * @return An open stream
+    */
+    protected static InputStream openTestResource(final URL url)
+        throws PrivilegedActionException
+    {
+    	return (InputStream)AccessController.doPrivileged
+	    (new java.security.PrivilegedExceptionAction(){
+
+		    public Object run() throws IOException{
+			return url.openStream();
+
+		    }
+
+		}
+	     );    	
+    }
     
     /**
      * Assert a security manager is installed.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SecurityManagerSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SecurityManagerSetup.java?rev=430872&r1=430871&r2=430872&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SecurityManagerSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SecurityManagerSetup.java
Fri Aug 11 12:36:04 2006
@@ -77,6 +77,17 @@
 	}
 	
 	/**
+	 * Install a SecurityManager with the default test policy
+	 * file:
+	 * org/apache/derbyTesting/functionTests/util/derby_tests.policy
+	 * 
+	 */
+	static void noSecurityManager() throws PrivilegedActionException
+	{
+		installSecurityManager("<NONE>");
+	}
+	
+	/**
 	 * Install specific polciy file with the security manager
 	 * including the special case of no security manager.
 	 */
@@ -148,6 +159,10 @@
 	private static void setSecurityPolicy(Properties set,
 			String policyResource) throws PrivilegedActionException
 	{
+		if ("<NONE>".equals(policyResource)) {
+			set.setProperty("java.security.policy", policyResource);
+			return;
+		}
 		URL policyURL = BaseTestCase.getTestResource(policyResource);
 
 		if (policyURL != null)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java?rev=430872&r1=430871&r2=430872&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
Fri Aug 11 12:36:04 2006
@@ -425,5 +425,29 @@
                                     driverClass + "': " + ie.getMessage());
         }
     }
+    
+    /*
+     * SecurityManager related configuration.
+     */
+    
+    /**
+     * Install the default security manager setup,
+     * for the current configuration.
+     * @throws PrivilegedActionException 
+     */
+    boolean defaultSecurityManagerSetup() throws PrivilegedActionException {
+    	
+    	// Testing with the DB2 client has not been performed
+    	// under the security manager since it's not part
+    	// of Derby so no real interest in tracking down issues.
+    	if (jdbcClient.isDB2Client()) {
+    		SecurityManagerSetup.noSecurityManager();
+    		return false;
+    	} else {
+    		SecurityManagerSetup.installSecurityManager();
+    		return true;
+    	}
+    }
+    
         
 }



Mime
View raw message