Selaa lähdekoodia

Fixed BUG from revision 16218. Changed ConnectionInfo so if ProxyType is set to None, constructor will not validate proxy parameters (host, port specifically), and when set to ProxyType.None, host, username and password is set to null in the other constructors - instead of string.Empty.
Added test, and special notes for Workitem 1140: SftpClient.IsConnected property does not get set to False after call to Disconnect()

Kenneth_aa_cp 13 vuotta sitten
vanhempi
sitoutus
3be0eaf09b

+ 25 - 0
Renci.SshClient/Renci.SshNet.Tests/ConnectionTest.cs

@@ -317,5 +317,30 @@ namespace Renci.SshNet.Tests
             var ret = new ConnectionInfo(Resources.HOST, 22, Resources.USERNAME, ProxyTypes.None, Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD, null);
             ret.Authenticate(null);
         }
+
+        [TestMethod]
+        [WorkItem(1140)]
+        [TestCategory("BaseClient")]
+        [Description("Test whether IsConnected is false after disconnect.")]
+        [Owner("Kenneth_aa")]
+        public void Test_BaseClient_IsConnected_True_After_Disconnect()
+        {
+            // 2012-04-29 - Kenneth_aa
+            // The problem with this test, is that after SSH Net calls .Disconnect(), the library doesn't wait
+            // for the server to confirm disconnect before IsConnected is checked. And now I'm not mentioning
+            // anything about Socket's either.
+
+            var connectionInfo = new PasswordAuthenticationMethod(Resources.USERNAME, Resources.PASSWORD);
+
+            using (SftpClient client = new SftpClient(Resources.HOST, Int32.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD))
+            {
+                client.Connect();
+                Assert.AreEqual<bool>(true, client.IsConnected, "IsConnected is not true after Connect() was called.");
+
+                client.Disconnect();
+
+                Assert.AreEqual<bool>(false, client.IsConnected, "IsConnected is true after Disconnect() was called.");
+            }
+        }
 	}
 }

+ 10 - 7
Renci.SshClient/Renci.SshNet/ConnectionInfo.cs

@@ -192,7 +192,7 @@ namespace Renci.SshNet
         /// <param name="username">The username.</param>
         /// <param name="authenticationMethods">The authentication methods.</param>
         public ConnectionInfo(string host, string username, params AuthenticationMethod[] authenticationMethods)
-            : this(host, 22, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, authenticationMethods)
+            : this(host, 22, username, ProxyTypes.None, null, 0, null, null, authenticationMethods)
         {
         }
 
@@ -204,7 +204,7 @@ namespace Renci.SshNet
         /// <param name="username">The username.</param>
         /// <param name="authenticationMethods">The authentication methods.</param>
         public ConnectionInfo(string host, int port, string username, params AuthenticationMethod[] authenticationMethods)
-            : this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, authenticationMethods)
+            : this(host, port, username, ProxyTypes.None, null, 0, null, null, authenticationMethods)
         {
         }
 
@@ -232,15 +232,18 @@ namespace Renci.SshNet
             if (!host.IsValidHost())
                 throw new ArgumentException("host");
 
-            if (string.IsNullOrEmpty(proxyHost) && !proxyHost.IsValidHost())
-                throw new ArgumentException("proxyHost");
+            if (proxyType != ProxyTypes.None)
+            {
+                if (string.IsNullOrEmpty(proxyHost) && !proxyHost.IsValidHost())
+                    throw new ArgumentException("proxyHost");
+
+                if (!proxyPort.IsValidPort())
+                    throw new ArgumentOutOfRangeException("proxyPort");
+            }
 
             if (!port.IsValidPort())
                 throw new ArgumentOutOfRangeException("port");
 
-            if (!proxyPort.IsValidPort())
-                throw new ArgumentOutOfRangeException("proxyPort");
-
             if (username.IsNullOrWhiteSpace())
                 throw new ArgumentException("username");