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 dj...@apache.org on 2007/03/17 00:51:30 UTC

svn commit: r519185 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests: Changes10_2.java PhaseChanger.java UpgradeRun.java

Author: djd
Date: Fri Mar 16 16:51:30 2007
New Revision: 519185

URL: http://svn.apache.org/viewvc?view=rev&rev=519185
Log:
DERBY-2217 convert upgrade test fixture that re-encrypts an existing encrypted database dueing upgrade.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java?view=diff&rev=519185&r1=519184&r2=519185
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_2.java Fri Mar 16 16:51:30 2007
@@ -339,44 +339,101 @@
     
     /**
      * Run the change encryption test against a
-     * non-encrypted database.
-     * 
+     * non-encrypted database. Test that changing the encryption
+     * is only allowed if the database has been hard-upgraded. 
+     * This test assumes it has its own single use database, which
+     * will not be booted by the general upgrade test setup.
      * @throws SQLException
      */
+
     public void testChangeEncryptionFromNone() throws SQLException
     {
-        changeEncryption("NO_ENCRYPT_10_2", false);
+        DataSource ds = JDBCDataSource.getDataSourceLogical("NO_ENCRYPT_10_2");
+        
+        switch (getPhase())
+        {
+        case PH_CREATE:
+            // create the database if it was not already created.
+            JDBCDataSource.setBeanProperty(ds, "createDatabase", "create");
+            ds.getConnection().close();
+            break;
+        case PH_SOFT_UPGRADE:
+            JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+                    "dataEncryption=true;bootPassword=xyz1234abc");
+            
+            try {
+                ds.getConnection();
+                fail("open re-encrypted connection in soft upgrade");
+            } catch (SQLException e) {
+                assertSQLState("XJ040", e);
+                e = e.getNextException();
+                assertNotNull(e);
+                assertSQLState("XCL47", e);
+            }
+            break;
+            
+            
+        case PH_POST_SOFT_UPGRADE:
+            // Should be able to successfully connect to it
+            // using the old setup.
+            ds.getConnection().close();
+            break;
+            
+        case PH_HARD_UPGRADE:
+            // On hard upgrade should be able to connect to it
+            // changing the encryption.
+            // Note we have to explicitly upgrade additional databases.
+            JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+            "upgrade=true;dataEncryption=true;bootPassword=haRD1234upGrAde");
+            ds.getConnection().close();
+            
+            // Shutdown the database.
+            JDBCDataSource.clearStringBeanProperty(ds, "connectionAttributes");
+            JDBCDataSource.shutdownDatabase(ds);
+            
+            // Reboot with no boot password, should fail
+            try {
+                ds.getConnection();
+                fail("open re-encrypted connection without password");
+            } catch (SQLException e) {
+                assertSQLState("XJ040", e);
+                e = e.getNextException();
+                assertNotNull(e);
+                assertSQLState("XBM06", e);
+            }
+            
+            // And connect successfully.
+            JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+                       "bootPassword=haRD1234upGrAde");
+            ds.getConnection().close();
+            break;
+        }
     }
-    
-    
     /**
-     * Test that changing the encryption is only allowed if
-     * the database has been hard-upgraded. This test can
-     * work against an existing encrypted or un-encrypted database.
+     * Run the change encryption test against a
+     * encrypted database. Test that changing the encryption
+     * is only allowed if the database has been hard-upgraded. 
      * This test assumes it has its own single use database, which
      * will not be booted by the general upgrade test setup.
      * @throws SQLException
      */
-    private void changeEncryption(String logicalDBName,
-            boolean encryptOldDB) throws SQLException
+
+    public void testChangeEncryptionFromEncryptedDatabase() throws SQLException
     {
-        DataSource ds = JDBCDataSource.getDataSourceLogical(logicalDBName);
+        DataSource ds = JDBCDataSource.getDataSourceLogical("ENCRYPT_10_2");
         
         switch (getPhase())
         {
         case PH_CREATE:
-            // create the database if it was not already created.
+            // create the database encrypted
             JDBCDataSource.setBeanProperty(ds, "createDatabase", "create");
-            if (encryptOldDB)
-            {
-                JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
-                    "dataEncryption=true;bootPassword=old1234dbPhraSe");
-            }
+            JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+                 "dataEncryption=true;bootPassword=old862phRase");
             ds.getConnection().close();
             break;
         case PH_SOFT_UPGRADE:
             JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
-                    "dataEncryption=true;bootPassword=xyz1234abc");
+                    "bootPassword=old862phRase;newBootPassword=new902pHrAse");
             
             try {
                 ds.getConnection();
@@ -393,6 +450,8 @@
         case PH_POST_SOFT_UPGRADE:
             // Should be able to successfully connect to it
             // using the old setup.
+            JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
+                 "bootPassword=old862phRase");
             ds.getConnection().close();
             break;
             
@@ -401,7 +460,7 @@
             // changing the encryption.
             // Note we have to explicitly upgrade additional databases.
             JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
-            "upgrade=true;dataEncryption=true;bootPassword=haRD1234upGrAde");
+            "upgrade=true;bootPassword=old862phRase;newBootPassword=hard924pHrAse");
             ds.getConnection().close();
             
             // Shutdown the database.
@@ -421,7 +480,7 @@
             
             // And connect successfully.
             JDBCDataSource.setBeanProperty(ds, "connectionAttributes",
-                       "bootPassword=haRD1234upGrAde");
+                       "bootPassword=hard924pHrAse");
             ds.getConnection().close();
             break;
         }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java?view=diff&rev=519185&r1=519184&r2=519185
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/PhaseChanger.java Fri Mar 16 16:51:30 2007
@@ -115,8 +115,9 @@
                     ds.getConnection().close();
                 } catch (SQLException e) {
                     // if the database was never created
-                    // don't bother shutting it down.
-                    if ("XJ004".equals(e.getSQLState()))
+                    // don't bother shutting it down
+                    String sqlState = e.getSQLState();
+                    if ("XJ004".equals(sqlState) || "XJ040".equals(sqlState))
                         shutdown = false;
                 }
                 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?view=diff&rev=519185&r1=519184&r2=519185
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java Fri Mar 16 16:51:30 2007
@@ -66,7 +66,8 @@
      * The databases are shutdown at the end of each phase.
      */
     static final String[] ADDITIONAL_DBS = {
-        "NO_ENCRYPT_10_2"
+        "NO_ENCRYPT_10_2",
+        "ENCRYPT_10_2"
     };
     
     private static String getTextVersion(int[] iv)