db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r699366 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/tools/ testing/org/apache/derbyTesting/junit/ tools/org/apache/derby/impl/tools/ij/ tools/org/...
Date Fri, 26 Sep 2008 15:26:08 GMT
Author: dag
Date: Fri Sep 26 08:26:08 2008
New Revision: 699366

URL: http://svn.apache.org/viewvc?rev=699366&view=rev
Log:
DERBY-3137 SQL roles: add catalog support

Patch DERBY-3137-ijfix:

- a fix to ij's "SHOW ROLES" command to give an error message if the driver is
  not Derby embedded or client. The command does not use database metadata,
  so the generated select from SYS.SYSROLES is inherently Derby specific.

- a new simple test for the command, tools/ij_show_roles.sql (run via
  JUnit/ToolScripts.java). The test is run both the embedded and via the network client.

- a fix to escape case normal form role names to protect the role id
  when performing DROP ROLE in CleanDatabaseTestSetup#removeRoles (the
  test above provoked this bug).


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles.out
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles.sql
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Session.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijException.java
    db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles.out?rev=699366&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles.out
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/ij_show_roles.out
Fri Sep 26 08:26:08 2008
@@ -0,0 +1,16 @@
+ij> -- Run via ToolScripts.java
+create role a;
+0 rows inserted/updated/deleted
+ij> create role b;
+0 rows inserted/updated/deleted
+ij> create role """eve""";
+0 rows inserted/updated/deleted
+ij> grant a to b;
+0 rows inserted/updated/deleted
+ij> show roles;
+ROLEID                        
+------------------------------
+"eve"                         
+A                             
+B                             
+ij> 

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java?rev=699366&r1=699365&r2=699366&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ToolScripts.java
Fri Sep 26 08:26:08 2008
@@ -24,6 +24,7 @@
 
 import org.apache.derbyTesting.functionTests.util.ScriptTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
 import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -73,6 +74,14 @@
     private static final String[] JDBC3_TESTS = {
     };
 
+
+    /**
+     * Tests that run with authentication and SQL authorization on.
+     */
+    private static final String[][] SQLAUTHORIZATION_TESTS = {
+        {"ij_show_roles", "test_dbo"}
+    };
+
     /**
      * Run a set of tool scripts (.sql files) passed in on the
      * command line. Note the .sql suffix must not be provided as
@@ -97,10 +106,12 @@
         suite.addTest(getSuite(EMBEDDED_TESTS));
         if (JDBC.vmSupportsJDBC3())
             suite.addTest(getSuite(JDBC3_TESTS));
+        suite.addTest(getAuthorizationSuite(SQLAUTHORIZATION_TESTS));
 
         // Set up the scripts run with the network client
         TestSuite clientTests = new TestSuite("ToolScripts:client");
         clientTests.addTest(getSuite(CLIENT_AND_EMBEDDED_TESTS));
+        clientTests.addTest(getAuthorizationSuite(SQLAUTHORIZATION_TESTS));
         clientTests.addTest(getSuite(CLIENT_TESTS));
         Test client = TestConfiguration.clientServerDecorator(clientTests);
 
@@ -131,4 +142,26 @@
 
         return getIJConfig(suite);
     }
+
+    /**
+     * Return a suite of tool tests from the list of script names. Each test is
+     * surrounded in a decorator that cleans the database, and adds
+     * authentication and authorization given the user for each script.
+     */
+    private static Test getAuthorizationSuite(String[][] list) {
+        TestSuite suite = new TestSuite("Tool scripts w/authorization");
+        final String PWSUFFIX = "pwSuffix";
+
+        for (int i = 0; i < list.length; i++) {
+            Test clean = new CleanDatabaseTestSetup(
+                new ToolScripts(list[i][0]));
+            suite.addTest(
+                TestConfiguration.sqlAuthorizationDecorator(
+                    DatabasePropertyTestSetup.builtinAuthentication(
+                        clean, new String[]{list[i][1]}, PWSUFFIX)));
+        }
+
+        return getIJConfig(suite);
+    }
+
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles.sql?rev=699366&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles.sql
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles.sql
Fri Sep 26 08:26:08 2008
@@ -0,0 +1,7 @@
+-- Run via ToolScripts.java
+create role a;
+create role b;
+create role """eve""";
+grant a to b;
+
+show roles;

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ij_show_roles.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java?rev=699366&r1=699365&r2=699366&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java
Fri Sep 26 08:26:08 2008
@@ -252,7 +252,7 @@
             "cast(isdef as char(1)) = 'Y'");
 
         while (rs.next()) {
-            dropStm.executeUpdate("DROP ROLE " + rs.getString(1));
+            dropStm.executeUpdate("DROP ROLE " + JDBC.escape(rs.getString(1)));
         }
 
         stm.close();

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Session.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Session.java?rev=699366&r1=699365&r2=699366&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Session.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/Session.java Fri Sep 26
08:26:08 2008
@@ -52,6 +52,8 @@
 	Hashtable asyncStmts = new Hashtable();
 	boolean isJCC= false;      // Is this the IBM UNIVERSAL DRIVER.
 	boolean isDNC = false;     // Is this the Derby Network Client JDBC Driver
