incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r498139 - in /incubator/ftpserver/trunk: core/src/java/org/apache/ftpserver/ ssl-tests/src/test/org/apache/ftpserver/ssl/
Date Sat, 20 Jan 2007 16:26:41 GMT
Author: ngn
Date: Sat Jan 20 08:26:40 2007
New Revision: 498139

URL: http://svn.apache.org/viewvc?view=rev&rev=498139
Log:
Fixing bug when a secure data connection is used and no data sent, as reported by Clinton
Foster (http://permalink.gmane.org/gmane.comp.jakarta.ftpserver.devel/429). Fix as provided
by Clinton and verified by Dave Roberts, thanks!
Adding two unit tests the reproduce the problem, one for listing an empty directory and one
the retriving a zero length file.  

Modified:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnectionFactory.java
    incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
    incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnectionFactory.java?view=diff&rev=498139&r1=498138&r2=498139
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnectionFactory.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnectionFactory.java
Sat Jan 20 08:26:40 2007
@@ -23,6 +23,8 @@
 import java.net.ServerSocket;
 import java.net.Socket;
 
+import javax.net.ssl.SSLSocket;
+
 import org.apache.commons.logging.Log;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.interfaces.DataConnectionConfig;
@@ -241,6 +243,13 @@
             closeDataSocket();
             log.warn("FtpDataConnection.getDataSocket()", ex);
             throw ex;
+        }
+        
+        // Make sure we initate the SSL handshake, or we'll
+        // get an error if we turn out not to send any data
+        // e.g. during the listing of an empty dir
+        if(dataSoc instanceof SSLSocket) {
+            ((SSLSocket)dataSoc).startHandshake();
         }
         
         return dataSoc;

Modified: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java?view=diff&rev=498139&r1=498138&r2=498139
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
Sat Jan 20 08:26:40 2007
@@ -21,10 +21,12 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.InputStream;
 
 import javax.net.ssl.SSLServerSocketFactory;
 
 import org.apache.commons.net.ftp.FTPReply;
+import org.apache.ftpserver.util.IoUtils;
 
 
 public abstract class ExplicitSecurityTestTemplate extends SSLTestTemplate {
@@ -111,5 +113,35 @@
         
         assertTrue(TEST_FILE2.exists());
         assertEquals(TEST_DATA.length, TEST_FILE2.length());
+    }
+    
+    public void testListEmptyDir() throws Exception {
+        client.setRemoteVerificationEnabled(false);
+        client.enterLocalPassiveMode();
+        
+        client.execPROT("P");
+        
+        File dir = new File(ROOT_DIR, "dir");
+        dir.mkdir();
+        
+        client.listFiles(dir.getName());
+    }
+
+    public void testReceiveEmptyFile() throws Exception {
+        client.setRemoteVerificationEnabled(false);
+        client.enterLocalPassiveMode();
+        
+        client.execPROT("P");
+        
+        File file = new File(ROOT_DIR, "foo");
+        file.createNewFile();
+        
+        InputStream is = null;
+        try {
+            is = client.retrieveFileStream(file.getName());
+            assertEquals(-1, is.read(new byte[1024]));
+        } finally {
+            IoUtils.close(is);
+        }
     }
 }

Modified: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java?view=diff&rev=498139&r1=498138&r2=498139
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
Sat Jan 20 08:26:40 2007
@@ -50,7 +50,7 @@
 
     private static final Log log = LogFactory.getLog(SSLTestTemplate.class);
 
-    private static final int DEFAULT_PORT = 12321;
+    private static final int DEFAULT_PORT = 12322;
 
     protected static final String ADMIN_PASSWORD = "admin";
 
@@ -216,6 +216,8 @@
             } catch (FTPConnectionClosedException e) {
                 // try again
             }
+            
+            System.out.println("Retrying!");
             Thread.sleep(500);
             attempts++;
         }



Mime
View raw message