public class GrantRevokeTest extends BaseJDBCTestCase
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
users
The set of users available for grant/revoke testing
|
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Constructor and Description |
---|
GrantRevokeTest(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
appendColumnValue(java.lang.StringBuffer sb,
int type)
Append a particular SQL datatype value to the given StringBuffer
|
void |
assertAllPrivileges(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String table,
java.lang.String[] columns)
Assert all privileges for a given user / schema / table / column set
|
void |
assertDeletePrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String table)
Assert that a user has delete privilege on a given table / column
|
void |
assertFunctionPrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String function,
boolean forProcedure)
Assert that a user has function execute privilege on a given table / column
|
void |
assertInsertPrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String table,
java.lang.String[] columns)
Assert that a user has insert privilege on a given table / column
|
void |
assertPrivilegeMetadata(boolean hasPrivilege,
java.lang.String type,
java.lang.String user,
java.lang.String schema,
java.lang.String table,
java.lang.String[] columns)
Assert that a specific privilege exists by checking the
database metadata available to a user
|
void |
assertProcedurePrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String procedure)
Assert that a user has procedure execute privilege on a given table / column
|
void |
assertReferencesPrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String table,
java.lang.String[] columns)
Assert that a user has references privilege on a given table / column
|
void |
assertSelectPrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String table,
java.lang.String[] columns)
Assert that a user has select privilege on a given table / column
|
void |
assertTriggerPrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String table)
Assert that a user has trigger execute privilege on a given table / column
|
void |
assertUpdatePrivilege(boolean hasPrivilege,
java.lang.String user,
java.lang.String schema,
java.lang.String table,
java.lang.String[] columns)
Assert that a user has update privilege on a given table / column
|
static junit.framework.Test |
basesuite()
One set of grant/revoke tests for either client/server or embedded.
|
(package private) static java.lang.String |
columnListAsString(java.lang.String[] columns)
Return the given String array as a comma separated String
|
(package private) java.lang.String[] |
getAllColumns(java.lang.String schema,
java.lang.String table)
Get all the columns in a given schema / table
|
(package private) java.lang.String |
getColumnDataType(java.lang.String schema,
java.lang.String table,
java.lang.String column)
Given a schema, table, and column as Strings, return the datatype of
the column as a String.
|
(package private) void |
grant(java.sql.Connection c,
java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String user)
Grant a single permission to a single user for a given connection.
|
(package private) void |
grant(java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String user)
Grant a single permission to a single user.
|
(package private) void |
grant(java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String[] users)
Grant a SQL permission to a set of users.
|
(package private) void |
grant(java.lang.String grantor,
java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String user)
Grant a single permission from a specific user to a single user.
|
(package private) void |
revoke(java.sql.Connection c,
java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String user)
Revoke a single permission to a single user for a given connection.
|
(package private) void |
revoke(java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String user)
Revoke a single permission from a single user.
|
(package private) void |
revoke(java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String[] users)
Revoke a SQL permission from a set of users.
|
(package private) void |
revoke(java.lang.String revoker,
java.lang.String perm,
java.lang.String schema,
java.lang.String table,
java.lang.String user)
Revoke a single permission from a specific user to a single user.
|
static int |
s1F1()
Utility function to test grant/revoke
|
static void |
s1F1P()
Utility method to test procedure with identical name to a
function
|
static void |
s1P1()
A utility method to test procedures with test grant/revoke
|
static int |
s2F1a()
Another utility function to test grant/revoke - placeholder for
future if SPECIFIC names are implemented.
|
static int |
s2F2()
Another utility function to test grant/revoke
|
static junit.framework.Test |
suite()
Most tests run in embedded only, since they are only checking DDL
statements.
|
void |
testAllPrivileges() |
void |
testColumnPrivileges() |
void |
testFunctionWithSameProcedureName() |
void |
testGrantDatabaseMetaDataMethods()
Test Grant/Revoke related DatabaseMetaData methods.
|
void |
testGrantDeleteWithColumnList() |
void |
testGrantExecuteOnTable() |
void |
testGrantExecuteWithRestrict() |
void |
testGrantOnFunctionWithBadSchema() |
void |
testGrantOnNonexistantColumn() |
void |
testGrantOnNonexistantFunction() |
void |
testGrantOnNonexistantFunctionForProcedure() |
void |
testGrantOnNonexistantProcedure() |
void |
testGrantOnNonexistantProcedureForFunction() |
void |
testGrantOnNonexistantSchema() |
void |
testGrantOnNonexistantTable() |
void |
testGrantOnProcedure() |
void |
testGrantOnProcedureWithBadSchema() |
void |
testGrantRevokeSelectWithRestrict() |
void |
testGrantRevokeWithoutRestrict() |
void |
testGrantRollbackAndCommit()
Test grant statements before, during, and after a rolled-back
transaction
|
void |
testGrantSelectOnRoutine() |
void |
testGrantTriggerWithColumnList() |
void |
testInvalidGrantAction() |
void |
testInvalidReservedWordAction() |
void |
testOtherUserCannotRevokeOwnerPrivileges() |
void |
testPublicRoutinePrivileges() |
void |
testPublicTablePrivileges() |
void |
testRevokeExecutePrivileges() |
void |
testRevokeExecuteWithPublicPrivilege() |
void |
testRevokeMultiplePermissionsMultipleUsers() |
void |
testRevokeRollbackAndCommit() |
void |
testRevokeSingleTableSingleUser() |
void |
testRevokeWithNoPermissions()
Test revoke statements when user already has no permissions.
|
void |
testRevokeWithPublicPrivilege() |
void |
testSimpleGrant() |
void |
testViewDefinersRights()
DERBY-5292
|
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, tearDown, 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
public static final java.lang.String[] users
public static junit.framework.Test suite()
public static junit.framework.Test basesuite()
public void testSimpleGrant() throws java.lang.Exception
java.lang.Exception
public void testAllPrivileges() throws java.lang.Exception
java.lang.Exception
public void testColumnPrivileges() throws java.lang.Exception
java.lang.Exception
public void testFunctionWithSameProcedureName() throws java.lang.Exception
java.lang.Exception
public void testGrantOnProcedure() throws java.lang.Exception
java.lang.Exception
public void testPublicTablePrivileges() throws java.lang.Exception
java.lang.Exception
public void testPublicRoutinePrivileges() throws java.lang.Exception
java.lang.Exception
public void testGrantRollbackAndCommit() throws java.sql.SQLException
java.sql.SQLException
public void testGrantDatabaseMetaDataMethods() throws java.lang.Exception
java.lang.Exception
public void testRevokeWithNoPermissions() throws java.lang.Exception
java.lang.Exception
public void testRevokeSingleTableSingleUser() throws java.lang.Exception
java.lang.Exception
public void testRevokeMultiplePermissionsMultipleUsers() throws java.sql.SQLException
java.sql.SQLException
public void testRevokeExecutePrivileges() throws java.lang.Exception
java.lang.Exception
public void testRevokeWithPublicPrivilege() throws java.lang.Exception
java.lang.Exception
public void testRevokeExecuteWithPublicPrivilege() throws java.lang.Exception
java.lang.Exception
public void testRevokeRollbackAndCommit() throws java.lang.Exception
java.lang.Exception
public void testInvalidGrantAction() throws java.lang.Exception
java.lang.Exception
public void testInvalidReservedWordAction() throws java.lang.Exception
java.lang.Exception
public void testGrantOnNonexistantColumn() throws java.lang.Exception
java.lang.Exception
public void testGrantOnNonexistantSchema() throws java.lang.Exception
java.lang.Exception
public void testGrantOnNonexistantTable() throws java.lang.Exception
java.lang.Exception
public void testGrantOnFunctionWithBadSchema() throws java.lang.Exception
java.lang.Exception
public void testGrantOnNonexistantFunction() throws java.lang.Exception
java.lang.Exception
public void testGrantOnNonexistantFunctionForProcedure() throws java.lang.Exception
java.lang.Exception
public void testGrantOnProcedureWithBadSchema() throws java.lang.Exception
java.lang.Exception
public void testGrantOnNonexistantProcedure() throws java.lang.Exception
java.lang.Exception
public void testGrantOnNonexistantProcedureForFunction() throws java.lang.Exception
java.lang.Exception
public void testGrantExecuteOnTable() throws java.lang.Exception
java.lang.Exception
public void testGrantSelectOnRoutine() throws java.lang.Exception
java.lang.Exception
public void testGrantExecuteWithRestrict() throws java.lang.Exception
java.lang.Exception
public void testGrantRevokeWithoutRestrict() throws java.lang.Exception
java.lang.Exception
public void testGrantRevokeSelectWithRestrict() throws java.lang.Exception
java.lang.Exception
public void testGrantDeleteWithColumnList() throws java.lang.Exception
java.lang.Exception
public void testGrantTriggerWithColumnList() throws java.lang.Exception
java.lang.Exception
public void testOtherUserCannotRevokeOwnerPrivileges() throws java.sql.SQLException
java.sql.SQLException
public void testViewDefinersRights() throws java.lang.Exception
java.lang.Exception
void grant(java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String user) throws java.sql.SQLException
perm
- Permission to grantschema
- Schema on which to grant permissiontable
- Table on which to grant permissionuser
- User to grant permission tojava.lang.Exception
- throws all exceptionsjava.sql.SQLException
void grant(java.lang.String grantor, java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String user) throws java.sql.SQLException
grantor
- Grantor of permissionperm
- Permission to grantschema
- Schema on which to grant permissiontable
- Table on which to grant permissionuser
- User to grant permission tojava.lang.Exception
- throws all exceptionsjava.sql.SQLException
void grant(java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String[] users) throws java.sql.SQLException
perm
- The permission to grantschema
- the schema on which to grant the permissiontable
- the table on which to grant the permissionusers
- an Array of users to grant the permissionjava.lang.Exception
- throws all exceptionsjava.sql.SQLException
void grant(java.sql.Connection c, java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String user) throws java.sql.SQLException
c
- the Connection used to execute the grant statementperm
- Permission to grantschema
- Schema on which to grant permissiontable
- Table on which to grant permissionuser
- User to grant permission tojava.lang.Exception
- throws all exceptionsjava.sql.SQLException
void revoke(java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String user) throws java.sql.SQLException
perm
- Permission to revokeschema
- Schema on which to revoke permissiontable
- Table on which to revoke permissionuser
- User to revoke permissionsjava.lang.Exception
- throws all exceptionsjava.sql.SQLException
void revoke(java.lang.String revoker, java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String user) throws java.sql.SQLException
revoker
- Grantor of permissionperm
- Permission to revokeschema
- Schema on which to revoke permissiontable
- Table on which to revoke permissionuser
- User to revoke permission tojava.lang.Exception
- throws all exceptionsjava.sql.SQLException
void revoke(java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String[] users) throws java.sql.SQLException
perm
- The permission to revokeschema
- the schema on which to revoke the permissiontable
- the table on which to revoke the permissionusers
- an array of users to revoke the permissionjava.lang.Exception
- throws all exceptionsjava.sql.SQLException
void revoke(java.sql.Connection c, java.lang.String perm, java.lang.String schema, java.lang.String table, java.lang.String user) throws java.sql.SQLException
c
- the connection to execute the revoke statementperm
- Permission to revokeschema
- Schema on which to revoke permissiontable
- Table on which to revoke permissionuser
- User to revoke permissionjava.lang.Exception
- throws all exceptionsjava.sql.SQLException
public static int s1F1()
public static int s2F1a()
public static int s2F2()
public static void s1F1P()
public static void s1P1()
public void assertAllPrivileges(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String table, java.lang.String[] columns) throws java.sql.SQLException
hasPrivilege
- whether we expect the given user to have the privilegeuser
- the user to checkschema
- the schema to checktable
- the table to checkcolumns
- the set of columns to check for the userjava.sql.SQLException
public void assertSelectPrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String table, java.lang.String[] columns) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checktable
- the table to checkcolumns
- the set of columns to checkjava.sql.SQLException
- throws all exceptionspublic void assertDeletePrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String table) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checktable
- the table to checkjava.sql.SQLException
- throws all exceptionspublic void assertInsertPrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String table, java.lang.String[] columns) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checktable
- the table to checkcolumns
- the set of columns to checkjava.sql.SQLException
- throws all exceptionspublic void assertUpdatePrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String table, java.lang.String[] columns) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checktable
- the table to checkcolumns
- the set of columns to checkjava.sql.SQLException
- throws all exceptionspublic void assertReferencesPrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String table, java.lang.String[] columns) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checktable
- the table to checkcolumns
- the set of columns to checkjava.sql.SQLException
- throws all exceptionspublic void assertTriggerPrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String table) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checktable
- the table to checkjava.sql.SQLException
- throws all exceptionspublic void assertFunctionPrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String function, boolean forProcedure) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checkfunction
- the function to checkforProcedure
- true if checking for lack of function execute privilege against procedure of same name.java.sql.SQLException
- throws all exceptionspublic void assertProcedurePrivilege(boolean hasPrivilege, java.lang.String user, java.lang.String schema, java.lang.String procedure) throws java.sql.SQLException
hasPrivilege
- whether or not the user has the privilegeuser
- the user to checkschema
- the schema to checkprocedure
- the name of the procedure to checkjava.sql.SQLException
- throws all exceptionspublic void assertPrivilegeMetadata(boolean hasPrivilege, java.lang.String type, java.lang.String user, java.lang.String schema, java.lang.String table, java.lang.String[] columns) throws java.sql.SQLException
hasPrivilege
- true if we expect the caller to have the privilegetype
- type of privilege, e.g. SELECT, INSERT, DELETE, etc.user
- the user to checkschema
- the schema to checktable
- the table to checkcolumns
- the set of columns to check, or all columns if nulljava.sql.SQLException
static void appendColumnValue(java.lang.StringBuffer sb, int type)
sb
- the StringBuffer to append the valuetype
- the java.sql.Types value to appendstatic java.lang.String columnListAsString(java.lang.String[] columns)
columns
- an array of columns to formatjava.lang.String[] getAllColumns(java.lang.String schema, java.lang.String table) throws java.sql.SQLException
java.sql.SQLException
java.lang.String getColumnDataType(java.lang.String schema, java.lang.String table, java.lang.String column) throws java.sql.SQLException
schema
- the schema for the table in which the column residestable
- the table containing the column to checkcolumn
- the column to get the data type as a Stringjava.sql.SQLException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.