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 my...@apache.org on 2007/03/22 01:24:34 UTC

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

Author: myrnavl
Date: Wed Mar 21 17:24:31 2007
New Revision: 521055

URL: http://svn.apache.org/viewvc?view=rev&rev=521055
Log:
DERBY-1496: committing patch DERBY-1496_20070321.diff. 

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverMgrAuthenticationTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PoolDSAuthenticationTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XADSAuthenticationTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java Wed Mar 21 17:24:31 2007
@@ -176,6 +176,21 @@
             "testNetworkServerSecurityMechanism"));
         return TestConfiguration.clientServerDecorator((suite));
     }
+    
+    public void tearDown() throws Exception {
+        try {
+            AccessController.doPrivileged
+            (new java.security.PrivilegedAction(){
+                public Object run(){
+                    return System.getProperties().remove(
+                            "derby.drda.securityMechanism");
+                }
+            });
+        } catch (Exception e) {
+            fail("warning: could not remove secmec settings");
+        }
+        super.tearDown();
+    }
 
     // Indicates userid/encrypted password security mechanism.
     static final short SECMEC_EUSRIDPWD = 0x09;
@@ -383,7 +398,7 @@
             server2.start(null);
             // TODO: sleep ridiculously long, otherwise getting 08001 errors
             //       even when the server is up.
-            Thread.sleep(80000);
+            Thread.sleep(120000);
             
             if (derby_drda_securityMechanism.equals("") ||
                 derby_drda_securityMechanism.equals("INVALID_VALUE"))
@@ -878,7 +893,7 @@
      * get connection from datasource
      * @param user username
      * @param password password
-     * @param msg message to print for testcase
+     * @param expectedValue expected sql state
      */
     public void getDataSourceConnection(
         String user, String password, String expectedValue)

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java Wed Mar 21 17:24:31 2007
@@ -53,6 +53,7 @@
         suite.addTest(BadConnectionTest.suite());
         suite.addTest(NetHarnessJavaTest.suite());
         suite.addTest(SecureServerTest.suite());
+        suite.addTest(NSSecurityMechanismTest.suite());
         
         // These tests references a client class directly
         // thus causing class not found exceptions if the

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java Wed Mar 21 17:24:31 2007
@@ -36,12 +36,11 @@
 import junit.framework.TestSuite;
 
 import org.apache.derby.jdbc.ClientDataSource;
