db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r365776 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: harness/ master/ suites/ tests/nist/ util/
Date Tue, 03 Jan 2006 23:59:14 GMT
Author: djd
Date: Tue Jan  3 15:59:10 2006
New Revision: 365776

URL: http://svn.apache.org/viewcvs?rev=365776&view=rev
Log:
DERBY-615 Make RunTest install a SecurityManager when using useprocess=false.
Add a utility SQL test function to indicate if a SecurityManager is installed.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/jvm.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/databaseProperties.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dml160.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/nist.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/nist/dml160.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestRoutines.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/testRoutines.sql

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/RunTest.java
Tue Jan  3 15:59:10 2006
@@ -2286,6 +2286,9 @@
     	PrintStream ps = new PrintStream(new FileOutputStream(pathStr), true);
     	System.setOut(ps);
     	System.setErr(ps);
+    	
+    	// Install a security manager within this JVM for this test.
+    	boolean installedSecurityManager = installSecurityManager();
     	if (testType.equals("sql"))
     	{
     	    String[] ijarg = new String[3];
@@ -2408,6 +2411,9 @@
         }
         
         ps.close();
+        
+        if (installedSecurityManager)
+        	System.setSecurityManager(null);
         // Reset System.out and System.err
         System.setOut(stdout);
         System.setErr(stderr);
@@ -2464,6 +2470,56 @@
         //System.out.println(tmp);
         
         return tmp;
+    }
+    
+    /**
+     * Install the default security manager in this JVM for this
+     * test, used when useprocess is false.
+     * @return
+     * @throws ClassNotFoundException
+     * @throws IOException
+     */
+    private static boolean installSecurityManager() throws ClassNotFoundException, IOException
+    {
+    	boolean installedSecurityManager = false;
+    	// Set up the SecurityManager in this JVM for this test.
+    	boolean haveSecurityManagerAlready = System.getSecurityManager() != null;
+        if (runWithoutSecurityManager)
+        {
+        	// Test doesn't run with a SecurityManager but there's
+        	// a chance that a previous test will have installed one.
+        	// Currently when running with useProcess=false we install
+        	// the SecurityManager on the first test that requires it
+        	// and leave it there.
+        	if (haveSecurityManagerAlready)
+        		System.out.println(
+        				"noSecurityManager=true,useProcess=false but SecurityManager installed by previous
test");
+        	else
+        	    System.out.println("-- SecurityManager not installed --");
+        }     
+        else if (!haveSecurityManagerAlready)
+    	{
+        	// Get the set of -D options that would be needed
+        	// for a spawned VM and convert them to system properties.
+    	    Vector propList = jvm.getSecurityProps(null);
+    	    for (Enumeration e = propList.elements(); e.hasMoreElements();)
+    	    {
+    	    	String dashDOpt = (String) e.nextElement();
+    	    	if ("java.security.manager".equals(dashDOpt))
+    	    		continue;
+    	    	
+    	    	int eq = dashDOpt.indexOf("=");
+    	    	String key = dashDOpt.substring(0, eq);
+    	    	String value = dashDOpt.substring(eq + 1);
+    	    	
+    	    	System.setProperty(key, value);
+    	    	
+     	    }
+		    System.setSecurityManager(new SecurityManager());
+		    installedSecurityManager = true;
+    	}
+        
+        return installedSecurityManager;
     }
 
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/jvm.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/jvm.java?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/jvm.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/harness/jvm.java
Tue Jan  3 15:59:10 2006
@@ -23,6 +23,8 @@
 import java.util.Vector;
 import java.util.StringTokenizer;
 import java.io.File;
+import java.io.IOException;
+
 import org.apache.derby.impl.tools.sysinfo.ZipInfoProperties;
 
 
@@ -324,9 +326,15 @@
 	 * set up security properties for server command line.
 	 */
 	protected void setSecurityProps() throws java.io.IOException, ClassNotFoundException
+	{		
+		D = jvm.getSecurityProps(D);
+		
+	}
+	
+	static Vector getSecurityProps(Vector D) throws ClassNotFoundException, IOException
 	{
-		if (this.D == null)
-			this.D = new Vector();
+		if (D == null)
+			D = new Vector();
 		
 		String userDir = System.getProperty("user.dir");
 		String policyFile = System.getProperty("serverPolicyFile");
@@ -358,27 +366,29 @@
 							   "serverPolicy(" + policyFile + 
 							   ") or serverCodeBase(" +  serverCodeBase + 
 							   ") not available");
-		return;
+		return D;
 		}
 		
