2009-01-16 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 16 Jan 2009 15:40:23 +0000 (15:40 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 16 Jan 2009 15:40:23 +0000 (15:40 -0000)
* FtpWebRequestTest.cs: add directory listing test when the $HOME is
not /.

svn path=/trunk/mcs/; revision=123616

mcs/class/System/Test/System.Net/ChangeLog
mcs/class/System/Test/System.Net/FtpWebRequestTest.cs

index c73f01167c5ddfb9873fd2ef2ff766fde69a18b5..1405437c55de7dce15c560cbdded2f80a0757952 100644 (file)
@@ -1,4 +1,9 @@
 
+2009-01-16 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * FtpWebRequestTest.cs: add directory listing test when the $HOME is
+       not /.
+
 2009-01-12 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * FtpWebRequestTest.cs: test deleting a file.
index af21ebd0ab1e9bb0df479d67fc8115f9dda92690..7c05b4224d0b4a10ab36b3428ba49fab975ec88c 100644 (file)
@@ -254,6 +254,95 @@ namespace MonoTests.System.Net
                        }
                }
 
+               [Test]
+               public void ListDirectory1 ()
+               {
+                       ServerListDirectory sp = new ServerListDirectory ();
+                       sp.Start ();
+                       string uri = String.Format ("ftp://{0}:{1}/somedir/", sp.IPAddress, sp.Port);
+                       try {
+                               FtpWebRequest ftp = (FtpWebRequest) WebRequest.Create (uri);
+                               Console.WriteLine (ftp.RequestUri);
+                               ftp.KeepAlive = false;
+                               ftp.Timeout = 5000;
+                               ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
+                               ftp.UseBinary = true;
+                               using (FtpWebResponse response = (FtpWebResponse) ftp.GetResponse ()) {
+                                       StreamReader reader = new StreamReader (response.GetResponseStream ());
+                                       string result = reader.ReadToEnd ();
+                                       Assert.IsTrue ((int) response.StatusCode >= 200 && (int) response.StatusCode < 300, "DF#01");
+                               }
+                       } catch (Exception e) {
+                               Console.WriteLine (e);
+                               if (!String.IsNullOrEmpty (sp.Where))
+                                       throw new Exception (sp.Where);
+                               throw;
+                       } finally {
+                               sp.Stop ();
+                       }
+               }
+
+               class ServerListDirectory : FtpServer {
+                       protected override void Run ()
+                       {
+                               Socket client = control.Accept ();
+                               NetworkStream ns = new NetworkStream (client, false);
+                               StreamWriter writer = new StreamWriter (ns, Encoding.ASCII);
+                               StreamReader reader = new StreamReader (ns, Encoding.UTF8);
+                               if (!DoAnonymousLogin (writer, reader)) {
+                                       client.Close ();
+                                       return;
+                               }
+
+                               if (!DoInitialDialog (writer, reader, "/home/someuser", "/home/someuser/somedir/")) {
+                                       client.Close ();
+                                       return;
+                               }
+
+                               string str = reader.ReadLine ();
+                               if (str != "PASV") {
+                                       Where = "PASV";
+                                       client.Close ();
+                                       return;
+                               }
+
+                               IPEndPoint end_data = (IPEndPoint) data.LocalEndPoint;
+                               byte [] addr_bytes = end_data.Address.GetAddressBytes ();
+                               byte [] port = new byte [2];
+                               port[0] = (byte) ((end_data.Port >> 8) & 255);
+                               port[1] = (byte) (end_data.Port & 255);
+                               StringBuilder sb = new StringBuilder ("227 Passive (");
+                               foreach (byte b in addr_bytes) {
+                                       sb.AppendFormat ("{0},", b);    
+                               }
+                               sb.AppendFormat ("{0},", port [0]);     
+                               sb.AppendFormat ("{0})", port [1]);     
+                               writer.WriteLine (sb.ToString ());
+                               writer.Flush ();
+
+                               str = reader.ReadLine ();
+                               if (str != "LIST") {
+                                       Where = "LIST - '" + str + "'";
+                                       client.Close ();
+                                       return;
+                               }
+                               writer.WriteLine ("150 Here comes the directory listing");
+                               writer.Flush ();
+
+                               Socket data_cnc = data.Accept ();
+                               byte [] dontcare = Encoding.ASCII.GetBytes ("drwxr-xr-x    2 ftp      ftp          4096 Oct 27 20:17 tests");
+                               data_cnc.Send (dontcare, 1, SocketFlags.None);
+                               data_cnc.Close ();
+                               writer.WriteLine ("226 Directory send Ok");
+                               writer.Flush ();
+                               if (!EndConversation (writer, reader)) {
+                                       client.Close ();
+                                       return;
+                               }
+                               client.Close ();
+                       }
+               }
+
                class ServerDeleteFile : FtpServer {
                        protected override void Run ()
                        {