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/10/25 20:28:15 UTC
svn commit: r588304 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
Author: djd
Date: Thu Oct 25 11:28:15 2007
New Revision: 588304
URL: http://svn.apache.org/viewvc?rev=588304&view=rev
Log:
DERBY-3150 Add some testing of user identifier casing for JDBC connection requests including two commented out cases that fail.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java?rev=588304&r1=588303&r2=588304&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AuthenticationTest.java Thu Oct 25 11:28:15 2007
@@ -29,6 +29,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.Locale;
import java.util.Properties;
import javax.sql.DataSource;
@@ -51,7 +52,8 @@
private static final String PASSWORD_SUFFIX = "suf2ix";
private static final String USERS[] =
- {"APP","dan","kreg","jeff","ames","jerry","francois","jamie","howardR"};
+ {"APP","dan","kreg","jeff","ames","jerry","francois","jamie","howardR",
+ "\"eVe\""};
private static final String zeus = "\u0396\u0395\u03A5\u03A3";
private static final String apollo = "\u0391\u09A0\u039F\u039B\u039B\u039A\u0390";
@@ -83,6 +85,9 @@
"testConnectShutdownAuthentication");
setBaseProps(suite, test);
+ test = new AuthenticationTest("testUserCasing");
+ setBaseProps(suite, test);
+
test = new AuthenticationTest("testUserFunctions");
setBaseProps(suite, test);
@@ -145,6 +150,123 @@
fail("failed to unset properties");
}
super.tearDown();
+ }
+
+ /**
+ * Test how user names behave with casing.
+ * @throws SQLException
+ */
+ public void testUserCasing() throws SQLException
+ {
+ for (int i = 0; i < USERS.length; i++)
+ {
+ String jdbcUserName = USERS[i];
+ boolean delimited = jdbcUserName.charAt(0) == '"';
+ String normalUserName;
+ if (delimited)
+ {
+ normalUserName = jdbcUserName.substring(1,
+ jdbcUserName.length() - 1);
+ }
+ else
+ {
+ normalUserName = jdbcUserName.toUpperCase(Locale.ENGLISH);
+ }
+
+ String password = USERS[i] + PASSWORD_SUFFIX;
+
+ userCasingTest(jdbcUserName, normalUserName, password);
+
+ if (!delimited)
+ {
+
+ if (!normalUserName.equals(jdbcUserName))
+ {
+ // Test connecting via the normalized name
+ // but only if it wasn't already tested.
+ // E.g. connect as "DAN" for user DAN as opposed
+ // to the user being defined as dan (regular identifier).
+
+ // DERBY-3150 disable this test until bug is fixed.
+ //userCasingTest(normalUserName, normalUserName, password);
+ }
+
+ // Test with the normalized name quoted as a delimited identifer.
+ // E.g. connect as "DAN" for user DAN
+
+ // DERBY-3150 disable this test until bug is fixed.
+ // userCasingTest("\"" + normalUserName + "\"",
+ // normalUserName, password);
+ }
+
+ }
+ }
+
+ /**
+ * Test the user casing obtaining connections a variety of ways.
+ * @param jdbcUserName User name to be used to obtain the connection via JDBC
+ * @param normalUserName Normalized form of the user connection.
+ * @param password Password for the user.
+ * @throws SQLException
+ */
+ private void userCasingTest(String jdbcUserName, String normalUserName,
+ String password) throws SQLException
+ {
+ // Default test mechanism to get a connection.
+ userCasingTest(jdbcUserName, normalUserName,
+ openDefaultConnection(jdbcUserName, password));
+
+
+ DataSource ds = JDBCDataSource.getDataSource();
+
+ // DataSource using explict user
+ userCasingTest(jdbcUserName, normalUserName,
+ ds.getConnection(jdbcUserName, password));
+
+ JDBCDataSource.setBeanProperty(ds, "user", jdbcUserName);
+ JDBCDataSource.setBeanProperty(ds, "password", password);
+ userCasingTest(jdbcUserName, normalUserName,
+ ds.getConnection());
+ }
+
+ /**
+ *
+ * @param jdbcUserName User name as passed into the JDBC connection request.
+ * @param normalUserName Normalized user name.
+ * @param connUser Connection for the user, closed by this method.
+ * @throws SQLException
+ */
+ private void userCasingTest(String jdbcUserName, String normalUserName,
+ Connection connUser) throws SQLException
+ {
+ assertNormalUserName(normalUserName, connUser);
+
+ JDBC.cleanup(connUser);
+ }
+
+ /**
+ * Assert that the user name returned by various mechanisms
+ * matches the normal user name.
+ * @param normalUserName
+ * @param conn
+ * @throws SQLException
+ */
+ private void assertNormalUserName(String normalUserName, Connection connUser)
+ throws SQLException
+ {
+ //assertEquals("DatabaseMetaData.getUserName",
+ // normalUserName, connUser.getMetaData().getUserName());
+
+ Statement s = connUser.createStatement();
+
+ JDBC.assertSingleValueResultSet(s.executeQuery("VALUES CURRENT_USER"),
+ normalUserName);
+ JDBC.assertSingleValueResultSet(s.executeQuery("VALUES SESSION_USER"),
+ normalUserName);
+ JDBC.assertSingleValueResultSet(s.executeQuery("VALUES {fn user()}"),
+ normalUserName);
+ s.close();
+
}