-		this.D.addElement("java.security.manager");
-		this.D.addElement("java.security.policy=" + policyFile);
+		D.addElement("java.security.manager");
+		D.addElement("java.security.policy=" + pf.getAbsolutePath());
 		
 		String codebaseType = isJar[0] ? "csinfo.codejar" : "csinfo.codeclasses";
 		String unusedType = isJar[0] ? "csinfo.codeclasses" : "csinfo.codejar";
 
 		// URL of the codebase
-		this.D.addElement(codebaseType + "=" + cb.toURL());
+		D.addElement(codebaseType + "=" + cb.toURL());
 		// file path to the codebase
-		this.D.addElement("csinfo.codedir=" + cb.getAbsolutePath());
+		D.addElement("csinfo.codedir=" + cb.getAbsolutePath());
 		String hostName = (System.getProperty("hostName"));
 		if (hostName == null)
 			hostName="localhost";
-		this.D.addElement("csinfo.serverhost=" + hostName);
-		this.D.addElement("csinfo.trustedhost=" + hostName);	 
+		D.addElement("csinfo.serverhost=" + hostName);
+		D.addElement("csinfo.trustedhost=" + hostName);	 
 		
 		// add an invalid path to the unused type 
-		this.D.addElement(unusedType + "=file://unused/");
+		D.addElement(unusedType + "=file://unused/");
+		
+		return D;
 		
 	}
 
@@ -386,7 +396,7 @@
 	 * @param resourceName (e.g. /org/apache/derbyTesting/functionTests/util/nwsvr.policy)
 	 * @return short name (e.g. nwsvr.policy)
 	 */
