incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r475381 - in /incubator/ftpserver/trunk/core/src: java/org/apache/ftpserver/command/ test/org/apache/ftpserver/clienttests/
Date Wed, 15 Nov 2006 19:49:51 GMT
Author: ngn
Date: Wed Nov 15 11:49:49 2006
New Revision: 475381

URL: http://svn.apache.org/viewvc?view=rev&rev=475381
Log:
Adding additional unit tests based on a coverage analysis

Added:
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RmDirTest.java
  (with props)
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/SystTest.java
  (with props)
Modified:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MD5.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SYST.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrieveTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MD5.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MD5.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MD5.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MD5.java Wed Nov
15 11:49:49 2006
@@ -61,6 +61,11 @@
         
         // print file information
         String argument = request.getArgument();
+        
+        if(argument == null || argument.trim().length() == 0) {
+            out.send(504, "MD5.invalid", null);
+            return;
+        }
 
         String[] fileNames = null;
         if(isMMD5) {

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SYST.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SYST.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SYST.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/SYST.java Wed Nov
15 11:49:49 2006
@@ -57,7 +57,7 @@
             systemName = systemName.toUpperCase();
             systemName = systemName.replace(' ', '-');
         }
-        
+        System.out.println(systemName);
         // print server system info
         out.send(215, "SYST", systemName);
     }

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DeleteTest.java
Wed Nov 15 11:49:49 2006
@@ -64,7 +64,7 @@
         TEST_FILE1.createNewFile();
         
         assertTrue(TEST_FILE1.exists());
-        
+
         assertFalse(client.deleteFile(TEST_FILE1.getName()));
         
         assertTrue(TEST_FILE1.exists());

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/DirectoryTest.java
Wed Nov 15 11:49:49 2006
@@ -45,6 +45,14 @@
         assertTrue(TEST_DIR1.exists());
     }
 
