From 56cfca1b9b4a5e8cb4b866c561998a9089a1657a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marie=20P=C3=ADchov=C3=A1?= <11718369+ManickaP@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:00:49 +0100 Subject: [PATCH] SslStream test keylogfile creation (#94859) * Added the same test as we have for Quic for SSLKEYLOGFILE creation * Added the same test as we have for Quic for SSLKEYLOGFILE creation --- .../SslStreamRemoteExecutorTests.cs | 64 +++++++++++++++++++ .../System.Net.Security.Tests.csproj | 1 + 2 files changed, 65 insertions(+) create mode 100644 src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs new file mode 100644 index 0000000000000..d162a54bf9217 --- /dev/null +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs @@ -0,0 +1,64 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using Microsoft.DotNet.RemoteExecutor; +using Microsoft.DotNet.XUnitExtensions; +using Xunit; +using Xunit.Abstractions; + +namespace System.Net.Security.Tests +{ + using Configuration = System.Net.Test.Common.Configuration; + + public class SslStreamRemoteExecutorTests + { + public SslStreamRemoteExecutorTests() + { } + + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/94843", ~TestPlatforms.Linux)] + public void SslKeyLogFile_IsCreatedAndFilled() + { + if (PlatformDetection.IsReleaseLibrary(typeof(SslStream).Assembly)) + { + throw new SkipTestException("Retrieving SSL secrets is not supported in Release mode."); + } + + var psi = new ProcessStartInfo(); + var tempFile = Path.GetTempFileName(); + psi.Environment.Add("SSLKEYLOGFILE", tempFile); + + RemoteExecutor.Invoke(async () => + { + (Stream clientStream, Stream serverStream) = TestHelper.GetConnectedStreams(); + using (clientStream) + using (serverStream) + using (var client = new SslStream(clientStream)) + using (var server = new SslStream(serverStream)) + using (X509Certificate2 certificate = Configuration.Certificates.GetServerCertificate()) + { + SslClientAuthenticationOptions clientOptions = new SslClientAuthenticationOptions(); + clientOptions.RemoteCertificateValidationCallback = delegate { return true; }; + + SslServerAuthenticationOptions serverOptions = new SslServerAuthenticationOptions(); + serverOptions.ServerCertificate = certificate; + + await TestConfiguration.WhenAllOrAnyFailedWithTimeout( + client.AuthenticateAsClientAsync(clientOptions), + server.AuthenticateAsServerAsync(serverOptions)); + + await TestHelper.PingPong(client, server); + } + }, new RemoteInvokeOptions { StartInfo = psi }).Dispose(); + + Assert.True(File.Exists(tempFile)); + Assert.True(File.ReadAllText(tempFile).Length > 0); + } + } +} \ No newline at end of file diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj index ce3d32e158cdc..2b26a1df7f117 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj @@ -116,6 +116,7 @@ +