-import org.apache.derby.jdbc.EmbeddedDataSource;
-import org.apache.derby.jdbc.EmbeddedSimpleDataSource;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 public class AuthenticationTest extends BaseJDBCTestCase {
@@ -53,6 +52,8 @@
     protected String zeus = "\u0396\u0395\u03A5\u03A3";
     protected String apollo = "\u0391\u09A0\u039F\u039B\u039B\u039A\u0390";
 
+    protected static Properties sysprops = new Properties();
+    protected static Properties props = new Properties();
     
     /** Creates a new instance of the Test */
     public AuthenticationTest(String name) {
@@ -70,59 +71,82 @@
         TestSuite suite = new TestSuite("AuthenticationTest");
         suite.addTest(baseSuite("AuthenticationTest:embedded"));
         if (!JDBC.vmSupportsJSR169())
+        {
             suite.addTest(TestConfiguration.clientServerDecorator(
                 baseSuite("AuthenticationTest:client")));
+        }
         return suite;
     }
     
     public static Test baseSuite(String name) {
         TestSuite suite = new TestSuite("AuthenticationTest");
-
-        // set users at system level
-        java.lang.System.setProperty("derby.user.system", "admin");
-        java.lang.System.setProperty("derby.user.mickey", "mouse");
-        
-        // Use DatabasePropertyTestSetup decorator to set the user properties
-        // required by this test (and shutdown the database for the
-        // property to take effect).
-        Properties props = new Properties();
-        props.setProperty("derby.infolog.append", "true");
-        props.setProperty("derby.debug.true", "AuthenticationTrace");
-
-        Test test = new AuthenticationTest("testConnectShutdownAuthentication");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
         
-        // DatabasePropertyTestSsetup uses SYSCS_SET_DATABASE_PROPERTY
-        // so that is database level setting.
+        Test test = new AuthenticationTest(
+            "testConnectShutdownAuthentication");
+        setBaseProps(suite, test);
+        
         test = new AuthenticationTest("testUserFunctions");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         test = new AuthenticationTest("testNotFullAccessUsers");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
         test = new AuthenticationTest(
             "testChangePasswordAndDatabasePropertiesOnly");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         // only part of this fixture runs with network server / client
         test = new AuthenticationTest("testGreekCharacters");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
+
+        test = new AuthenticationTest("testSystemShutdown");
+        setBaseProps(suite, test);
         
         // This test needs to run in a new single use database as we're setting
         // a number of properties
         return TestConfiguration.singleUseDatabaseDecorator(suite);
     }
+    
+    protected static void setBaseProps(TestSuite suite, Test test) 
+    {
+        // Use DatabasePropertyTestSetup.builtinAuthentication decorator
+        // to set the user properties required by this test (and shutdown 
+        // the database for the property to take effect).
+        // DatabasePropertyTestSetup uses SYSCS_SET_DATABASE_PROPERTY
+        // so that is database level setting.
+        // Additionally use DatabasePropertyTestSetup to add some
+        // possibly useful settings
+        // Finally SystemPropertyTestSetup sets up system level users
+        props.setProperty("derby.infolog.append", "true");
+        props.setProperty("derby.debug.true", "AuthenticationTrace");
+        sysprops.put("derby.user.system", "admin");
+        sysprops.put("derby.user.mickey", "mouse");
+        test = DatabasePropertyTestSetup.builtinAuthentication(test,
+            USERS, PASSWORD_SUFFIX);
+        test = new DatabasePropertyTestSetup (test, props, true);
+        suite.addTest(new SystemPropertyTestSetup (test, sysprops));
+    }
+    
+    public void tearDown() throws Exception {
+        try {
+            AccessController.doPrivileged
+            (new java.security.PrivilegedAction(){
+                public Object run(){
+                    System.getProperties().remove(
+                        "derby.connection.requireAuthentication");
+                    String apollo = 
+                        "\u0391\u09A0\u039F\u039B\u039B\u039A\u0390";
+                    return 
+                        System.getProperties().remove("derby.user." +apollo);
+                }
+            });
+        } catch (Exception e) {
+            fail("failed to unset properties");
+        }
+        super.tearDown();
+    }
 
+    
     // roughly based on old functionTests test users.sql, except that
     // test used 2 databases. Possibly that was on the off-chance that
     // a second database would not work correctly - but that will not
@@ -219,18 +243,24 @@
         assertShutdownFail("08004", dbName, "badUser", "badPwd");
         assertShutdownFail("08004", dbName, "dan", "badPwd");
         assertShutdownFail("08004", dbName, "badUser", ("dan" + PASSWORD_SUFFIX));
-        
-        // try system shutdown with wrong user
-        assertSystemShutdownFail("08004", "", "badUser", ("dan" + PASSWORD_SUFFIX));
-        // with 'allowed' user but bad pwd
-        assertSystemShutdownFail("08004", "", "dan", ("jeff" + PASSWORD_SUFFIX));
-        // dbo, but bad pwd
-        assertSystemShutdownFail("08004", "", "APP", ("POO"));
-        // allowed user but not dbo
-        assertSystemShutdownFail("2850H", "", "dan", ("dan" + PASSWORD_SUFFIX));
+
+        // try some system shutdowns. Note, that all these work, because
+        // we have not set require authentication at system level.
+        // try system shutdown with wrong user - should work
+        assertSystemShutdownOK("", "badUser", ("dan" + PASSWORD_SUFFIX));
+        openDefaultConnection("dan", ("dan" + PASSWORD_SUFFIX)); // revive
+        // with 'allowed' user but bad pwd - will succeed
+        assertSystemShutdownOK("", "dan", ("jeff" + PASSWORD_SUFFIX));
+        openDefaultConnection("dan", ("dan" + PASSWORD_SUFFIX)); // revive
+        // dbo, but bad pwd - will succeed
+        assertSystemShutdownOK("", "APP", ("POO"));
+        openDefaultConnection("dan", ("dan" + PASSWORD_SUFFIX)); // revive
+        // allowed user but not dbo - will also succeed
+        assertSystemShutdownOK("", "dan", ("dan" + PASSWORD_SUFFIX));
+        openDefaultConnection("dan", ("dan" + PASSWORD_SUFFIX)); // revive
         // expect Derby system shutdown, which gives XJ015 error.
         assertSystemShutdownOK("", "APP", ("APP" + PASSWORD_SUFFIX));
-        
+
         // so far so good. set back security properties
         conn1 = openDefaultConnection("dan", ("dan" + PASSWORD_SUFFIX));
         setDatabaseProperty(
@@ -530,6 +560,67 @@
         conn1.close();
     }
     
+    // tests system shutdown with setting required authentication at
+    // system level
+    public void testSystemShutdown() throws SQLException
+    {
+        String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();
+        
+        // just for the setting the stage, recheck connections while fullAccess
+        // (default) is set at database level. 
+        
+        // first try connection with valid user/password
+        assertConnectionOK(dbName, "system", ("admin"));
+        assertConnectionOK(dbName, "dan", ("dan" + PASSWORD_SUFFIX));
+
+        // try ensuring system level is set for authentication
+        AccessController.doPrivileged
+        (new java.security.PrivilegedAction(){
+                public Object run(){
+                    return java.lang.System.setProperty(
+                        "derby.connection.requireAuthentication", "true");
+                }
+        });
+        // bring down the database
+        assertShutdownOK(dbName, "APP", "APP" + PASSWORD_SUFFIX);
+        // recheck
+        assertConnectionOK(dbName, "system", "admin");
+        assertConnectionOK(dbName, "dan", ("dan" + PASSWORD_SUFFIX));
+        // bring down server to ensure settings take effect 
+        assertSystemShutdownOK("", "badUser", ("dan" + PASSWORD_SUFFIX));
+        openDefaultConnection("dan", ("dan" + PASSWORD_SUFFIX)); // revive
+
+        // try system shutdown with wrong user
+        assertSystemShutdownFail("08004", "", "badUser", ("dan" + PASSWORD_SUFFIX));
+        // with 'allowed' user but bad pwd
+        assertSystemShutdownFail("08004", "", "dan", ("jeff" + PASSWORD_SUFFIX));
+        // APP, but bad pwd
+        assertSystemShutdownFail("08004", "", "APP", ("POO"));
+        // note: we don't have a database, so no point checking for dbo.
+        // expect Derby system shutdown, which gives XJ015 error.
+        assertSystemShutdownOK("", "system", "admin");
+        
+        // reset.
+        Connection conn1 = openDefaultConnection("dan", ("dan" + PASSWORD_SUFFIX));
+        setDatabaseProperty(
+            "derby.database.defaultConnectionMode","fullAccess", conn1);
+        setDatabaseProperty(
+            "derby.connection.requireAuthentication","false", conn1);
+        AccessController.doPrivileged
+        (new java.security.PrivilegedAction(){
+                public Object run(){
+                    return java.lang.System.setProperty(
+                        "derby.connection.requireAuthentication", "false");
+                }
+        });
+        conn1.commit();
+        conn1.close();
+        openDefaultConnection("system", "admin");
+        assertShutdownOK(dbName, "APP", "APP" + PASSWORD_SUFFIX);
+        assertSystemShutdownOK("", "system", "admin");
+        openDefaultConnection("system", "admin"); // just so teardown works.
+    }
+    
     protected void assertFailSetDatabaseProperty(
         String propertyName, String value, Connection conn) 
     throws SQLException {
@@ -792,7 +883,14 @@
     throws SQLException {
         if (usingEmbedded())
         {
-            DataSource ds = JDBCDataSource.getDataSource(dbName);
+            // we cannot use JDBCDataSource.getDataSource() (which uses the
+            // default database name), unless we specifically clear the 
+            // databaseName. Otherwise, only the database will be shutdown.
+            // The alternative is to use jDBCDataSource.getDatasource(dbName),
+            // where dbName is an empty string - this will in the current code
+            // be interpreted as a system shutdown.
+            DataSource ds = JDBCDataSource.getDataSource();
+            JDBCDataSource.clearStringBeanProperty(ds, "databaseName");
             JDBCDataSource.setBeanProperty(ds, "shutdownDatabase", "shutdown");
             try {
                 ds.getConnection(user, password);
@@ -804,6 +902,13 @@
         }
         else if (usingDerbyNetClient())
         {
+            // ds.setShutdown is not currently suppported by client, so we need
+            // to use ds.setConnectionAttributes.
+            // With client, we cannot user clearStringBeanProperty on the  
+            // databaseName, that will result in error 08001 - 
+            // Required DataSource property databaseName not set.
+            // So, we pass an empty string as databaseName, which the current
+            // code interprets as a system shutdown.
             ClientDataSource ds = 
                 (ClientDataSource)JDBCDataSource.getDataSource(dbName);
             ds.setConnectionAttributes("shutdown=true");
@@ -817,12 +922,6 @@
         }
     }
 
-    // Note, we need a separate method for fail & OK because something
-    // the framework will add the wrong details. If we use
-    // getDataSource(dbName), we don't get a successful XJ015, ever,
-    // if we use getDataSource(), it appears the user/password on connect
-    // is ignored, at least, we get XJ015 anyway.
-    // 
     protected void assertSystemShutdownFail(
         String expectedError, String dbName, String user, String password)
     throws SQLException {
@@ -843,13 +942,19 @@
         else if (usingDerbyNetClient())
         {
             ClientDataSource ds = 
-                (ClientDataSource)JDBCDataSource.getDataSource();
-            JDBCDataSource.clearStringBeanProperty(ds, "databaseName");
+                (ClientDataSource)JDBCDataSource.getDataSource(dbName);
+            // note: with network server, you cannot set the databaseName
+            // to null, that results in error 08001 - Required DataSource
+            // property databaseName not set.
+            // so, we rely on passing of an empty string for databaseName,
+            // which in the current code is interpreted as system shutdown.
+            // also, we need to use setConnectionAttributes.
             ds.setConnectionAttributes(
                 "shutdown=true;user=" + user + ";password=" + password);
             try {
                 ds.getConnection();
                 fail("expected shutdown to fail");
+                ds.getConnection(user, password);
             } catch (SQLException e) {
                 assertSQLState(expectedError, e);
             }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverMgrAuthenticationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverMgrAuthenticationTest.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverMgrAuthenticationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverMgrAuthenticationTest.java Wed Mar 21 17:24:31 2007
@@ -24,12 +24,10 @@
 
 import java.sql.DriverManager;
 import java.sql.SQLException;
-import java.util.Properties;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -58,50 +56,32 @@
             return suite;
         }
     }
-    
+
+    // baseSuite takes advantage of setting system properties as defined
+    // in AuthenticationTest
     public static Test baseSuite(String name) {
         TestSuite suite = new TestSuite("DriverMgrAuthenticationTest");
-
-        // set a user at system level
-        java.lang.System.setProperty("derby.user.system", "admin");
-        java.lang.System.setProperty("derby.user.mickey", "mouse");
         
-        // Use DatabasePropertyTestSetup decorator to set the user properties
-        // required by this test (and shutdown the database for the
-        // property to take effect).
-        Properties props = new Properties();
-        props.setProperty("derby.infolog.append", "true");
-        props.setProperty("derby.debug.true", "AuthenticationTrace");
-
         Test test = new DriverMgrAuthenticationTest(
             "testConnectShutdownAuthentication");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
-        // DatabasePropertyTestSsetup uses SYSCS_SET_DATABASE_PROPERTY
-        // so that is database level setting.
         test = new DriverMgrAuthenticationTest("testUserFunctions");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         test = new DriverMgrAuthenticationTest("testNotFullAccessUsers");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
         test = new DriverMgrAuthenticationTest(
             "testChangePasswordAndDatabasePropertiesOnly");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         // only part of this fixture runs with network server / client
         test = new DriverMgrAuthenticationTest("testGreekCharacters");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
+
+        test = new DriverMgrAuthenticationTest("testSystemShutdown");
+        setBaseProps(suite, test);
         
         // The test needs to run in a new single use database as we're
         // setting a number of properties
@@ -233,7 +213,7 @@
     {
         String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
         if (usingDerbyNetClient() && dbName=="")
-            // The junit test harness has kicked off the test will hang when 
+            // The junit test harness that kicked off the test will hang when 
             // we attempt to shutdown the system - most likely because we're
             // shutting down the system while the network server thread is
             // still alive, so it gets confused...
@@ -252,9 +232,9 @@
         String expectedSqlState, String dbName, String user, String password) 
     throws SQLException
     {
-        String url = TestConfiguration.getCurrent().getJDBCUrl();
+        String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
         if (usingDerbyNetClient() && dbName=="")
-            // The junit test harness has kicked off the test will hang when 
+            // The junit test harness that kicked off the test will hang when 
             // we attempt to shutdown the system - most likely because we're
             // shutting down the system while the network server thread is
             // still alive, so it gets confused...
@@ -262,7 +242,8 @@
         String url2 = 
             url + ";user=" + user + ";password=" + password + ";shutdown=true";
         try {
-            DriverManager.getConnection(url2, user, password);
+            //DriverManager.getConnection(url2, user, password);
+            DriverManager.getConnection(url2);
             fail("expected failed shutdown");
         } catch (SQLException e) {
             assertSQLState(expectedSqlState, e);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PoolDSAuthenticationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PoolDSAuthenticationTest.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PoolDSAuthenticationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PoolDSAuthenticationTest.java Wed Mar 21 17:24:31 2007
@@ -32,7 +32,6 @@
 
 import org.apache.derby.jdbc.ClientConnectionPoolDataSource;
 import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
-import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.J2EEDataSource;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
@@ -49,7 +48,8 @@
     }
 
     public static Test suite() {
-        // This test uses driverManager and so is not suitable for JSR169
+        // This test uses ConnectionPoolDataSource and so is not suitable for 
+        // JSR169
         if (JDBC.vmSupportsJSR169())
             return new TestSuite("ConnectionPoolDataSource not available" +
                 " with JSR169; empty test");
@@ -62,55 +62,37 @@
         }
     }
     
+    // baseSuite takes advantage of setting system properties as defined
+    // in AuthenticationTest
     public static Test baseSuite(String name) {
         TestSuite suite = new TestSuite("PoolDSAuthenticationTest");
 
-        // set a user at system level
-        java.lang.System.setProperty("derby.user.system", "admin");
-        java.lang.System.setProperty("derby.user.mickey", "mouse");
-        
-        // Use DatabasePropertyTestSetup decorator to set the user 
-        // properties required by this test (and shutdown the database for
-        // the property to take effect).
-        Properties props = new Properties();
-        props.setProperty("derby.infolog.append", "true");
-        props.setProperty("derby.debug.true", "AuthenticationTrace");
-
         Test test = new PoolDSAuthenticationTest(
             "testConnectShutdownAuthentication");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
-        // DatabasePropertyTestSsetup uses SYSCS_SET_DATABASE_PROPERTY
-        // so that is database level setting.
         test = new PoolDSAuthenticationTest("testUserFunctions");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         test = new PoolDSAuthenticationTest("testNotFullAccessUsers");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
         test = new PoolDSAuthenticationTest(
             "testChangePasswordAndDatabasePropertiesOnly");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         // only part of this fixture runs with network server / client
         test = new PoolDSAuthenticationTest("testGreekCharacters");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
+        test = new PoolDSAuthenticationTest("testSystemShutdown");
+        setBaseProps(suite, test);
+
         // The test needs to run in a new single use database as we're
         // setting a number of properties
         return TestConfiguration.singleUseDatabaseDecorator(suite);
     }
-    
+
     protected void assertConnectionOK(
         String dbName, String user, String password)
     throws SQLException
@@ -315,10 +297,10 @@
         if (usingEmbedded())
         {
             pds = J2EEDataSource.getConnectionPoolDataSource();
+            JDBCDataSource.clearStringBeanProperty(pds, "databaseName");
             JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
             JDBCDataSource.setBeanProperty(pds, "user", user);
             JDBCDataSource.setBeanProperty(pds, "password", password);
-            JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
             try {
                 pds.getPooledConnection();
                 fail("expected system shutdown resulting in XJ015 error");
@@ -332,7 +314,10 @@
             ClientConnectionPoolDataSource pds = 
                 (ClientConnectionPoolDataSource)
                 J2EEDataSource.getConnectionPoolDataSource();
+            // current client/server code interprets shutdown with an
+            // empty databaseName string as a system shutdown
             pds.setDatabaseName(dbName);
+            // Client does not support *ds*.setShutdown(), use set Conn Attrs 
             pds.setConnectionAttributes(
                     "shutdown=true;user=" + user + ";password=" + password);
             try {
@@ -345,19 +330,14 @@
         }
     }
 
-    // Note, we need a separate method for fail & OK because something
-    // the framework will add the wrong details. If we use
-    // getDataSource(dbName), we don't get a successful XJ015, ever,
-    // if we use getDataSource(), it appears the user/password on connect
-    // is ignored, at least, we get XJ015 anyway.
-    // 
     protected void assertSystemShutdownFail(
             String expectedError, String dbName, String user, String password)
     throws SQLException {
         if (usingEmbedded())
         {
             pds = J2EEDataSource.getConnectionPoolDataSource();
-            JDBCDataSource.setBeanProperty(pds, "shutdownDatabase","shutdown");
+            JDBCDataSource.clearStringBeanProperty(pds, "databaseName");
+            JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
             JDBCDataSource.setBeanProperty(pds, "user", user);
             JDBCDataSource.setBeanProperty(pds, "password", password);
             try {
@@ -372,6 +352,10 @@
             ClientConnectionPoolDataSource pds = 
                 (ClientConnectionPoolDataSource)
                 J2EEDataSource.getConnectionPoolDataSource();
+            // current client/server code interprets shutdown with an
+            // empty databaseName string as a system shutdown
+            pds.setDatabaseName(dbName);
+            // Client does not support *ds*.setShutdown(), use set Conn Attrs 
             pds.setConnectionAttributes(
                     "shutdown=true;user=" + user + ";password=" + password);
             try {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XADSAuthenticationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XADSAuthenticationTest.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XADSAuthenticationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/XADSAuthenticationTest.java Wed Mar 21 17:24:31 2007
@@ -31,7 +31,6 @@
 
 import org.apache.derby.jdbc.ClientXADataSource;
 import org.apache.derby.jdbc.EmbeddedXADataSource;
-import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.J2EEDataSource;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.JDBCDataSource;
@@ -49,7 +48,7 @@
     }
 
     public static Test suite() {
-        // This test uses driverManager and so is not suitable for JSR169
+        // This test uses XADataSource and so is not suitable for JSR169
         if (JDBC.vmSupportsJSR169())
             return new TestSuite("");
         else {
@@ -61,50 +60,32 @@
         }
     }
     
+    // baseSuite takes advantage of setting system properties as defined
+    // in AuthenticationTest
     public static Test baseSuite(String name) {
         TestSuite suite = new TestSuite("XADSAuthenticationTest");
 
-        // set a user at system level
-        java.lang.System.setProperty("derby.user.system", "admin");
-        java.lang.System.setProperty("derby.user.mickey", "mouse");
-        
-        // Use DatabasePropertyTestSetup decorator to set the user properties
-        // required by this test (and shutdown the database for the
-        // property to take effect).
-        Properties props = new Properties();
-        props.setProperty("derby.infolog.append", "true");
-        props.setProperty("derby.debug.true", "AuthenticationTrace");
-
         Test test = new XADSAuthenticationTest(
             "testConnectShutdownAuthentication");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
-        // DatabasePropertyTestSsetup uses SYSCS_SET_DATABASE_PROPERTY
-        // so that is database level setting.
         test = new XADSAuthenticationTest("testUserFunctions");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         test = new XADSAuthenticationTest("testNotFullAccessUsers");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
         test = new XADSAuthenticationTest(
             "testChangePasswordAndDatabasePropertiesOnly");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
 
         // only part of this fixture runs with network server / client
         test = new XADSAuthenticationTest("testGreekCharacters");
-        test = DatabasePropertyTestSetup.builtinAuthentication(test,
-            USERS, PASSWORD_SUFFIX);
-        suite.addTest(new DatabasePropertyTestSetup (test, props, true));
+        setBaseProps(suite, test);
         
+        test = new XADSAuthenticationTest("testSystemShutdown");
+        setBaseProps(suite, test);
+
         // The test needs to run in a new single use database as we're setting
         // a number of properties
         return TestConfiguration.singleUseDatabaseDecorator(suite);
@@ -310,10 +291,11 @@
         if (usingEmbedded())
         {
             xads = J2EEDataSource.getXADataSource();
-            JDBCDataSource.setBeanProperty(xads, "shutdownDatabase", "shutdown");
+            JDBCDataSource.setBeanProperty(
+                xads, "shutdownDatabase", "shutdown");
+            JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
             JDBCDataSource.setBeanProperty(xads, "user", user);
             JDBCDataSource.setBeanProperty(xads, "password", password);
-            JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
             try {
                 xads.getXAConnection();
                 fail("expected system shutdown resulting in XJ015 error");
@@ -326,7 +308,10 @@
         {
             ClientXADataSource xads = 
                 (ClientXADataSource)J2EEDataSource.getXADataSource();
+            // current client/server code interprets shutdown with an
+            // empty databaseName string as a system shutdown
             xads.setDatabaseName(dbName);
+            // Client does not support *ds*.setShutdown(), use set Conn Attrs 
             xads.setConnectionAttributes(
                 "shutdown=true;user=" + user + ";password=" + password);
             try {
@@ -339,12 +324,6 @@
         }
     }
 
-    // Note, we need a separate method for fail & OK because something
-    // the framework will add the wrong details. If we use
-    // getDataSource(dbName), we don't get a successful XJ015, ever,
-    // if we use getDataSource(), it appears the user/password on connect
-    // is ignored, at least, we get XJ015 anyway.
-    // 
     protected void assertSystemShutdownFail(
         String expectedError, String dbName, String user, String password)
     throws SQLException {
@@ -353,6 +332,7 @@
             xads = J2EEDataSource.getXADataSource();
             JDBCDataSource.setBeanProperty(
                 xads, "shutdownDatabase", "shutdown");
+            JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
             JDBCDataSource.setBeanProperty(xads, "user", user);
             JDBCDataSource.setBeanProperty(xads, "password", password);
             try {
@@ -366,8 +346,12 @@
         {
             ClientXADataSource xads = 
                 (ClientXADataSource)J2EEDataSource.getXADataSource();
+            // current client/server code interprets shutdown with an
+            // empty databaseName string as a system shutdown
+            xads.setDatabaseName(dbName);
+            // Client does not support *ds*.setShutdown(), use set Conn Attrs 
             xads.setConnectionAttributes(
-                    "shutdown=true;user=" + user + ";password=" + password);
+                "shutdown=true;user=" + user + ";password=" + password);
             try {
                 xads.getXAConnection(user, password);
                 fail("expected shutdown to fail");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java Wed Mar 21 17:24:31 2007
@@ -73,6 +73,7 @@
 		suite.addTest(DatabaseMetaDataTest.suite());
 		suite.addTest(ClosedObjectTest.suite());
                 suite.addTest(SetTransactionIsolationTest.suite());
+		suite.addTest(AuthenticationTest.suite());
         
         // Old harness .java tests that run using the HarnessJavaTest
         // adapter and continue to use a single master file.
@@ -93,6 +94,12 @@
             // Tests JDBC 3.0 ability to establish a result set of 
             // auto-generated keys.
             suite.addTest(AutoGenJDBC30Test.suite());
+
+            // Test uses DriverManager
+            suite.addTest(DriverMgrAuthenticationTest.suite());
+            // Tests uses JDBC 3.0 datasources
+            suite.addTest(PoolDSAuthenticationTest.suite());
+            suite.addTest(XADSAuthenticationTest.suite());
         }
 		
         return suite;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=diff&rev=521055&r1=521054&r2=521055
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Wed Mar 21 17:24:31 2007
@@ -221,14 +221,20 @@
      */
     public static void shutdownDatabase(javax.sql.DataSource ds)
     {
-        setBeanProperty(ds, "shutdownDatabase", "shutdown");
+        // commenting out until such time as setShutdownDatabase is
+        // supported by client
+        //setBeanProperty(ds, "shutdownDatabase", "shutdown");
+        setBeanProperty(ds, "connectionAttributes", "shutdown=true");
         try {
             ds.getConnection();
             Assert.fail("Database failed to shut down");
         } catch (SQLException e) {
              BaseJDBCTestCase.assertSQLState("Database shutdown", "08006", e);
         } finally {
-            clearStringBeanProperty(ds, "shutdownDatabase");
+            // here too, commenting out until setShutdownDatabase is 
+            // supported by client
+            //clearStringBeanProperty(ds, "shutdownDatabase");
+            clearStringBeanProperty(ds, "connectionAttributes");
         }
     }
 }