org.apache.derbyTesting.functionTests.tests.jdbcapi
Class DboPowersTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.jdbcapi.DboPowersTest
All Implemented Interfaces:
junit.framework.Test

public class DboPowersTest
extends BaseJDBCTestCase

This JUnit tests enforcement of dbo (=database owner) powers, cf. DERBY-2264. The tests are run in the cross product (cardinality 10) of contexts: {client/server, embedded} x {no authentication, authentication and authentication/sqlAuthorization} x {data base owner, other user } One could consider removing the client/server suites to speed up this test as it does not add much value given the nature of the changes.


Field Summary
private  int _authLevel
           
private  java.lang.String _dbo
           
private  java.lang.String _dboPassword
           
private static int AUTHENTICATION
           
(package private) static java.lang.String[] encryptionTests
          Enumerates the encryption tests
private static int NOAUTHENTICATION
           
(package private) static java.lang.String pwSuffix
           
private static java.lang.String[] secLevelNames
           
private static int SQLAUTHORIZATION
           
(package private) static java.lang.String[][] users
          Users used by both dboShutdownSuite and dboEncryptionSuite
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
DboPowersTest(java.lang.String name, int authLevel)
          Create a new instance of DboPowersTest (for shutdown test)
DboPowersTest(java.lang.String name, int authLevel, java.lang.String dbo, java.lang.String dboPassword)
          Create a new instance of DboPowersTest (for encryption and hard upgrade tests).
 
Method Summary
private  void bringDbDown()
          Shut down database, as db owner (not testing that power here)
private  void bringDbUp(java.lang.String bootPassword)
          Boot database back up after encryption using current user, should succeed
private static junit.framework.Test dboEncryptionSuite(java.lang.String framework)
          Construct suite of tests for database encryption action
private static junit.framework.Test dboHardUpgradeSuite(java.lang.String framework)
          Construct suite of tests for hard upgrade database action NOTE: there is no real upgrade going on here since the database is created with the same version, but the checking is performed nonetheless, which is what we are testing here.
private static junit.framework.Test dboShutdownSuite(java.lang.String framework)
          Construct suite of tests for shutdown database action
private  void derby3038(java.sql.Connection con)
          Make and call a stored procedure which opens a nested connection to expose DERBY-3038.
static void derby3038Proc()
           
private  void doEncrypt(java.lang.String bootPassword)
          Encrypt database, as owner (not testing encryption power here)
static junit.framework.Test suite()
          Construct top level suite in this JUnit test
 void testEncrypt()
          Test database encryption for an already created database.
 void testHardUpgrade()
          Test database upgrade power enforcement
 void testReEncrypt()
          Test database re-encryption for an already encrypted database.
 void testShutDown()
          Test database shutdown power enforcement
private  void vetAttempt(java.lang.String user, java.sql.SQLException e, java.lang.String state, java.lang.String operation)
          Decide if the result of trying operation yields expected result.
private  void vetEncryptionAttempt(java.lang.String user, java.sql.SQLException e)
          Decide if the result of trying to (re)encrypt the database is compliant with the semantics introduced by DERBY-2264.
private  void vetHardUpgradeAttempt(java.lang.String user, java.sql.SQLException e)
          Decide if the result of trying to hard upgrade the database is compliant with the semantics introduced by DERBY-2264.
private  void vetShutdownException(java.lang.String user, java.sql.SQLException e)
          Decide if the result of trying to shut down the database is compliant with the semantics introduced by DERBY-2264.
private static junit.framework.Test wrapEncryptionUserTests(int autLev)
          Wraps the encryption fixtures in decorators to run with data base owner and one other valid user.
private static junit.framework.Test wrapHardUpgradeUserTests(int autLev)
          Wraps the shutdown fixture in decorators to run with data base owner and one other valid user.
private static junit.framework.Test wrapShutdownUserTests(int autLev)
          Wraps the shutdown fixture in decorators to run with data base owner and one other valid user.
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
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, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_authLevel

private final int _authLevel

_dbo

private final java.lang.String _dbo

_dboPassword

private final java.lang.String _dboPassword

NOAUTHENTICATION

private static final int NOAUTHENTICATION
See Also:
Constant Field Values

AUTHENTICATION

private static final int AUTHENTICATION
See Also:
Constant Field Values

SQLAUTHORIZATION

private static final int SQLAUTHORIZATION
See Also:
Constant Field Values

secLevelNames

private static final java.lang.String[] secLevelNames

users

static final java.lang.String[][] users
Users used by both dboShutdownSuite and dboEncryptionSuite


pwSuffix

static final java.lang.String pwSuffix
See Also:
Constant Field Values

encryptionTests

static final java.lang.String[] encryptionTests
Enumerates the encryption tests

Constructor Detail

DboPowersTest

public DboPowersTest(java.lang.String name,
                     int authLevel)
Create a new instance of DboPowersTest (for shutdown test)

Parameters:
name - Fixture name
authLevel - authentication level with which test is run

DboPowersTest

public DboPowersTest(java.lang.String name,
                     int authLevel,
                     java.lang.String dbo,
                     java.lang.String dboPassword)
Create a new instance of DboPowersTest (for encryption and hard upgrade tests). The database owner credentials is needed to always be able to perform the restricted operations (when they are not under test, but used as part of a test fixture for another operation).

