You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2007/03/16 16:20:00 UTC

svn commit: r519004 - in /db/derby/code/trunk/java: drda/org/apache/derby/drda/ testing/org/apache/derbyTesting/functionTests/tests/derbynet/ testing/org/apache/derbyTesting/junit/

Author: rhillegas
Date: Fri Mar 16 08:19:59 2007
New Revision: 519004

URL: http://svn.apache.org/viewvc?view=rev&rev=519004
Log:
DERBY-2435: Commit derby-2435-01.diff, making NetworkServerControl pick up properties from derby.properties as needed.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.derby.properties   (with props)
Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java?view=diff&rev=519004&r1=519003&r2=519004
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java Fri Mar 16 08:19:59 2007
@@ -26,6 +26,7 @@
 import java.net.URL;
 import java.util.Properties;
 import org.apache.derby.iapi.reference.Property;
+import org.apache.derby.iapi.services.property.PropertyUtil;
 
 import org.apache.derby.impl.drda.NetworkServerControlImpl;
 
@@ -561,7 +562,11 @@
         // be tricked into a false sense of security. Important security checks
         // will be identity based.
         //
-        if ( !Boolean.getBoolean( Property.REQUIRE_AUTHENTICATION_PARAMETER ) )
+        String      authenticationProperty =
+            PropertyUtil.getSystemProperty( Property.REQUIRE_AUTHENTICATION_PARAMETER );
+        boolean     authenticationRequired = Boolean.valueOf( authenticationProperty ).booleanValue();
+        
+        if ( !authenticationRequired )
         {
             String  errorMessage = server.localizeMessage
                 (
@@ -587,10 +592,10 @@
         //
         // The Basic policy refers to some properties. Make sure they are set.
         //
-        if ( System.getProperty( Property.SYSTEM_HOME_PROPERTY ) == null )
-        { System.setProperty( Property.SYSTEM_HOME_PROPERTY, System.getProperty( "user.dir" ) ); }
+        if ( PropertyUtil.getSystemProperty( Property.SYSTEM_HOME_PROPERTY ) == null )
+        { System.setProperty( Property.SYSTEM_HOME_PROPERTY, PropertyUtil.getSystemProperty( "user.dir" ) ); }
 
-        if ( System.getProperty( Property.DRDA_PROP_HOSTNAME ) == null )
+        if ( PropertyUtil.getSystemProperty( Property.DRDA_PROP_HOSTNAME ) == null )
         { System.setProperty( Property.DRDA_PROP_HOSTNAME, server.getHost() ); }
 
         //

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.derby.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.derby.properties?view=auto&rev=519004
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.derby.properties (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.derby.properties Fri Mar 16 08:19:59 2007
@@ -0,0 +1,12 @@
+#
+# This is a sample derby.properties file used by one
+# of the configurations of SecureServerTest.
+# These properties are used to verify that
+# the server picks up variables from derby.properties as well
+# as from the VM's system properties.
+#
+
+derby.connection.requireAuthentication=true
+derby.authentication.provider=BUILTIN
+derby.user.SA=sapwd
+derby.user.MARY=marypwd

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.derby.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java?view=diff&rev=519004&r1=519003&r2=519004
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java Fri Mar 16 08:19:59 2007
@@ -36,6 +36,7 @@
 import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.ServerSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
 import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -98,6 +99,7 @@
     // startup state
     private boolean _unsecureSet;
     private boolean _authenticationRequired;
+    private boolean _useCustomDerbyProperties;
 
     // expected outcomes
     private Outcome _outcome;
@@ -116,6 +118,7 @@
         (
          boolean unsecureSet,
          boolean authenticationRequired,
+         boolean useCustomDerbyProperties,
 
          Outcome    outcome
         )
@@ -124,6 +127,7 @@
 
          _unsecureSet =  unsecureSet;
          _authenticationRequired =  authenticationRequired;
+         _useCustomDerbyProperties = useCustomDerbyProperties;
 
          _outcome = outcome;
 
@@ -154,14 +158,16 @@
 
         // O = Overriden
         // A = Authenticated
+        // C = using Custom properties
         //
-        //      .addTest( decorateTest( S,      O,       A,     Outcome ) );
+        //      .addTest( decorateTest( O,        A,       C,    Outcome ) );
         //
 
-        suite.addTest( decorateTest( false,  false, FAILED_NO_AUTHENTICATION ) );
-        suite.addTest( decorateTest( false,  true, RUNNING_SECURITY_BOOTED ) );
-        suite.addTest( decorateTest( true,  false, RUNNING_SECURITY_NOT_BOOTED ) );
-        suite.addTest( decorateTest( true,  true, RUNNING_SECURITY_NOT_BOOTED ) );
+        suite.addTest( decorateTest( false,  false, false, FAILED_NO_AUTHENTICATION ) );
+        suite.addTest( decorateTest( false,  false, true, RUNNING_SECURITY_BOOTED ) );
+        suite.addTest( decorateTest( false,  true, false, RUNNING_SECURITY_BOOTED ) );
+        suite.addTest( decorateTest( true,  false, false, RUNNING_SECURITY_NOT_BOOTED ) );
+        suite.addTest( decorateTest( true,  true, false, RUNNING_SECURITY_NOT_BOOTED ) );
         
         return suite;
     }
@@ -191,7 +197,8 @@
         (
          boolean unsecureSet,
          boolean authenticationRequired,
-
+         boolean useCustomDerbyProperties,
+         
          Outcome outcome
         )
     {
@@ -199,11 +206,12 @@
             (
              unsecureSet,
              authenticationRequired,
+             useCustomDerbyProperties,
 
              outcome
             );
 
-        String[]        startupProperties = getStartupProperties( authenticationRequired );
+        String[]        startupProperties = getStartupProperties( authenticationRequired, useCustomDerbyProperties );
         String[]        startupArgs = getStartupArgs( unsecureSet );
 
         TestSetup   testSetup = new NetworkServerTestSetup
@@ -216,6 +224,19 @@
              secureServerTest._inputStreamHolder
              );
 
+        // if using the custom derby.properties, copy the custom properties to a visible place
+        if ( useCustomDerbyProperties )
+        {
+            testSetup = new SupportFilesSetup
+                (
+                 testSetup,
+                 null,
+                 new String[] { "functionTests/tests/derbynet/SecureServerTest.derby.properties" },
+                 null,
+                 new String[] { "derby.properties" }
+                 );
+        }
+
         testSetup = new ServerSetup( testSetup, TestConfiguration.DEFAULT_HOSTNAME, TestConfiguration.DEFAULT_PORT );
 
         Test        test = SecurityManagerSetup.noSecurityManager( testSetup );
@@ -249,7 +270,7 @@
      * Return a set of startup properties suitable for SystemPropertyTestSetup.
      * </p>
      */
-    private static  String[]  getStartupProperties( boolean authenticationRequired )
+    private static  String[]  getStartupProperties( boolean authenticationRequired, boolean useCustomDerbyProperties )
     {
         ArrayList       list = new ArrayList();
 
@@ -258,6 +279,11 @@
             list.add( "derby.connection.requireAuthentication=true" );
         }
 
+        if ( useCustomDerbyProperties )
+        {
+            list.add( "derby.system.home=extinout" );
+        }
+
         String[]    result = new String[ list.size() ];
 
         list.toArray( result );
@@ -298,8 +324,9 @@
         StringBuffer    buffer = new StringBuffer();
 
         buffer.append( "SecureServerTest( " );
-        buffer.append( "Opened = " ); buffer.append( _unsecureSet); buffer.append( ", " );
-        buffer.append( "Authenticated= " ); buffer.append( _authenticationRequired );
+        buffer.append( "Opened = " ); buffer.append( _unsecureSet);
+        buffer.append( ", Authenticated= " ); buffer.append( _authenticationRequired );
+        buffer.append( ", CustomDerbyProperties= " ); buffer.append( _useCustomDerbyProperties );
         buffer.append( " )" );
 
         return buffer.toString();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java?view=diff&rev=519004&r1=519003&r2=519004
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java Fri Mar 16 08:19:59 2007
@@ -64,6 +64,8 @@
     
     private String[] readOnly;
     private String[] readWrite;
+    private String[] readOnlyTargetFileNames;
+    private String[] readWriteTargetFileNames;
 
     /**
      * Create all the folders but don't copy any resources.
@@ -79,7 +81,7 @@
      */
     public SupportFilesSetup(Test test, String[] readOnly)
     {
-        this(test, readOnly, (String[]) null);
+        this(test, readOnly, (String[]) null, (String[]) null, (String[]) null);
     }
     
     /**
@@ -89,16 +91,30 @@
    */
     public SupportFilesSetup(Test test, String[] readOnly, String[] readWrite)
     {
+        this(test, readOnly, readWrite, (String[]) null, (String[]) null);
+    }
+    
+    /**
+     * Create all the folders, copy a set of resources into
+     * the read only folder and copy a set of resources into
+     * the read write folder. If specified, use the specific target file
+     * supplied by the caller.
+     */
+    public SupportFilesSetup
+        (Test test, String[] readOnly, String[] readWrite, String[] readOnlyTargetFileNames, String[] readWriteTargetFileNames)
+    {
         super(test);
         this.readOnly = readOnly;
         this.readWrite = readWrite;
+        this.readOnlyTargetFileNames = readOnlyTargetFileNames;
+        this.readWriteTargetFileNames = readWriteTargetFileNames;
     }
     
     protected void setUp() throws PrivilegedActionException, IOException
     {
-        privCopyFiles("extin", readOnly);
-        privCopyFiles("extinout", readWrite);
-        privCopyFiles("extout", (String[]) null);
+        privCopyFiles("extin", readOnly, readOnlyTargetFileNames);
+        privCopyFiles("extinout", readWrite, readWriteTargetFileNames);
+        privCopyFiles("extout", (String[]) null, (String[]) null);
     }
     
     protected void tearDown()
@@ -108,21 +124,21 @@
         DropDatabaseSetup.removeDirectory("extout");
     }
     
-    private void privCopyFiles(final String dirName, final String[] resources)
+    private void privCopyFiles(final String dirName, final String[] resources, final String[] targetNames)
     throws PrivilegedActionException
     {
         AccessController.doPrivileged
         (new java.security.PrivilegedExceptionAction(){
             
             public Object run() throws IOException, PrivilegedActionException { 
-              copyFiles(dirName, resources);
+              copyFiles(dirName, resources, targetNames);
               return null;
             }
         });
 
     }
     
-    private void copyFiles(String dirName, String[] resources)
+    private void copyFiles(String dirName, String[] resources, String[] targetNames)
         throws PrivilegedActionException, IOException
     {
         File dir = new File(dirName);
@@ -136,10 +152,20 @@
             String name =
                 "org/apache/derbyTesting/".concat(resources[i]);
             
-            String baseName = name.substring(name.lastIndexOf('/') + 1);
-            
+            String baseName;
+
+            if ( targetNames == null )
+            {
+                // by default, just the same file name as the source file
+                baseName = name.substring(name.lastIndexOf('/') + 1);
+            }
+            else
+            {
+                // we let the caller override the target file name
+                baseName = targetNames[ i ];
+            }
             
-            URL url = BaseTestCase.getTestResource(name);
+                        URL url = BaseTestCase.getTestResource(name);
             assertNotNull(name, url);
             
             InputStream in = BaseTestCase.openTestResource(url);