Skip to content

Commit 767fafb

Browse files
committed
Improve exception messages further.
1 parent f60f24f commit 767fafb

4 files changed

+23
-10
lines changed

src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ public void StartShouldHaveThrownSshConnectionException()
8686
{
8787
Assert.IsNotNull(_actualException);
8888
Assert.IsNull(_actualException.InnerException);
89-
Assert.AreEqual("Server response does not contain SSH protocol identification. Connection to remote server was closed before any data was received.", _actualException.Message);
89+
Assert.AreEqual(string.Format("The server response does not contain an SSH protocol identification.{0}" +
90+
"The connection to the remote server was closed before any data was received.{0}{0}" +
91+
"More information on the Protocol Version Exchange is available here:{0}" +
92+
"https://tools.ietf.org/html/rfc4253#section-4.2",
93+
Environment.NewLine),
94+
_actualException.Message);
9095
}
9196

9297
[TestMethod]

src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ protected void Act()
8888
[TestMethod]
8989
public void StartShouldHaveThrownSshConnectionException()
9090
{
91-
var expectedMessage = "The identification string contains a null character at position 0x00000005:" + Environment.NewLine +
92-
" 00000000 ED 95 9C 21 00 ...!.";
91+
var expectedMessage = string.Format("The server response contains a null character at position 0x00000005:{0}{0}" +
92+
" 00000000 ED 95 9C 21 00 ...!.{0}{0}" +
93+
"A server must not send a null character before the Protocol Version Exchange is complete.{0}{0}" +
94+
"More information is available here:{0}" +
95+
"https://tools.ietf.org/html/rfc4253#section-4.2",
96+
Environment.NewLine);
9397

9498
Assert.IsNotNull(_actualException);
9599
Assert.IsNull(_actualException.InnerException);

src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ protected void Act()
8989
[TestMethod]
9090
public void StartShouldHaveThrownSshConnectionException()
9191
{
92-
var expectedMessage = string.Format("The server response does not contain an SSH protocol identification:{0}{0}" +
92+
var expectedMessage = string.Format("The server response does not contain an SSH identification string:{0}{0}" +
9393
" 00000000 53 53 48 2D 32 2E 30 0D 0A SSH-2.0..{0}{0}" +
94-
"More information is available here:{0}" +
94+
"More information on the Protocol Version Exchange is available here:{0}" +
9595
"https://tools.ietf.org/html/rfc4253#section-4.2",
9696
Environment.NewLine);
9797

src/Renci.SshNet/Connection/ProtocolVersionExchange.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ public SshIdentification Start(string clientVersion, Socket socket, TimeSpan tim
5252
{
5353
if (bytesReceived.Count == 0)
5454
{
55-
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);
55+
throw new SshConnectionException(string.Format("The server response does not contain an SSH identification string.{0}" +
56+
"The connection to the remote server was closed before any data was received.{0}{0}" +
57+
"More information on the Protocol Version Exchange is available here:{0}" +
58+
"https://tools.ietf.org/html/rfc4253#section-4.2",
59+
Environment.NewLine),
60+
DisconnectReason.ConnectionLost);
5661
}
5762

58-
throw new SshConnectionException(string.Format("The server response does not contain an SSH protocol identification:{0}{0}{1}{0}{0}" +
59-
"More information is available here:{0}" +
63+
throw new SshConnectionException(string.Format("The server response does not contain an SSH identification string:{0}{0}{1}{0}{0}" +
64+
"More information on the Protocol Version Exchange is available here:{0}" +
6065
"https://tools.ietf.org/html/rfc4253#section-4.2",
6166
Environment.NewLine,
6267
PacketDump.Create(bytesReceived, 2)),
@@ -120,8 +125,7 @@ private static string SocketReadLine(Socket socket, TimeSpan timeout, List<byte>
120125
{
121126
throw new SshConnectionException(string.Format(CultureInfo.InvariantCulture,
122127
"The server response contains a null character at position 0x{0:X8}:{1}{1}{2}{1}{1}" +
123-
"A server must not send a null character before the Protocol Version Exchange is{1}" +
124-
"complete.{1}{1}" +
128+
"A server must not send a null character before the Protocol Version Exchange is complete.{1}{1}" +
125129
"More information is available here:{1}" +
126130
"https://tools.ietf.org/html/rfc4253#section-4.2",
127131
buffer.Count,

0 commit comments

Comments
 (0)