-	private String baseName(String resourceName)
+	private static String baseName(String resourceName)
 	{
 	  
 		return resourceName.substring(resourceName.lastIndexOf("/"),resourceName.length());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/databaseProperties.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/databaseProperties.out?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/databaseProperties.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/databaseProperties.out
Tue Jan  3 15:59:10 2006
@@ -5,6 +5,8 @@
 0 rows inserted/updated/deleted
 ij> CREATE PROCEDURE TESTROUTINE.SLEEP(IN SLEEP_TIME_MS BIGINT) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.sleep'
language java parameter style java;
 0 rows inserted/updated/deleted
+ij> CREATE FUNCTION TESTROUTINE.HAS_SECURITY_MANAGER() RETURNS INT NO SQL EXTERNAL NAME
'org.apache.derbyTesting.functionTests.util.TestRoutines.hasSecurityManager' language java
parameter style java;
+0 rows inserted/updated/deleted
 ij> CREATE FUNCTION GET_TABLE_PROPERTY (SCHEMA_NAME VARCHAR(128), TABLE_NAME VARCHAR(128),
PROP_KEY VARCHAR(1000)) RETURNS VARCHAR(1000) EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestPropertyInfo.getTableProperty'
LANGUAGE JAVA PARAMETER STYLE JAVA;
 0 rows inserted/updated/deleted
 ij> -- Get a property that hasn't been set yet - should return null

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dml160.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dml160.out?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dml160.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dml160.out
Tue Jan  3 15:59:10 2006
@@ -272,5 +272,18 @@
 --O-- END TEST >>> 0860 <<< END TEST
 --O-- *********************************************
 --O-- *************************************************////END-OF-MODULE
-;
+-- Simple addition to check the test has a security manager installed.
+run resource '/org/apache/derbyTesting/functionTests/util/testRoutines.sql';
+ij> -- Changed to create individual procedures so that this will work with JSR169. 
+-- Direct call to 'installRoutines' uses nested connection
+CREATE PROCEDURE TESTROUTINE.SET_SYSTEM_PROPERTY(IN PROPERTY_KEY VARCHAR(32000), IN PROPERTY_VALUE
VARCHAR(32000)) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.setSystemProperty'
language java parameter style java;
+0 rows inserted/updated/deleted
+ij> CREATE PROCEDURE TESTROUTINE.SLEEP(IN SLEEP_TIME_MS BIGINT) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.sleep'
language java parameter style java;
+0 rows inserted/updated/deleted
+ij> CREATE FUNCTION TESTROUTINE.HAS_SECURITY_MANAGER() RETURNS INT NO SQL EXTERNAL NAME
'org.apache.derbyTesting.functionTests.util.TestRoutines.hasSecurityManager' language java
parameter style java;
+0 rows inserted/updated/deleted
+ij> values TESTROUTINE.HAS_SECURITY_MANAGER();
+1          
+-----------
+1          
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/nist.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/nist.properties?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/nist.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/nist.properties
Tue Jan  3 15:59:10 2006
@@ -1,4 +1,3 @@
-db2j.database.mode=DB2
 usesystem=nist
 useprocess=false
 keepfiles=true

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/nist/dml160.sql
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/nist/dml160.sql?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/nist/dml160.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/nist/dml160.sql
Tue Jan  3 15:59:10 2006
@@ -278,3 +278,7 @@
 --O-- END TEST >>> 0860 <<< END TEST
 --O-- *********************************************
 --O-- *************************************************////END-OF-MODULE
+
+-- Simple addition to check the test has a security manager installed.
+run resource '/org/apache/derbyTesting/functionTests/util/testRoutines.sql';
+values TESTROUTINE.HAS_SECURITY_MANAGER();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestRoutines.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestRoutines.java?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestRoutines.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestRoutines.java
Tue Jan  3 15:59:10 2006
@@ -64,6 +64,8 @@
 		// sleep
 		s.execute("CREATE PROCEDURE TESTROUTINE.SLEEP(IN SLEEP_TIME_MS BIGINT) NO SQL EXTERNAL
NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.sleep' language java parameter
style java");
 
+		s.execute("CREATE FUNCTION TESTROUTINE.HAS_SECURITY_MANAGER() RETURNS INT NO SQL EXTERNAL
NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.hasSecurityManager' language
java parameter style java");
+
 		s.close();
 	}
 
@@ -93,6 +95,16 @@
 	public static void sleep(long ms) throws InterruptedException {
 
 		Thread.sleep(ms);
+	}
+	
+	/**
+	 * TESTROUTINE.HAS_SECURITY_MANAGER()
+	 * Return 0 is no security manager is installed, 1 if one is.
+	 * @return
+	 */
+	public static int hasSecurityManager()
+	{
+		return System.getSecurityManager() == null ? 0 : 1;
 	}
 }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
Tue Jan  3 15:59:10 2006
@@ -119,6 +119,10 @@
   
   // Access all files under ${user.dir}to write the test directory structure
   permission java.io.FilePermission "${user.dir}${/}-", "read,write,delete"; 
+ 
+  // When running with useprocess=false need to install and uninstall
+  // the security manager.
+  permission java.lang.RuntimePermission "setSecurityManager";
   
   // lang/errorStream.java
   permission java.lang.RuntimePermission "setIO";
@@ -149,6 +153,9 @@
   // Access all files under ${user.dir}to write the test directory structure
   permission java.io.FilePermission "${user.dir}${/}-", "read,write,delete"; 
   
+  // When running with useprocess=false need to install and uninstall
+  // the security manager.
+  permission java.lang.RuntimePermission "setSecurityManager";
   
   // Import/export and other support files from these locations in tests
   permission java.io.FilePermission "${user.dir}${/}extin${/}*", "read";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/testRoutines.sql
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/testRoutines.sql?rev=365776&r1=365775&r2=365776&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/testRoutines.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/testRoutines.sql
Tue Jan  3 15:59:10 2006
@@ -2,3 +2,4 @@
 -- Direct call to 'installRoutines' uses nested connection
 CREATE PROCEDURE TESTROUTINE.SET_SYSTEM_PROPERTY(IN PROPERTY_KEY VARCHAR(32000), IN PROPERTY_VALUE
VARCHAR(32000)) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.setSystemProperty'
language java parameter style java;
 CREATE PROCEDURE TESTROUTINE.SLEEP(IN SLEEP_TIME_MS BIGINT) NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.sleep'
language java parameter style java;
+CREATE FUNCTION TESTROUTINE.HAS_SECURITY_MANAGER() RETURNS INT NO SQL EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.TestRoutines.hasSecurityManager'
language java parameter style java;



Mime
View raw message