// 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
}
}
+ [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<InvalidOperationException>(() => ssl.AuthenticateAsClientAsync("foo.com", null, SslProtocols.Tls12, false));
+ }
+ }
+
private static bool ValidateServerCertificate(
object sender,
X509Certificate retrievedServerPublicCertificate,