فهرست منبع

Improve exception messages further.

drieseng 4 سال پیش
والد
کامیت
767fafbfc1

+ 6 - 1
src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs

@@ -86,7 +86,12 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             Assert.IsNotNull(_actualException);
             Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual("Server response does not contain SSH protocol identification. Connection to remote server was closed before any data was received.", _actualException.Message);
+            Assert.AreEqual(string.Format("The server response does not contain an SSH protocol identification.{0}" +
+                                          "The connection to the remote server was closed before any data was received.{0}{0}" +
+                                          "More information on the Protocol Version Exchange is available here:{0}" +
+                                          "https://tools.ietf.org/html/rfc4253#section-4.2",
+                                          Environment.NewLine),
+                            _actualException.Message);
         }
 
         [TestMethod]

+ 6 - 2
src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs

@@ -88,8 +88,12 @@ namespace Renci.SshNet.Tests.Classes.Connection
         [TestMethod]
         public void StartShouldHaveThrownSshConnectionException()
         {
-            var expectedMessage = "The identification string contains a null character at position 0x00000005:" + Environment.NewLine +
-                                  "  00000000  ED 95 9C 21 00                                   ...!.";
+            var expectedMessage = string.Format("The server response contains a null character at position 0x00000005:{0}{0}" +
+                                                "  00000000  ED 95 9C 21 00                                   ...!.{0}{0}" +
+                                                "A server must not send a null character before the Protocol Version Exchange is complete.{0}{0}" +
+                                                "More information is available here:{0}" +
+                                                "https://tools.ietf.org/html/rfc4253#section-4.2",
+                                                Environment.NewLine);
 
             Assert.IsNotNull(_actualException);
             Assert.IsNull(_actualException.InnerException);

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs

@@ -89,9 +89,9 @@ namespace Renci.SshNet.Tests.Classes.Connection
         [TestMethod]
         public void StartShouldHaveThrownSshConnectionException()
         {
-            var expectedMessage = string.Format("The server response does not contain an SSH protocol identification:{0}{0}" +
+            var expectedMessage = string.Format("The server response does not contain an SSH identification string:{0}{0}" +
                                                 "  00000000  53 53 48 2D 32 2E 30 0D 0A                       SSH-2.0..{0}{0}" +
-                                                "More information is available here:{0}" +
+                                                "More information on the Protocol Version Exchange is available here:{0}" +
                                                 "https://tools.ietf.org/html/rfc4253#section-4.2",
                                                 Environment.NewLine);
 

+ 9 - 5
src/Renci.SshNet/Connection/ProtocolVersionExchange.cs

@@ -52,11 +52,16 @@ namespace Renci.SshNet.Connection
                 {
                     if (bytesReceived.Count == 0)
                     {
-                        throw new SshConnectionException("The server response does not contain an SSH protocol identification. Connection to remote server was closed before any data was received.", DisconnectReason.ConnectionLost);
+                        throw new SshConnectionException(string.Format("The server response does not contain an SSH identification string.{0}" +
+                                                                       "The connection to the remote server was closed before any data was received.{0}{0}" +
+                                                                       "More information on the Protocol Version Exchange is available here:{0}" +
+                                                                       "https://tools.ietf.org/html/rfc4253#section-4.2",
+                                                                       Environment.NewLine),
+                                                         DisconnectReason.ConnectionLost);
                     }
 
-                    throw new SshConnectionException(string.Format("The server response does not contain an SSH protocol identification:{0}{0}{1}{0}{0}" +
-                                                                   "More information is available here:{0}" +
+                    throw new SshConnectionException(string.Format("The server response does not contain an SSH identification string:{0}{0}{1}{0}{0}" +
+                                                                   "More information on the Protocol Version Exchange is available here:{0}" +
                                                                    "https://tools.ietf.org/html/rfc4253#section-4.2",
                                                                    Environment.NewLine,
                                                                    PacketDump.Create(bytesReceived, 2)),
@@ -120,8 +125,7 @@ namespace Renci.SshNet.Connection
                 {
                     throw new SshConnectionException(string.Format(CultureInfo.InvariantCulture,
                                                                    "The server response contains a null character at position 0x{0:X8}:{1}{1}{2}{1}{1}" +
-                                                                   "A server must not send a null character before the Protocol Version Exchange is{1}" +
-                                                                   "complete.{1}{1}" +
+                                                                   "A server must not send a null character before the Protocol Version Exchange is complete.{1}{1}" +
                                                                    "More information is available here:{1}" +
                                                                    "https://tools.ietf.org/html/rfc4253#section-4.2",
                                                                    buffer.Count,