From c2ffb0f70e203aefffe8e178fe0ae4654e6ce80b Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Tue, 17 Dec 2019 14:31:47 -0800 Subject: [PATCH] add test for nested ssl authentication (#873) * add test for nested ssl authentication * feedback from review --- .../FunctionalTests/SslStreamNetworkStreamTest.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNetworkStreamTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNetworkStreamTest.cs index 03099eb..cf47a4c 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNetworkStreamTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNetworkStreamTest.cs @@ -2,12 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.IO; using System.Net.Sockets; +using System.Net.Test.Common; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; - using Xunit; namespace System.Net.Security.Tests @@ -167,6 +168,22 @@ namespace System.Net.Security.Tests } } + [Fact] + public async Task SslStream_NestedAuth_Throws() + { + VirtualNetwork network = new VirtualNetwork(); + + using (var clientStream = new VirtualNetworkStream(network, isServer: false)) + using (var serverStream = new VirtualNetworkStream(network, isServer: true)) + using (var ssl = new SslStream(clientStream)) + { + // Start handshake. + Task task = ssl.AuthenticateAsClientAsync("foo.com", null, SslProtocols.Tls12, false); + // Do it again without waiting for previous one to finish. + await Assert.ThrowsAsync(() => ssl.AuthenticateAsClientAsync("foo.com", null, SslProtocols.Tls12, false)); + } + } + private static bool ValidateServerCertificate( object sender, X509Certificate retrievedServerPublicCertificate, -- 2.7.4