Parameters:
name - Fixture name
authLevel - authentication level with which test is run
dbo - Database owner
dboPassword - Database owner's password
Method Detail

suite

public static junit.framework.Test suite()
Construct top level suite in this JUnit test

Returns:
A suite containing embedded and client suites

dboShutdownSuite

private static junit.framework.Test dboShutdownSuite(java.lang.String framework)
Construct suite of tests for shutdown database action

Parameters:
framework - Derby framework name
Returns:
A suite containing the test case for shutdown incarnated for the three security levels no authentication, authentication, and authentication plus sqlAuthorization, The latter two has an instance for dbo, and one for an ordinary user, so there are in all five incarnations of tests.

wrapShutdownUserTests

private static junit.framework.Test wrapShutdownUserTests(int autLev)
Wraps the shutdown fixture in decorators to run with data base owner and one other valid user.

Parameters:
autLev - security context to use

testShutDown

public void testShutDown()
                  throws java.sql.SQLException
Test database shutdown power enforcement

Throws:
java.sql.SQLException

vetShutdownException

private void vetShutdownException(java.lang.String user,
                                  java.sql.SQLException e)
Decide if the result of trying to shut down the database is compliant with the semantics introduced by DERBY-2264.


dboEncryptionSuite

private static junit.framework.Test dboEncryptionSuite(java.lang.String framework)
Construct suite of tests for database encryption action

Parameters:
framework - Derby framework name
Returns:
A suite containing the test case for encryption incarnated for the three security levels no authentication, authentication, and authentication plus sqlAuthorization, The latter two has an instance for dbo, and one for an ordinary user, so there are in all five incarnations of tests.

wrapEncryptionUserTests

private static junit.framework.Test wrapEncryptionUserTests(int autLev)
Wraps the encryption fixtures in decorators to run with data base owner and one other valid user.

Parameters:
autLev - security context to use

testEncrypt

public void testEncrypt()
                 throws java.sql.SQLException
Test database encryption for an already created database. Note: The test needs to shut down the database for the single use decorators to work.

Throws:
java.sql.SQLException

testReEncrypt

public void testReEncrypt()
                   throws java.sql.SQLException
Test database re-encryption for an already encrypted database. Note: The test needs to shut down database for the single use decorators to work.

Throws:
java.sql.SQLException

doEncrypt

private void doEncrypt(java.lang.String bootPassword)
                throws java.sql.SQLException
Encrypt database, as owner (not testing encryption power here)

Parameters:
bootPassword -
Throws:
java.sql.SQLException

bringDbDown

private void bringDbDown()
Shut down database, as db owner (not testing that power here)


bringDbUp

private void bringDbUp(java.lang.String bootPassword)
                throws java.sql.SQLException
Boot database back up after encryption using current user, should succeed

Parameters:
bootPassword - Boot using this bootPassword
Throws:
java.sql.SQLException

vetEncryptionAttempt

private void vetEncryptionAttempt(java.lang.String user,
                                  java.sql.SQLException e)
Decide if the result of trying to (re)encrypt the database is compliant with the semantics introduced by DERBY-2264.

Parameters:
user - The db user under which we tried to encrypt
e - Exception caught during attempt, if any

dboHardUpgradeSuite

private static junit.framework.Test dboHardUpgradeSuite(java.lang.String framework)
Construct suite of tests for hard upgrade database action NOTE: there is no real upgrade going on here since the database is created with the same version, but the checking is performed nonetheless, which is what we are testing here. This saves us from having to create a database with an old version of Derby to test this power.

Parameters:
framework - Derby framework name
Returns:
A suite containing the test case for hard upgrade incarnated for the three security levels no authentication, authentication, and authentication plus sqlAuthorization, The latter two has an instance for dbo, and one for an ordinary user, so there are in all five incarnations of tests.

wrapHardUpgradeUserTests

private static junit.framework.Test wrapHardUpgradeUserTests(int autLev)
Wraps the shutdown fixture in decorators to run with data base owner and one other valid user.

Parameters:
autLev - security context to use

testHardUpgrade

public void testHardUpgrade()
                     throws java.sql.SQLException
Test database upgrade power enforcement

Throws:
java.sql.SQLException

vetHardUpgradeAttempt

private void vetHardUpgradeAttempt(java.lang.String user,
                                   java.sql.SQLException e)
Decide if the result of trying to hard upgrade the database is compliant with the semantics introduced by DERBY-2264.

Parameters:
user - The db user under which we tried to upgrade
e - Exception caught during attempt, if any

vetAttempt

private void vetAttempt(java.lang.String user,
                        java.sql.SQLException e,
                        java.lang.String state,
                        java.lang.String operation)
Decide if the result of trying operation yields expected result.

Parameters:
user - The db user under which we tried to upgrade
e - Exception caught during attempted operation, if any
state - The expected SQL state if this operation fails due to insufficient power
operation - string describing the operation attempted

derby3038

private void derby3038(java.sql.Connection con)
                throws java.sql.SQLException
Make and call a stored procedure which opens a nested connection to expose DERBY-3038.

Throws:
java.sql.SQLException

derby3038Proc

public static void derby3038Proc()
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

Built on Thu 2009-11-26 18:42:53-0800, from revision 884739

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.