Skip to content

Commit 8e66833

Browse files
authored
Merge pull request #20523 from dotnet-maestro-bot/merge/release/5.0-preview3-to-master
[automated] Merge branch 'release/5.0-preview3' => 'master'
2 parents f4be244 + 66ae2ba commit 8e66833

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/ProjectTemplates/test/Helpers/AspNetProcess.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics;
7+
using System.IO;
78
using System.Linq;
89
using System.Net;
910
using System.Net.Http;
@@ -30,6 +31,9 @@ public class AspNetProcess : IDisposable
3031
private readonly HttpClient _httpClient;
3132
private readonly ITestOutputHelper _output;
3233

34+
private string _certificatePath;
35+
private string _certificatePassword = Guid.NewGuid().ToString();
36+
3337
internal readonly Uri ListeningUri;
3438
internal ProcessEx Process { get; }
3539

@@ -48,12 +52,14 @@ public AspNetProcess(
4852
AllowAutoRedirect = true,
4953
UseCookies = true,
5054
CookieContainer = new CookieContainer(),
51-
ServerCertificateCustomValidationCallback = (m, c, ch, p) => true,
55+
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator,
5256
})
5357
{
5458
Timeout = TimeSpan.FromMinutes(2)
5559
};
5660

61+
_certificatePath = Path.Combine(workingDirectory, $"{Guid.NewGuid()}.pfx");
62+
5763
EnsureDevelopmentCertificates();
5864

5965
output.WriteLine("Running ASP.NET application...");
@@ -62,7 +68,13 @@ public AspNetProcess(
6268

6369
logger?.LogInformation($"AspNetProcess - process: {DotNetMuxer.MuxerPathOrDefault()} arguments: {arguments}");
6470

65-
Process = ProcessEx.Run(output, workingDirectory, DotNetMuxer.MuxerPathOrDefault(), arguments, envVars: environmentVariables);
71+
var finalEnvironmentVariables = new Dictionary<string, string>(environmentVariables)
72+
{
73+
["ASPNETCORE_KESTREL__CERTIFICATES__DEFAULT__PATH"] = _certificatePath,
74+
["ASPNETCORE_KESTREL__CERTIFICATES__DEFAULT__PASSWORD"] = _certificatePassword
75+
};
76+
77+
Process = ProcessEx.Run(output, workingDirectory, DotNetMuxer.MuxerPathOrDefault(), arguments, envVars: finalEnvironmentVariables);
6678

6779
logger?.LogInformation("AspNetProcess - process started");
6880

@@ -74,10 +86,12 @@ public AspNetProcess(
7486
}
7587
}
7688

77-
internal static void EnsureDevelopmentCertificates()
89+
internal void EnsureDevelopmentCertificates()
7890
{
7991
var now = DateTimeOffset.Now;
80-
new CertificateManager().EnsureAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1));
92+
var manager = new CertificateManager();
93+
var certificate = manager.CreateAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1), "CN=localhost");
94+
manager.ExportCertificate(certificate, path: _certificatePath, includePrivateKey: true, _certificatePassword);
8195
}
8296

8397
public void VisitInBrowser(IWebDriver driver)

0 commit comments

Comments
 (0)