+    public void testMkdirNoDirectoryName() throws Exception {
+        assertEquals(501 ,client.sendCommand("MKD"));
+    }
+
+    public void testMkdirInValidDirectoryName() throws Exception {
+        assertEquals(550 ,client.sendCommand("MKD foo:bar;foo"));
+    }
+
     public void testMkdirDouble() throws Exception {
         assertFalse(TEST_DIR1.exists());
         assertFalse(TEST_DIR_IN_DIR1.exists());

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/FtpMd5Test.java
Wed Nov 15 11:49:49 2006
@@ -26,6 +26,7 @@
 import org.apache.commons.codec.digest.DigestUtils;
 
 
+
 public class FtpMd5Test extends ClientTestTemplate {
     private static final File TEST_FILE1 = new File(ROOT_DIR, "test1.txt");
     private static final File TEST_FILE_WITH_SPACE = new File(ROOT_DIR, "test 2.txt");
@@ -65,6 +66,18 @@
         assertEquals(251, client.sendCommand("MD5 " + fileName));
 
         assertHash(testDataHash, client.getReplyString(), fileName);
+    }
+    
+    public void testMd5NoFileName() throws Exception {        
+        assertEquals(504, client.sendCommand("MD5"));
+    }
+
+    public void testMd5NonExistingFile() throws Exception {
+        assertFalse(TEST_FILE1.exists());
+        
+        String fileName = TEST_FILE1.getName();
+        
+        assertEquals(504, client.sendCommand("MD5 " + fileName));
     }
 
     public void testMd5WithSpaceInFileName() throws Exception {

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
Wed Nov 15 11:49:49 2006
@@ -44,6 +44,11 @@
     public void testLoginWithAccount() throws Exception {
         assertTrue(client.login(ADMIN_USERNAME, ADMIN_PASSWORD, UNKNOWN_PASSWORD));
     }
+
+    public void testLoginWithEmptyPassword() throws Exception {
+        assertTrue(FTPReply.isPositiveIntermediate(client.user(ADMIN_USERNAME)));
+        assertEquals(501, client.sendCommand("PASS"));
+    }
     
     public void testLoginIncorrectPassword() throws Exception {
         assertFalse(client.login(ADMIN_USERNAME, UNKNOWN_PASSWORD));

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrieveTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrieveTest.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrieveTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RetrieveTest.java
Wed Nov 15 11:49:49 2006
@@ -27,6 +27,7 @@
 
 public class RetrieveTest extends ClientTestTemplate {
     private static final String TEST_FILENAME = "test.txt";
+    private static final File TEST_FILE = new File(ROOT_DIR, TEST_FILENAME);
 
     private static byte[] testData = null;
     
@@ -42,27 +43,37 @@
     }
 
     public void testRetrieve() throws Exception {
-        File testFile = new File(ROOT_DIR, TEST_FILENAME);
         
-        writeDataToFile(testFile, testData);
+        writeDataToFile(TEST_FILE, testData);
 
-        assertTrue(testFile.exists());
+        assertTrue(TEST_FILE.exists());
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         assertTrue(client.retrieveFile(TEST_FILENAME, baos));
         
-        assertTrue(testFile.exists());
+        assertTrue(TEST_FILE.exists());
         TestUtil.assertArraysEqual(testData, baos.toByteArray());
     }
 
+    public void testRetrieveNoFileName() throws Exception {
+        assertEquals(501, client.sendCommand("RETR"));
+    }
+    
+    public void testRetrieveInValidFileName() throws Exception {
+        assertEquals(550 ,client.sendCommand("RETR foo:bar;foo"));
+    }
+
+    public void testRetrieveDirectory() throws Exception {
+        TEST_FILE.mkdirs();
+        assertEquals(550, client.sendCommand("RETR "+ TEST_FILE.getName()));
+    }
+    
     public void testRetrieveWithRestart() throws Exception {
         int skipLen = 4;
         
-        File testFile = new File(ROOT_DIR, TEST_FILENAME);
-        
-        writeDataToFile(testFile, testData);
+        writeDataToFile(TEST_FILE, testData);
         
-        assertTrue(testFile.exists());
+        assertTrue(TEST_FILE.exists());
         
         client.setRestartOffset(4);
 
@@ -73,7 +84,7 @@
         byte[] expected = new byte[len];
         System.arraycopy(testData, skipLen, expected, 0, len);
         
-        assertTrue(testFile.exists());
+        assertTrue(TEST_FILE.exists());
         TestUtil.assertArraysEqual(expected, baos.toByteArray());
     }
     
@@ -95,9 +106,8 @@
     }
 
     public void testRetrieveNonExistingFile() throws Exception {
-        File testFile = new File(ROOT_DIR, TEST_FILENAME);
         
-        assertFalse(testFile.exists());
+        assertFalse(TEST_FILE.exists());
         
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         assertFalse(client.retrieveFile(TEST_FILENAME, baos));

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RmDirTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RmDirTest.java?view=auto&rev=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RmDirTest.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RmDirTest.java
Wed Nov 15 11:49:49 2006
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */  
+
+package org.apache.ftpserver.clienttests;
+
+import java.io.File;
+
+
+public class RmDirTest extends ClientTestTemplate {
+    private static final File TEST_DIR1 = new File(ROOT_DIR, "dir1");
+    private static final File TEST_DIR_IN_DIR1 = new File(TEST_DIR1, "dir3");
+
+    /* (non-Javadoc)
+     * @see org.apache.ftpserver.clienttests.ClientTestTemplate#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+    }
+
+    public void testRmdir() throws Exception {
+        assertTrue(TEST_DIR1.mkdirs());
+        assertTrue(client.removeDirectory(TEST_DIR1.getName()));
+        
+        assertFalse(TEST_DIR1.exists());
+    }
+
+    public void testRmdirNestedDir() throws Exception {
+        assertTrue(TEST_DIR_IN_DIR1.mkdirs());
+        assertTrue(client.removeDirectory(TEST_DIR1.getName() + "/" + TEST_DIR_IN_DIR1.getName()));
+        
+        assertTrue(TEST_DIR1.exists());
+        assertFalse(TEST_DIR_IN_DIR1.exists());
+    }
+
+    public void testRmdirNoDirectoryName() throws Exception {
+        assertEquals(501 ,client.sendCommand("RMD"));
+    }
+
+    public void testRmdirInValidDirectoryName() throws Exception {
+        assertEquals(550 ,client.sendCommand("RMD foo:bar;foo"));
+    }
+
+    public void testRmdirOnFile() throws Exception {
+        assertTrue(TEST_DIR1.createNewFile());
+        
+        assertFalse(client.removeDirectory(TEST_DIR1.getName()));
+        
+        assertTrue(TEST_DIR1.exists());
+    }
+    
+    public void testRmdirWithoutWriteAccess() throws Exception {
+        client.rein();
+        client.login(ANONYMOUS_USERNAME, ANONYMOUS_PASSWORD);
+        
+        assertTrue(TEST_DIR1.mkdirs());
+        
+        assertFalse(client.removeDirectory(TEST_DIR1.getName()));
+        
+        assertTrue(TEST_DIR1.exists());
+    }
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/RmDirTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java?view=diff&rev=475381&r1=475380&r2=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/StoreTest.java
Wed Nov 15 11:49:49 2006
@@ -64,6 +64,16 @@
         TestUtil.assertFileEqual(testData, testFile);
     }
 
+    public void testStoreNoFileName() throws Exception {
+        assertEquals(501, client.sendCommand("STOR"));
+    }
+    /* TODO: this test now fails as we don't detect the invalid file name
+     * A future improvment would be to detect this and report an error
+    public void testStoreInValidFileName() throws Exception {
+        assertEquals(550 ,client.sendCommand("STOR foo:bar;foo"));
+    }
+    */
+    
     public void testStoreWithRestart() throws Exception {
         File testFile = new File(ROOT_DIR, TEST_FILENAME);
         writeDataToFile(testFile, testData);

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/SystTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/SystTest.java?view=auto&rev=475381
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/SystTest.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/SystTest.java
Wed Nov 15 11:49:49 2006
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */  
+
+package org.apache.ftpserver.clienttests;
+
+import org.apache.commons.net.ftp.FTPReply;
+
+
+public class SystTest extends ClientTestTemplate {
+
+    /* (non-Javadoc)
+     * @see org.apache.ftpserver.clienttests.ClientTestTemplate#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+    }
+
+    public void testSyst() throws Exception {
+        assertTrue(FTPReply.isPositiveCompletion(client.syst()));
+        // hardcoded to Unix as that's the type of list etc we use
+        assertEquals("215 UNIX Type: Apache FTP Server", client.getReplyString().trim());
+    }
+
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/SystTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message