public abstract class EncryptionKeyTest extends BaseJDBCTestCase
The algorithms used for en-/decryption is determined by the subclasses, where a single algorithm and a set of keys are associated with each subclass.
Databases are created in the EXTINOUT directory. Backups are made
to EXTINOUT/backups and restored databases are put into
EXTINOUT/restored if and only if the databases need to be
both written and read. Otherwise backups are placed in EXTOUT.
Testsuites generated from this class must be wrapped in a
SupportFileSetup
decorator.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
algorithm
The algorithm used by the fixture.
|
private java.sql.Connection |
con
Variable to hold the various connections.
|
protected static int |
CORRECT_KEY
Correct key constant.
|
private static int[] |
DATA
Test data inserted into database and used for verification.
|
protected static int |
INVALID_CHAR_KEY
Invalid char key constant.
|
private java.lang.String |
keyCorrect
The correct key.
|
private java.lang.String |
keyInvalidChar
A key with an invalid char in it.
|
private java.lang.String |
keyOddLength
A key with odd length.
|
private java.lang.String |
keyWrong
An incorrect key.
|
protected static int |
ODD_LENGTH_KEY
Odd length key constant.
|
private static java.lang.String |
TABLE
Table holding the test data.
|
protected static int |
WRONG_KEY
Wrong key constant.
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
EncryptionKeyTest(java.lang.String name,
java.lang.String algorithm,
java.lang.String correctKey,
java.lang.String wrongKey,
java.lang.String oddLengthKey,
java.lang.String invalidCharKey)
Configures a new setup by specifying the encryption properties.
|
Modifier and Type | Method and Description |
---|---|
private void |
confirmNonBootedDB(java.lang.String dbName)
Confirm that the specified encrypted database has not been booted.
|
protected java.sql.Connection |
createAndPopulateDB(java.lang.String dbName)
Create a new database and populate it.
|
private void |
createBackupRestore(java.lang.String sourceDb,
java.lang.String targetDb)
Create encrypted database, validate it, backup, restore and validate
recovered database.
|
private java.sql.Connection |
getConnection(java.lang.String dbName,
int keyMode)
Try to establish a connection to the named database with the
specified type of key.
|
private java.sql.Connection |
getConnection(java.lang.String dbName,
int keyMode,
java.lang.String recoveryAttribute)
Create a new connection to the specified database, using the given
connection attributes.
|
(package private) java.lang.String |
obtainDbName(java.lang.String dbName,
java.lang.String subdirectory)
Obtain absolute path for the specified database name.
|
protected void |
shutdown(java.lang.String databaseName)
Shutdown the specified database.
|
protected void |
shutdown(java.lang.String databaseName,
java.lang.String dir)
Shutdown the database, specified by the database name and prefix.
|
protected void |
tearDown()
Clean up the connection maintained by this test.
|
void |
testBackupEncryptedDatabase()
Backup an encrypted database.
|
void |
testConnectionSequence1()
Test a sequence of connections and connection attempts.
|
void |
testConnectionSequence2()
Test a sequence of connections and connection attempts.
|
void |
testCreateDbFromBackup()
Create a new database from a backup image.
|
void |
testCreateWithInvalidEncryptionKey()
Try to create database with a key containing one or more invalid chars.
|
void |
testCreateWithOddEncryptionKeyLength()
Try to create database with a key of odd length.
|
void |
testInvalidRestoreFrom()
Try to recover database with an invalid key.
|
void |
testRestoreFrom()
Recover the database using restoreFrom.
|
protected void |
validateDBContents(java.sql.Connection con)
Validate the data in the database against the data model.
|
assertCallError, assertCheckTable, assertCommitError, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertErrorCode, assertGetIntError, assertNextError, assertPreparedStatementError, assertResults, assertResults, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertStatementErrorUnordered, assertTableRowCount, assertUpdateCount, assertUpdateCount, assertWarning, chattyPrepare, chattyPrepareCall, checkAllConsistency, checkEstimatedRowCount, closeStatement, commit, createStatement, createStatement, createStatement, dropTable, dropTable, dropView, dropView, dumpRs, dumpRs, emptyStatementCache, executeQuery, expectCompilationError, expectCompilationError, expectExecutionError, getClientTransactionID, getConnection, getDatabaseProperty, getLastSQLException, goodStatement, goodUpdate, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runBare, runBareOverridable, runScript, runScript, runSQLCommands, setAutoCommit, usingDB2Client, usingDerbyNetClient, usingEmbedded
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, toString
protected static final int CORRECT_KEY
protected static final int WRONG_KEY
protected static final int ODD_LENGTH_KEY
protected static final int INVALID_CHAR_KEY
private static final java.lang.String TABLE
private static final int[] DATA
private final java.lang.String algorithm
private final java.lang.String keyCorrect
private final java.lang.String keyWrong
private final java.lang.String keyOddLength
private final java.lang.String keyInvalidChar
private java.sql.Connection con
public EncryptionKeyTest(java.lang.String name, java.lang.String algorithm, java.lang.String correctKey, java.lang.String wrongKey, java.lang.String oddLengthKey, java.lang.String invalidCharKey)
name
- name of the fixturealgorithm
- encryption algorithm to usecorrectKey
- the correct encryption keywrongKey
- an incorrect encryption keyoddLengthKey
- a key of odd lengthinvalidCharKey
- a key with invalid charactersprotected void tearDown() throws java.lang.Exception
tearDown
in class BaseJDBCTestCase
java.lang.Exception
public void testConnectionSequence1() throws java.sql.SQLException
java.sql.SQLException
public void testConnectionSequence2() throws java.sql.SQLException
java.sql.SQLException
public void testBackupEncryptedDatabase() throws java.sql.SQLException
java.sql.SQLException
public void testCreateDbFromBackup() throws java.sql.SQLException
java.sql.SQLException
public void testRestoreFrom() throws java.sql.SQLException
java.sql.SQLException
public void testInvalidRestoreFrom() throws java.sql.SQLException
It should be noted that the existing database, which has been previously recovered from the same backup image, is deleted/overwritten even though Derby is unable to boot the backup image.
java.sql.SQLException
public void testCreateWithOddEncryptionKeyLength() throws java.sql.SQLException
java.sql.SQLException
public void testCreateWithInvalidEncryptionKey()
java.lang.String obtainDbName(java.lang.String dbName, java.lang.String subdirectory)
This absolute path is the name of the database (specified) prefixed with
the absolute path to the EXTINOUT directory. The latter is determined by
consulting SupportFilesSetup
.
dbName
- name of the databasesubdirectory
- directory to prefix the database name with (can be
null
). Note that the database name will be prefixed
with the path to the EXTINOUT directory even if this parameter is
null
.SupportFilesSetup
private void createBackupRestore(java.lang.String sourceDb, java.lang.String targetDb) throws java.sql.SQLException
The source db is shutdown, the recovered db is left booted.
sourceDb
- the original database to createtargetDb
- the database to recover tojava.sql.SQLException
private void confirmNonBootedDB(java.lang.String dbName)
dbName
- name of an encrypted databasejunit.framework.AssertionFailedError
- if the database has been
booted (connection may or may not be established)private java.sql.Connection getConnection(java.lang.String dbName, int keyMode) throws java.sql.SQLException
dbName
- name of the databasekeyMode
- what kind of key to use (correct, wrong, invalid, odd)java.sql.SQLException
- if connection failsprivate java.sql.Connection getConnection(java.lang.String dbName, int keyMode, java.lang.String recoveryAttribute) throws java.sql.SQLException
dbName
- name of the databasekeyMode
- what kind of key to use (correct, wrong, invalid, odd)recoveryAttribute
- attribute to recover a database from a backup,
for instance createFrom
or restoreFrom
.
Both the attribute and its value is expected.java.sql.SQLException
- if connection failsprotected void shutdown(java.lang.String databaseName) throws java.sql.SQLException
databaseName
- the name of the databasejava.sql.SQLException
protected void shutdown(java.lang.String databaseName, java.lang.String dir) throws java.sql.SQLException
databaseName
- the name of the databasedir
- sub-directory prefix for the databasejava.sql.SQLException
protected java.sql.Connection createAndPopulateDB(java.lang.String dbName) throws java.sql.SQLException
The method fails with an exception if the database already exists. This is because it is the creation process that is to be tested.
dbName
- name of the database to createjava.sql.SQLException
- if the database already exist, or
a general error happens during database interactionprotected void validateDBContents(java.sql.Connection con) throws java.sql.SQLException
con
- the database to validate the contents ofjunit.framework.AssertionFailedError
- if there is a mismatch
between the data in the database and the modeljava.sql.SQLException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.