Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 08a369c

Browse files
committed
Prevent the ASP.NET certificate generation logic from running on the installers
1 parent 3f70aa8 commit 08a369c

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.DotNet.Configurer
5+
{
6+
public class NoOpAspNetCertificateSentinel : IAspNetCertificateSentinel
7+
{
8+
public bool Exists()
9+
{
10+
return true;
11+
}
12+
13+
public void CreateIfNotExists()
14+
{
15+
}
16+
17+
public void Dispose()
18+
{
19+
}
20+
}
21+
}

src/dotnet/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null
9292
new FirstTimeUseNoticeSentinel(cliFallbackFolderPathCalculator))
9393
{
9494
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel;
95+
IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(cliFallbackFolderPathCalculator);
9596
for (; lastArg < args.Length; lastArg++)
9697
{
9798
if (IsArg(args[lastArg], "d", "diagnostics"))
@@ -134,14 +135,15 @@ internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null
134135
var hasSuperUserAccess = false;
135136
if (IsDotnetBeingInvokedFromNativeInstaller(topLevelCommandParserResult))
136137
{
138+
aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel();
137139
firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel();
138140
hasSuperUserAccess = true;
139141
}
140142

141143
ConfigureDotNetForFirstTimeUse(
142144
nugetCacheSentinel,
143145
firstTimeUseNoticeSentinel,
144-
new AspNetCertificateSentinel(cliFallbackFolderPathCalculator),
146+
aspNetCertificateSentinel,
145147
cliFallbackFolderPathCalculator,
146148
hasSuperUserAccess);
147149

test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public void ItShowsTheAppropriateMessageToTheUser()
7676
.And.NotContain("Restore completed in");
7777
}
7878

79+
[Fact]
80+
public void ItShowsTheAspNetCertificateGenerationMessageToTheUser()
81+
{
82+
_firstDotnetVerbUseCommandResult.StdOut
83+
.Should()
84+
.ContainVisuallySameFragment(Configurer.LocalizableStrings.AspNetCertificateInstalled)
85+
.And.NotContain("Restore completed in");
86+
}
87+
7988
[Fact]
8089
public void ItCreatesASentinelFileUnderTheNuGetCacheFolder()
8190
{
@@ -93,7 +102,15 @@ public void ItCreatesAFirstUseSentinelFileUnderTheDotDotNetFolder()
93102
}
94103

95104
[Fact]
96-
public void ItDoesNotCreateAFirstUseSentinelFileUnderTheDotDotNetFolderWhenInternalReportInstallSuccessIsInvoked()
105+
public void ItCreatesAnAspNetCertificateSentinelFileUnderTheDotDotNetFolder()
106+
{
107+
_dotDotnetFolder
108+
.Should()
109+
.HaveFile($"{GetDotnetVersion()}.aspNetCertificateSentinel");
110+
}
111+
112+
[Fact]
113+
public void ItDoesNotCreateAFirstUseSentinelFileNorAnAspNetCertificateSentinelFileUnderTheDotDotNetFolderWhenInternalReportInstallSuccessIsInvoked()
97114
{
98115
var emptyHome = Path.Combine(_testDirectory, "empty_home");
99116
var profiled = Path.Combine(_testDirectory, "profile.d");
@@ -117,6 +134,7 @@ public void ItDoesNotCreateAFirstUseSentinelFileUnderTheDotDotNetFolderWhenInter
117134
var homeFolder = new DirectoryInfo(Path.Combine(emptyHome, ".dotnet"));
118135
string[] fileEntries = Directory.GetFiles(homeFolder.ToString());
119136
fileEntries.Should().OnlyContain(x => !x.Contains(".dotnetFirstUseSentinel"));
137+
fileEntries.Should().OnlyContain(x => !x.Contains(".aspNetCertificateSentinel"));
120138
}
121139

122140
[Fact]
@@ -147,6 +165,34 @@ public void ItShowsTheTelemetryNoticeWhenInvokingACommandAfterInternalReportInst
147165
.ContainVisuallySameFragment(Configurer.LocalizableStrings.FirstTimeWelcomeMessage);
148166
}
149167

168+
[Fact]
169+
public void ItShowsTheAspNetCertificateGenerationMessageWhenInvokingACommandAfterInternalReportInstallSuccessHasBeenInvoked()
170+
{
171+
var newHome = Path.Combine(_testDirectory, "aspnet_home");
172+
var newHomeFolder = new DirectoryInfo(Path.Combine(newHome, ".dotnet"));
173+
var profiled = Path.Combine(_testDirectory, "profile.d");
174+
var pathsd = Path.Combine(_testDirectory, "paths.d");
175+
176+
var command = new DotnetCommand()
177+
.WithWorkingDirectory(_testDirectory);
178+
command.Environment["HOME"] = newHome;
179+
command.Environment["USERPROFILE"] = newHome;
180+
command.Environment["APPDATA"] = newHome;
181+
command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = _nugetFallbackFolder.FullName;
182+
command.Environment["DOTNET_CLI_TEST_LINUX_PROFILED_PATH"] = profiled;
183+
command.Environment["DOTNET_CLI_TEST_OSX_PATHSD_PATH"] = pathsd;
184+
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
185+
command.Environment["SkipInvalidConfigurations"] = "true";
186+
187+
command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass();
188+
189+
var result = command.ExecuteWithCapturedOutput("new --debug:ephemeral-hive");
190+
191+
result.StdOut
192+
.Should()
193+
.ContainVisuallySameFragment(Configurer.LocalizableStrings.AspNetCertificateInstalled);
194+
}
195+
150196
[Fact]
151197
public void ItRestoresTheNuGetPackagesToTheNuGetCacheFolder()
152198
{

0 commit comments

Comments
 (0)