+	boolean isEmbeddedDerby = false; // Is this the Derby Embedded JDBC Driver
+
 	Session(Connection newConn, String newTag, String newName) {
 		conn = newConn;
 		tag = newTag;
@@ -61,7 +63,8 @@
 		{
 			isJCC = conn.getMetaData().getDriverName().startsWith("IBM DB2 JDBC Universal Driver");
 			isDNC = conn.getMetaData().getDriverName().startsWith("Apache Derby Network Client");
-
+			isEmbeddedDerby = conn.getMetaData().getDriverName().
+				startsWith("Apache Derby Embedded JDBC Driver");
 		}
 		catch (SQLException se)
 		{
@@ -85,6 +88,11 @@
 		return isDNC;
 	}
 
+	boolean getIsEmbeddedDerby()
+	{
+		return isEmbeddedDerby;
+	}
+
 	String getName() {
 		return name;
 	}

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj?rev=699366&r1=699365&r2=699366&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj Fri Sep 26 08:26:08
2008
@@ -837,18 +837,24 @@
 		try {
 			haveConnection();
 
-			rs = theConnection.createStatement().executeQuery
-				("SELECT ROLEID FROM SYS.SYSROLES WHERE ISDEF='Y' " +
-				 "ORDER BY ROLEID ASC");
-
-			int[] displayColumns = new int[] {
-				rs.findColumn("ROLEID")
-			};
-			int[] columnWidths = new int[] {
-				30
-			};
-
-			return new ijResultSetResult(rs, displayColumns, columnWidths);
+			if (currentConnEnv.getSession().getIsDNC() ||
+				currentConnEnv.getSession().getIsEmbeddedDerby()) {
+				rs = theConnection.createStatement().executeQuery
+					("SELECT ROLEID FROM SYS.SYSROLES WHERE ISDEF='Y' " +
+					 "ORDER BY ROLEID ASC");
+
+				int[] displayColumns = new int[] {
+					rs.findColumn("ROLEID")
+				};
+				int[] columnWidths = new int[] {
+					30
+				};
+
+				return new ijResultSetResult(rs, displayColumns, columnWidths);
+			} else {
+				throw ijException.notAvailableForDriver(
+					theConnection.getMetaData().getDriverName());
+			}
 		} catch (SQLException e) {
 			if(rs!=null)
 				rs.close();

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijException.java?rev=699366&r1=699365&r2=699366&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijException.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ijException.java Fri Sep
26 08:26:08 2008
@@ -62,6 +62,7 @@
 	private final static String StatementGetWarningsFailed = "IJ_UnabToGetWar_22";
 	private final static String WaitInterrupted = "IJ_WaitForStatI";
 	private final static String ZeroInvalidForAbsolute = "IJ_0IsAnInvaVal";
+	private final static String NotAvailableForDriver = "IJ_NotAvailForDriver";
 
 	public ijException(String message) {
 		super(message);
@@ -149,4 +150,8 @@
 	public static ijException zeroInvalidForAbsolute() {
 		return new ijException(LocalizedResource.getMessage(ZeroInvalidForAbsolute));
 	}
+	public static ijException notAvailableForDriver(String s) {
+		return new ijException(
+			LocalizedResource.getMessage(NotAvailableForDriver, s));
+	}
 }

Modified: db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties?rev=699366&r1=699365&r2=699366&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/loc/toolsmessages.properties Fri Sep 26
08:26:08 2008
@@ -144,6 +144,7 @@
 IJ_UnabToGetWar_22=Unable to get warnings for statement
 IJ_WaitForStatI=Wait for statement interrupted: {0}
 IJ_0IsAnInvaVal=0 is an invalid value for ABSOLUTE <integer> <cursorname>
+IJ_NotAvailForDriver=command not available for this driver: {0}
 # From ijFatalException.java
 IJ_FataExceTerm=Fatal Exception; terminating
 IJ_Fata01=FatalException: {0}: {1}



Mime
View raw message