Index: testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java =================================================================== --- testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java (revision 209299) +++ testing/org/apache/derbyTesting/functionTests/tests/derbynet/dataSourcePermissions_net.java (working copy) @@ -185,9 +185,14 @@ if (TestUtil.isJCCFramework()) { attrs.setProperty("driverType","4"); + /** + * As per the fix of derby-410 + * servername should now default to localhost + */ + attrs.setProperty("serverName","localhost"); } - attrs.setProperty("serverName","localhost"); + attrs.setProperty("portNumber","20000"); //attrs.setProperty("retrieveMessagesFromServerOnGetMessage","true"); return attrs; @@ -246,6 +251,12 @@ { testRetrieveMessageText(); testDescription(); + + //Added for Derby-409 + testConnectionAttributes(); + + //Added for Derby-406 + allUsernameAndPasswordTests(); } /** @@ -361,7 +372,129 @@ } } - + + /** + * Added for Derby-409 + * + * Designed to test combinations of attributes to insure that + * no exceptions are thrown. + */ + public void testConnectionAttributes() { + try { + System.out.println("Begin connection attribute tests"); + testDataSourceConnection("One attribute test: ", + "EDWARD", "noodle", "create=true"); + testDataSourceConnection("Another different attribute: ", + "EDWARD", "noodle", "tracefile=trace.out"); + testDataSourceConnection("Two Attributes: ", + "EDWARD", "noodle", "create=true;tracefile=trace.out"); + System.out.println("End connection attribute tests"); + } + catch (Exception e) + { + System.out.println("FAIL: testSetConnectionAttributes() Unexpected Exception " + e.getMessage()); + e.printStackTrace(System.out); + } + } + + /** + * Added for Derby-406 + * + * Tests DataSource with a number of different username/password + * input combinations. + */ + public void allUsernameAndPasswordTests() { + + try { + System.out.println("Begin username and password tests"); + + testDataSourceConnection("Normal test: ", "EDWARD", "noodle", null); + + testDataSourceConnection("No username or password, only attributes test: ", + null, null, "user=EDWARD;password=noodle"); + + testDataSourceConnection("Bogus username and password, good attributes test: ", + "Whatis", "theMatrix?", "user=EDWARD;password=noodle"); + + testDataSourceConnection("Username, password attribute test: ", + "EDWARD", null, "password=noodle"); + + testDataSourceConnection("Password, username attribute test: ", + null, "noodle", "user=EDWARD"); + + System.out.println("Turning off authentication"); + DataSource ds = getDS("wombat", "EDWARD", "noodle"); + Connection conn = ds.getConnection(); + CallableStatement cs = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)"); + cs.setString(1, "derby.connection.requireAuthentication"); + cs.setString(2, "false"); + cs.execute(); + cs.close(); + cs = null; + conn.close(); + //We have to shut down before the changes will take effect. + shutdown(); + start(); + + testDataSourceConnection("Username, no password test: ", + "EDWARD", null, null); + + testDataSourceConnection("No username, password test: ", + null, "noodle", null); + + testDataSourceConnection("No username, no password test: ", + null, null, null); + + System.out.println("Turning on authentication"); + ds = getDS("wombat", "EDWARD", "noodle"); + conn = ds.getConnection(); + cs = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)"); + cs.setString(1, "derby.connection.requireAuthentication"); + cs.setString(2, "true"); + cs.execute(); + cs.close(); + cs = null; + conn.close(); + shutdown(); + start(); + + System.out.println("End username and password tests"); + } + catch (Exception e) + { + System.out.println("FAIL: allUsernameAndPasswordTests. Unexpected Exception " + e.getMessage()); + e.printStackTrace(System.out); + } + } + + /** + * A method that attempts to retrieve the connection via a datasource + * with the given user, password and connection attributes. + * + * @param testType A string description of the type of test + * @param username The user + * @param password The Password + * @param attributes A string to be added to a properties object. A + * null string means null Property object. + * @throws SQLException + */ + public void testDataSourceConnection(String testType, String username, String password, String attributes) throws SQLException { + try { + System.out.print(testType); + Properties props = null; + if (attributes != null) { + props = new Properties(); + props.put("ConnectionAttributes", attributes); + } + DataSource ds = getDS("wombat", username, password, props); + Connection conn = ds.getConnection(); + conn.close(); + System.out.println("PASS."); + } catch (SQLException e) { + System.out.println("FAIL. Unexpected Exception: "); + e.printStackTrace(System.out); + } + } } Index: testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dataSourcePermissions_net.out =================================================================== --- testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dataSourcePermissions_net.out (revision 209299) +++ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dataSourcePermissions_net.out (working copy) @@ -7,8 +7,8 @@ Checking connections with DataSource EXPECTED SHUTDOWN DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'wombat' shutdown. data source with no default user -EXPECTED CONNFAIL null userid not supported EXPECTED CONNFAIL Connection authorization failure occurred. Reason: userid invalid. +EXPECTED CONNFAIL Connection authorization failure occurred. Reason: userid invalid. DS connected as EDWARD DS connected as FRANCES EXPECTED SHUTDOWN DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'wombat' shutdown. @@ -22,8 +22,8 @@ EXPECTED SHUTDOWN DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'wombat' shutdown. Checking connections with ConnectionPoolDataSource ConnectionPoolDataSource with no default user -EXPECTED CONNFAIL null userid not supported EXPECTED CONNFAIL Connection authorization failure occurred. Reason: userid invalid. +EXPECTED CONNFAIL Connection authorization failure occurred. Reason: userid invalid. CP connected as EDWARD CP connected as FRANCES EXPECTED SHUTDOWN DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'wombat' shutdown. @@ -39,4 +39,23 @@ PASS: Message text not retrieved ** checkMessageText() with retrieveMessageText= true PASS: Message Text retrieved properly +Begin connection attribute tests +One attribute test: PASS. +Another different attribute: PASS. +Two Attributes: PASS. +End connection attribute tests +Begin username and password tests +Normal test: PASS. +No username or password, only attributes test: PASS. +Bogus username and password, good attributes test: PASS. +Username, password attribute test: PASS. +Password, username attribute test: PASS. +Turning off authentication +EXPECTED SHUTDOWN DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'wombat' shutdown. +Username, no password test: PASS. +No username, password test: PASS. +No username, no password test: PASS. +Turning on authentication +EXPECTED SHUTDOWN DERBY SQL error: SQLCODE: -1, SQLSTATE: 08006, SQLERRMC: Database 'wombat' shutdown. +End username and password tests Completed dataSourcePermissions_net Index: client/org/apache/derby/jdbc/ClientBaseDataSource.java =================================================================== --- client/org/apache/derby/jdbc/ClientBaseDataSource.java (revision 209299) +++ client/org/apache/derby/jdbc/ClientBaseDataSource.java (working copy) @@ -136,8 +136,9 @@ // ---------------------------- serverName ----------------------------------- // - // - protected String serverName = null; + // Derby-410 fix. + protected String serverName = propertyDefault_serverName; + public final static String propertyDefault_serverName = "localhost"; public final static String propertyKey_serverName = "serverName"; // serverName is not permitted in a properties object @@ -153,7 +154,8 @@ // Each data source implementation subclass will maintain it's own password property. // This password property may or may not be declared transient, and therefore may be serialized // to a file in clear-text, care must taken by the user to prevent security breaches. - protected String user = null; + // Derby-406 fix + protected String user = propertyDefault_user; public final static String propertyKey_user = "user"; public final static String propertyDefault_user = "APP"; Index: client/org/apache/derby/client/am/Connection.java =================================================================== --- client/org/apache/derby/client/am/Connection.java (revision 209299) +++ client/org/apache/derby/client/am/Connection.java (working copy) @@ -155,7 +155,8 @@ user_ = user; // Extract common properties. - databaseName_ = dataSource.getDatabaseName() + dataSource.getConnectionAttributes(); + // Derby-409 fix + databaseName_ = dataSource.getDatabaseName() + ";" + dataSource.getConnectionAttributes(); retrieveMessageText_ = dataSource.getRetrieveMessageText(); loginTimeout_ = dataSource.getLoginTimeout();