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/02/02 00:12:50 UTC

svn commit: r502400 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/suites/EncryptionSuite.java junit/Decorator.java

Author: djd
Date: Thu Feb  1 15:12:49 2007
New Revision: 502400

URL: http://svn.apache.org/viewvc?view=rev&rev=502400
Log:
DERBY-1952 (partial) Add a top-level encryption suite EncryptionSuite that runs a set of tests in
encrypted databases with different algorithms. A replacement mechanism for the
encrypted suite in the old harness. Only includes a single test at the moment,
since that is the only converted test that run under the old harness with encrpytion.
EncryptionSuite is not added to suites.All as I'd like to see some more testing
on other platforms before enabling for all.
Added the encryptedDatabase decorators to a new class junit.Decorator to stop
TestConfiguration becoming clogged with decorators.


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/EncryptionSuite.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java   (with props)

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/EncryptionSuite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/EncryptionSuite.java?view=auto&rev=502400
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/EncryptionSuite.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/EncryptionSuite.java Thu Feb  1 15:12:49 2007
@@ -0,0 +1,93 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.suites.EncryptionSuite
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.derbyTesting.functionTests.suites;
+
+import org.apache.derbyTesting.functionTests.tests.jdbcapi.LobStreamsTest;
+import org.apache.derbyTesting.junit.Decorator;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * A suite that runs a set of tests using encrypted
+ * databases with a number of algorithms.
+ * This is a general encryption test to see if
+ * tests run without any problems when encryption
+ * is enabled.
+ * <BR>
+ * It is not for testing of encrpytion functionality,
+ * e.g. testing that bootPassword must be a certain
+ * length etc. That should be in a specific JUnit test
+ * that probably needs to control database creation
+ * more carefully than this.
+ * <BR>
+ * The same set of tests is run for each algorithm,
+ * and each algorithm (obviously) uses a single
+ * use database with the required encryption setup.
+ * 
+ * @see Decorator#encryptedDatabase(Test)
+ * @see Decorator#encryptedDatabase(Test, String)
+ *
+ */
+public final class EncryptionSuite {
+    
+
+    private EncryptionSuite() {
+        super();
+    }
+    
+    /**
+     * Runs tests with a set of encryption algorithms.
+     * The set comes from the set of algorithms used
+     * for the same purpose in the old harness.
+     */
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("Encrpytion Suite");
+        
+        suite.addTest(Decorator.encryptedDatabase(baseSuite("default")));
+        suite.addTest(encryptedSuite("AES/CBC/NoPadding"));
+        suite.addTest(encryptedSuite("DES/ECB/NoPadding"));
+        suite.addTest(encryptedSuite("DESede/CFB/NoPadding"));
+        suite.addTest(encryptedSuite("DES/CBC/NoPadding"));
+        suite.addTest(encryptedSuite("Blowfish/CBC/NoPadding"));
+        suite.addTest(encryptedSuite("AES/CBC/NoPadding"));
+        
+        return suite;
+    }
+    
+    private static Test encryptedSuite(String algorithm)
+    {
+        return Decorator.encryptedDatabase(baseSuite(algorithm), algorithm);
+    }
+    
+    /**
+     * Set of tests which are run for each encryption algorithm.
+     */
+    private static Test baseSuite(String algorithm)
+    {
+        TestSuite suite = new TestSuite("Encryption Algorithm: " + algorithm);
+        
+        // LobStreamsTest was in the encrpytion suite for the old harness. 
+        suite.addTest(LobStreamsTest.suite());
+        return suite;
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/EncryptionSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java?view=auto&rev=502400
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java Thu Feb  1 15:12:49 2007
@@ -0,0 +1,151 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.junit.Decorator
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.derbyTesting.junit;
+
+import java.sql.SQLException;
+import java.util.Random;
+
+import javax.sql.DataSource;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+/**
+ * Utility class that provides static methods to decorate tests.
+ * Used as a central collection point for decorators than cannot
+ * be simply expressed as a TestSetup class. Typically the
+ * decorators will be collections of other decorators
+ */
+public class Decorator {
+
+    private Decorator() {
+        super();
+    }
+
+    /**
+     * Decorate a set of tests to use an encrypted
+     * single use database. This is to run tests
+     * using encrpyption as a general test and
+     * not specific tests of how encryption is handled.
+     * E.g. tests of setting various URL attributes
+     * would be handled in a specific test.
+     * <BR>
+     * The database will use the default encryption
+     * algorithm.
+     * <BR>
+     * A boot password (phrase) is used with a random
+     * set of characters and digits 16 characters long.
+     * <BR>
+     * The database is created during the setUp of the decorator.
+     * 
+     * @param test test to decorate
+     * @return decorated tests
+     */
+    public static Test encryptedDatabase(Test test)
+    {
+        test = new TestSetup(test) {
+            
+            /**
+             * Create an encrypted database using a
+             * JDBC data source.
+             */
+            protected void setUp() throws SQLException
+            {
+                String bootPhrase = getBootPhrase(16);
+
+                DataSource ds = JDBCDataSource.getDataSource();
+                               
+                JDBCDataSource.setBeanProperty(ds,
+                        "createDatabase", "create");
+                JDBCDataSource.setBeanProperty(ds,
+                        "connectionAttributes",
+                        "dataEncryption=true;bootPassword=" + bootPhrase);
+                
+                ds.getConnection().close();
+            }
+        };
+        
+        return TestConfiguration.singleUseDatabaseDecorator(test);
+    }
+    
+    /**
+     * Decorate a set of tests to use an encrypted
+     * single use database. This is to run tests
+     * using encrpyption as a general test and
+     * not specific tests of how encryption is handled.
+     * E.g. tests of setting various URL attributes
+     * would be handled in a specific test.
+     * <BR>
+     * The database will use the specified encryption
+     * algorithm.
+     * <BR>
+     * A boot password (phrase) is used with a random
+     * set of characters and digits 64 characters long.
+     * <BR>
+     * The database is created during the setUp of the decorator.
+
+     * 
+     * @param test test to decorate
+     * @return decorated tests
+     */
+    public static Test encryptedDatabase(Test test, final String algorithm)
+    {
+        test = new TestSetup(test) {
+            
+            /**
+             * Create an encrypted database using a
+             * JDBC data source.
+             */
+            protected void setUp() throws SQLException
+            {
+                String bootPhrase = getBootPhrase(64);
+                DataSource ds = JDBCDataSource.getDataSource();
+                        
+                JDBCDataSource.setBeanProperty(ds,
+                        "createDatabase", "create");
+                JDBCDataSource.setBeanProperty(ds,
+                        "connectionAttributes",
+                        "dataEncryption=true;bootPassword=" + bootPhrase +
+                        ";encryptionAlgorithm=" + algorithm);
+                
+                ds.getConnection().close();
+            }
+        };
+        
+        return TestConfiguration.singleUseDatabaseDecorator(test);
+    }
+    
+    private static String getBootPhrase(int length)
+    {
+        Random rand = new Random();
+        
+        char[] bp = new char[length];
+        for (int i = 0; i < bp.length; ) {
+            char c = (char) rand.nextInt();
+            if (Character.isLetterOrDigit(c))
+            {
+                bp[i++] = c;
+            }
+        }
+        
+        return new String(bp);
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/Decorator.java
------------------------------------------------------------------------------
    svn:eol-style = native