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 my...@apache.org on 2014/02/27 02:33:05 UTC

svn commit: r1572384 - in /db/derby/code/branches/10.10: ./ java/drda/org/apache/derby/impl/drda/ java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/ java/testing/org/apache/derbyTesting/junit/

Author: myrnavl
Date: Thu Feb 27 01:33:05 2014
New Revision: 1572384

URL: http://svn.apache.org/r1572384
Log:
DERBY-6457; NetworkServerControl API breaks when username or password contains non-ascii characters
   backport of revision 1560311 from trunk. Original fix / patch contributed by Knut Anders Hatlen

Modified:
    db/derby/code/branches/10.10/   (props changed)
    db/derby/code/branches/10.10/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java

Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1560311

Modified: db/derby/code/branches/10.10/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1572384&r1=1572383&r2=1572384&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java (original)
+++ db/derby/code/branches/10.10/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java Thu Feb 27 01:33:05 2014
@@ -2762,8 +2762,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/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java?rev=1572384&r1=1572383&r2=1572384&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java Thu Feb 27 01:33:05 2014
@@ -51,6 +51,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 String POLICY_FILE_NAME="functionTests/tests/derbynet/NetworkServerControlApiTest.policy";
     private static String TARGET_POLICY_FILE_NAME="server.policy";
     
@@ -166,8 +169,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
@@ -317,7 +339,11 @@ public class NetworkServerControlApiTest
         suite.addTest(decorateTest());
         
         suite = decorateSystemPropertyTests(suite);
-                    
+
+        suite.addTest(decorateShutdownTest(
+                "xtestShutdownWithNonASCIICredentials",
+                NON_ASCII_USER, NON_ASCII_PASSWORD));
+
         return suite;
     }
 
@@ -340,6 +366,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/branches/10.10/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java?rev=1572384&r1=1572383&r2=1572384&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/SystemPropertyTestSetup.java Thu Feb 27 01:33:05 2014
@@ -125,6 +125,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();)
@@ -135,12 +153,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
     {