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 ka...@apache.org on 2014/01/22 11:50:25 UTC
svn commit: r1560311 - in /db/derby/code/trunk/java:
drda/org/apache/derby/impl/drda/
testing/org/apache/derbyTesting/functionTests/tests/derbynet/
testing/org/apache/derbyTesting/junit/
Author: kahatlen
Date: Wed Jan 22 10:50:24 2014
New Revision: 1560311
URL: http://svn.apache.org/r1560311
Log:
DERBY-6457: NetworkServerControl API breaks when username or password
contains non-ascii characters
Make NetworkServerControlImpl.writeLDString() write the length in
bytes instead of characters to match how it is read by
NetworkServerControlImpl.readLDString().
Modified:
db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1560311&r1=1560310&r2=1560311&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java Wed Jan 22 10:50:24 2014
@@ -2780,8 +2780,9 @@ public final class NetworkServerControlI
}
else
{
- commandOs.writeShort(msg.length());
- writeString(msg);
+ byte[] msgBytes = msg.getBytes(DEFAULT_ENCODING);
+ commandOs.writeShort(msgBytes.length);
+ commandOs.write(msgBytes);
}
}
catch (IOException e)
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java?rev=1560311&r1=1560310&r2=1560311&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java Wed Jan 22 10:50:24 2014
@@ -47,6 +47,9 @@ import junit.framework.TestSuite;
public class NetworkServerControlApiTest extends BaseJDBCTestCase {
+ private static final String NON_ASCII_USER = "bj\u00F8rn";
+ private static final String NON_ASCII_PASSWORD = "l\u00F8yndom";
+
private static final String POLICY_FILE_NAME =
"org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.policy";
@@ -162,8 +165,27 @@ public class NetworkServerControlApiTest
assertFalse(conn.getMetaData().isReadOnly());
assertTrue(fileExists(derbysystemhome+"/trace/Server1.trace"));
}
-
-
+
+ /**
+ * Run the shutdown command with credentials that contain non-ASCII
+ * characters. Regression test case for DERBY-6457.
+ */
+ public void xtestShutdownWithNonASCIICredentials() throws Exception {
+ NetworkServerControl control =
+ NetworkServerTestSetup.getNetworkServerControl();
+
+ // Verify that the server is up.
+ NetworkServerTestSetup.pingForServerStart(control);
+
+ // Shut down the server with the default credentials, which contain
+ // non-ASCII characters. See NON_ASCII_USER and NON_ASCII_PASSWORD.
+ // This call used to hang forever before DERBY-6457 was fixed.
+ control.shutdown();
+
+ // Verify that the server is down.
+ NetworkServerTestSetup.pingForServerUp(control, null, false);
+ }
+
/**
* Test NetworkServerControl ping command.
* @throws Exception
@@ -250,7 +272,11 @@ public class NetworkServerControlApiTest
suite.addTest(decorateTest());
suite = decorateSystemPropertyTests(suite);
-
+
+ suite.addTest(decorateShutdownTest(
+ "xtestShutdownWithNonASCIICredentials",
+ NON_ASCII_USER, NON_ASCII_PASSWORD));
+
return suite;
}
@@ -273,6 +299,30 @@ public class NetworkServerControlApiTest
return suite;
}
+ /**
+ * Decorate a test case that will attempt to shut down a network server
+ * using the supplied credentials. The network server will run with
+ * authentication enabled.
+ *
+ * @param testName name of the test case to decorate
+ * @param user the user that should attempt to shut down the server
+ * @param password the password to be used when shutting down the server
+ * @return the decorated test case
+ */
+ private static Test decorateShutdownTest(String testName,
+ String user, String password) {
+ Properties props = new Properties();
+ props.setProperty("derby.connection.requireAuthentication", "true");
+ props.setProperty("derby.authentication.provider", "BUILTIN");
+ props.setProperty("derby.user." + user, password);
+
+ Test test = new NetworkServerControlApiTest(testName);
+ test = TestConfiguration.clientServerDecorator(test);
+ test = new SystemPropertyTestSetup(test, props, true);
+ test = TestConfiguration.changeUserDecorator(test, user, password);
+ return test;
+ }
+
// test fixtures from maxthreads
public void test_04_MaxThreads_0() throws Exception {
NetworkServerControl server = new NetworkServerControl(InetAddress.getLocalHost(),TestConfiguration.getCurrent().getPort());
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java?rev=1560311&r1=1560310&r2=1560311&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java Wed Jan 22 10:50:24 2014
@@ -130,6 +130,24 @@ public class SystemPropertyTestSetup ext
protected void tearDown()
throws java.lang.Exception
{
+ // Shut down the engine to restore any static properties. Do that
+ // before the properties are reset to their old values, since the
+ // engine shutdown may rely on some of the system properties. For
+ // example, the system properties could contain the user database
+ // (in derby.user.* style properties), and clearing those first
+ // would lead to "invalid authentication" errors when attempting
+ // to shut down the engine.
+ try {
+ if (staticProperties) {
+ TestConfiguration.getCurrent().shutdownEngine();
+ }
+ } finally {
+ restoreOldPropertyValues();
+ oldValues = null;
+ }
+ }
+
+ private void restoreOldPropertyValues() throws Exception {
// Clear all the system properties set by the new set
// that will not be reset by the old set.
for (Enumeration e = newValues.propertyNames(); e.hasMoreElements();)
@@ -140,12 +158,8 @@ public class SystemPropertyTestSetup ext
}
// and then reset nay old values
setProperties(oldValues);
- // shutdown engine to restore any static properties
- if (staticProperties)
- TestConfiguration.getCurrent().shutdownEngine();
- oldValues = null;
}
-
+
private void setProperties(Properties values)
throws PrivilegedActionException
{