Fix bug with SslStream Read behavior.
authorLakshmi Priya Sekar <lasekar@microsoft.com>
Fri, 19 Jan 2018 00:36:42 +0000 (16:36 -0800)
committerLakshmi Priya Sekar <lasekar@microsoft.com>
Fri, 19 Jan 2018 00:36:42 +0000 (16:36 -0800)
Commit migrated from https://github.com/dotnet/corefx/commit/3542bcf21a328e227799a4b84475328d7ffed3ff

src/libraries/System.Net.Security/src/System/Net/Security/SslStreamInternal.cs
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamAllowRenegotiationTests.cs
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNetworkStreamTest.cs

index 294e44e..99e2f8b 100644 (file)
@@ -282,7 +282,7 @@ namespace System.Net.Security
                             _sslState.ReplyOnReAuthentication(extraBuffer);
 
                             // Loop on read.
-                            return -1;
+                            continue;
                         }
 
                         if (message.CloseConnection)
index 4e37a94..a570d3c 100644 (file)
@@ -52,11 +52,8 @@ namespace System.Net.Security.Tests
                 // Initiate Read operation, that results in starting renegotiation as per server response to the above request.
                 int bytesRead = await ssl.ReadAsync(message, 0, message.Length);
 
-                // SslStream.ReadAsync should return -1 bytes, indicating renegotiation operation is in progress.
-                Assert.Equal(-1, bytesRead);
-
-                // Do another Read, to get the HTTP response from the server, after successful renegotiation.
-                bytesRead = await ssl.ReadAsync(message, 0, message.Length);
+                // There's no good way to ensure renegotiation happened in the test.
+                // Under the debugger, we can see this test hits the renegotiation codepath.
                 Assert.InRange(bytesRead, 1, message.Length);
                 Assert.Contains("HTTP/1.1 200 OK", Encoding.UTF8.GetString(message));
             }
index 9822a2e..2d02da1 100644 (file)
@@ -101,11 +101,8 @@ namespace System.Net.Security.Tests
                 // Initiate Read operation, that results in starting renegotiation as per server response to the above request.
                 int bytesRead = await ssl.ReadAsync(message, 0, message.Length);
 
-                // SslStream.ReadAsync should return -1 bytes, indicating renegotiation operation is in progress.
-                Assert.Equal(-1, bytesRead);
-
-                // Do another Read, to get the HTTP response from the server, after successful renegotiation.
-                bytesRead = await ssl.ReadAsync(message, 0, message.Length);
+                // There's no good way to ensure renegotiation happened in the test.
+                // Under the debugger, we can see this test hits the renegotiation codepath.
                 Assert.InRange(bytesRead, 1, message.Length);
                 Assert.Contains("HTTP/1.1 200 OK", Encoding.UTF8.GetString(message));
             }