diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index fd0179d4c..412fb9ab9 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -59,7 +59,9 @@ 2.0.1-servicing-25908-02 $(MicrosoftNETCoreAppPackageVersion) $(MicrosoftNETCoreAppPackageVersion) - + + 2.1.0-preview1-27617 2.0.3 aspnetcore-store dev-26623 diff --git a/build/NugetConfigFile.targets b/build/NugetConfigFile.targets index ef6be9c14..06eb5cf2c 100644 --- a/build/NugetConfigFile.targets +++ b/build/NugetConfigFile.targets @@ -21,6 +21,8 @@ + + diff --git a/src/Microsoft.DotNet.Configurer/AspNetCertificateSentinel.cs b/src/Microsoft.DotNet.Configurer/AspNetCertificateSentinel.cs new file mode 100644 index 000000000..c8dc622c0 --- /dev/null +++ b/src/Microsoft.DotNet.Configurer/AspNetCertificateSentinel.cs @@ -0,0 +1,61 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.Extensions.EnvironmentAbstractions; + +namespace Microsoft.DotNet.Configurer +{ + public class AspNetCertificateSentinel : IAspNetCertificateSentinel + { + public static readonly string SENTINEL = $"{Product.Version}.aspNetCertificateSentinel"; + + private readonly IFile _file; + private readonly IDirectory _directory; + + private string _dotnetUserProfileFolderPath; + + private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL); + + public AspNetCertificateSentinel(CliFolderPathCalculator cliFallbackFolderPathCalculator) : + this( + CliFolderPathCalculator.DotnetUserProfileFolderPath, + FileSystemWrapper.Default.File, + FileSystemWrapper.Default.Directory) + { + } + + internal AspNetCertificateSentinel(string dotnetUserProfileFolderPath, IFile file, IDirectory directory) + { + _file = file; + _directory = directory; + _dotnetUserProfileFolderPath = dotnetUserProfileFolderPath; + } + + public bool Exists() + { + return _file.Exists(SentinelPath); + } + + public void CreateIfNotExists() + { + if (!Exists()) + { + if (!_directory.Exists(_dotnetUserProfileFolderPath)) + { + _directory.CreateDirectory(_dotnetUserProfileFolderPath); + } + + _file.CreateEmptyFile(SentinelPath); + } + } + + public void Dispose() + { + } + } +} diff --git a/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs b/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs index 29e17f7de..584ae0923 100644 --- a/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs +++ b/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs @@ -16,6 +16,8 @@ namespace Microsoft.DotNet.Configurer private INuGetCachePrimer _nugetCachePrimer; private INuGetCacheSentinel _nugetCacheSentinel; private IFirstTimeUseNoticeSentinel _firstTimeUseNoticeSentinel; + private IAspNetCertificateSentinel _aspNetCertificateSentinel; + private IAspNetCoreCertificateGenerator _aspNetCoreCertificateGenerator; private string _cliFallbackFolderPath; private readonly IEnvironmentPath _pathAdder; @@ -23,6 +25,8 @@ namespace Microsoft.DotNet.Configurer INuGetCachePrimer nugetCachePrimer, INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, + IAspNetCertificateSentinel aspNetCertificateSentinel, + IAspNetCoreCertificateGenerator aspNetCoreCertificateGenerator, IEnvironmentProvider environmentProvider, IReporter reporter, string cliFallbackFolderPath, @@ -31,6 +35,8 @@ namespace Microsoft.DotNet.Configurer _nugetCachePrimer = nugetCachePrimer; _nugetCacheSentinel = nugetCacheSentinel; _firstTimeUseNoticeSentinel = firstTimeUseNoticeSentinel; + _aspNetCertificateSentinel = aspNetCertificateSentinel; + _aspNetCoreCertificateGenerator = aspNetCoreCertificateGenerator; _environmentProvider = environmentProvider; _reporter = reporter; _cliFallbackFolderPath = cliFallbackFolderPath; @@ -59,6 +65,31 @@ namespace Microsoft.DotNet.Configurer _nugetCachePrimer.PrimeCache(); } } + + if(ShouldGenerateAspNetCertificate()) + { + GenerateAspNetCertificate(); + } + } + + private void GenerateAspNetCertificate() + { + _aspNetCoreCertificateGenerator.GenerateAspNetCoreDevelopmentCertificate(); + + _reporter.WriteLine(); + _reporter.WriteLine(LocalizableStrings.AspNetCertificateInstalled); + + _aspNetCertificateSentinel.CreateIfNotExists(); + } + + private bool ShouldGenerateAspNetCertificate() + { + var generateAspNetCertificate = + _environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true); + + return ShouldRunFirstRunExperience() && + generateAspNetCertificate && + !_aspNetCertificateSentinel.Exists(); } private void AddPackageExecutablePath() diff --git a/src/Microsoft.DotNet.Configurer/IAspNetCertificateSentinel.cs b/src/Microsoft.DotNet.Configurer/IAspNetCertificateSentinel.cs new file mode 100644 index 000000000..5a422a1f7 --- /dev/null +++ b/src/Microsoft.DotNet.Configurer/IAspNetCertificateSentinel.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.DotNet.Configurer +{ + public interface IAspNetCertificateSentinel + { + bool Exists(); + + void CreateIfNotExists(); + } +} diff --git a/src/Microsoft.DotNet.Configurer/IAspNetCoreCertificateGenerator.cs b/src/Microsoft.DotNet.Configurer/IAspNetCoreCertificateGenerator.cs new file mode 100644 index 000000000..e19fc15d6 --- /dev/null +++ b/src/Microsoft.DotNet.Configurer/IAspNetCoreCertificateGenerator.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.DotNet.Configurer +{ + public interface IAspNetCoreCertificateGenerator + { + void GenerateAspNetCoreDevelopmentCertificate(); + } +} diff --git a/src/Microsoft.DotNet.Configurer/LocalizableStrings.resx b/src/Microsoft.DotNet.Configurer/LocalizableStrings.resx index 173004d0d..dd7715bb8 100644 --- a/src/Microsoft.DotNet.Configurer/LocalizableStrings.resx +++ b/src/Microsoft.DotNet.Configurer/LocalizableStrings.resx @@ -137,7 +137,7 @@ A command is running to populate your local package cache to improve restore spe Failed to prime the NuGet cache. {0} failed with: {1} - + Permission denied to modify the '{0}' folder. Here are some options to fix this error: @@ -147,4 +147,9 @@ Here are some options to fix this error: 3. Copy the .NET Core SDK to a non-protected location and use it from there. - + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf index 2721a3a76..7a19f721a 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf @@ -58,6 +58,15 @@ Tuto chybu můžete opravit pomocí některé z těchto možností: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf index d4998123b..c505c26b8 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf @@ -58,6 +58,15 @@ Im Folgenden finden Sie einige Optionen, um diesen Fehler zu beheben: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf index dab80ee44..169766c1b 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf @@ -57,6 +57,15 @@ Estas son algunas opciones para corregir este error: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf index 9d5658555..039a5f7f9 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.fr.xlf @@ -58,6 +58,15 @@ Voici quelques options pour corriger cette erreur : + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf index d8d3faa40..6a36fe74f 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.it.xlf @@ -58,6 +58,15 @@ Ecco alcune opzioni per correggere questo errore: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf index 26af93ab4..ee4655409 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ja.xlf @@ -58,6 +58,15 @@ Here are some options to fix this error: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf index 8fdb602fe..dcd90afd7 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ko.xlf @@ -58,6 +58,15 @@ Here are some options to fix this error: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf index 38921e940..6824f402e 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pl.xlf @@ -58,6 +58,15 @@ Oto kilka opcji naprawiania tego błędu: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf index 9d13efe8f..f7d8aeb70 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.pt-BR.xlf @@ -58,6 +58,15 @@ Aqui estão algumas opções para corrigir este erro: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf index 1e099ec63..b3b0aad59 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.ru.xlf @@ -58,6 +58,15 @@ Here are some options to fix this error: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf index 52204d503..20799b5d7 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.tr.xlf @@ -58,6 +58,15 @@ Bu hatayı düzeltmek için bazı seçenekler: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf index 2ba1a1840..72254b873 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hans.xlf @@ -58,6 +58,15 @@ Here are some options to fix this error: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf index d91e56863..c99df17e6 100644 --- a/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.zh-Hant.xlf @@ -58,6 +58,15 @@ Here are some options to fix this error: + + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + ASP.NET Core +------------ +Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805 + + \ No newline at end of file diff --git a/src/dotnet/AspNetCoreCertificateGenerator.cs b/src/dotnet/AspNetCoreCertificateGenerator.cs new file mode 100644 index 000000000..d0fcf0a9a --- /dev/null +++ b/src/dotnet/AspNetCoreCertificateGenerator.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.AspNetCore.DeveloperCertificates.XPlat; +using Microsoft.DotNet.Configurer; + +namespace Microsoft.DotNet.Cli +{ + public class AspNetCoreCertificateGenerator : IAspNetCoreCertificateGenerator + { + public void GenerateAspNetCoreDevelopmentCertificate() + { + CertificateGenerator.GenerateAspNetHttpsCertificate(); + } + } +} diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 37a4ebd7c..9dfceaf78 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -141,6 +141,7 @@ namespace Microsoft.DotNet.Cli ConfigureDotNetForFirstTimeUse( nugetCacheSentinel, firstTimeUseNoticeSentinel, + new AspNetCertificateSentinel(cliFallbackFolderPathCalculator), cliFallbackFolderPathCalculator, hasSuperUserAccess); @@ -204,6 +205,7 @@ namespace Microsoft.DotNet.Cli private static void ConfigureDotNetForFirstTimeUse( INuGetCacheSentinel nugetCacheSentinel, IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, + IAspNetCertificateSentinel aspNetCertificateSentinel, CliFolderPathCalculator cliFolderPathCalculator, bool hasSuperUserAccess) { @@ -219,10 +221,13 @@ namespace Microsoft.DotNet.Cli nugetPackagesArchiver, nugetCacheSentinel, cliFolderPathCalculator); + var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator(); var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( nugetCachePrimer, nugetCacheSentinel, firstTimeUseNoticeSentinel, + aspNetCertificateSentinel, + aspnetCertificateGenerator, environmentProvider, Reporter.Output, cliFolderPathCalculator.CliFallbackFolderPath, diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index a8803a5bf..1e0e86aa3 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -55,6 +55,7 @@ + diff --git a/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs b/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs index f3c549582..27b3247f4 100644 --- a/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs +++ b/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs @@ -18,6 +18,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests private Mock _nugetCachePrimerMock; private Mock _nugetCacheSentinelMock; private Mock _firstTimeUseNoticeSentinelMock; + private Mock _aspNetCertificateSentinelMock; + private Mock _aspNetCoreCertificateGeneratorMock; private Mock _environmentProviderMock; private Mock _reporterMock; private Mock _pathAdder; @@ -27,6 +29,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock = new Mock(); _nugetCacheSentinelMock = new Mock(); _firstTimeUseNoticeSentinelMock = new Mock(); + _aspNetCertificateSentinelMock = new Mock(); + _aspNetCoreCertificateGeneratorMock = new Mock(); _environmentProviderMock = new Mock(); _reporterMock = new Mock(); _pathAdder = new Mock(); @@ -48,6 +52,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -71,6 +77,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -94,6 +102,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -114,6 +124,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -134,6 +146,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -153,6 +167,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -172,6 +188,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -194,6 +212,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -213,6 +233,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -233,6 +255,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -256,6 +280,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -281,6 +307,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, new FakeCreateWillExistNuGetCacheSentinel(false, true), new FakeCreateWillExistFirstTimeUseNoticeSentinel(false), + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -300,6 +328,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -327,6 +357,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, _environmentProviderMock.Object, _reporterMock.Object, CliFallbackFolderPath, @@ -337,6 +369,104 @@ namespace Microsoft.DotNet.Configurer.UnitTests _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never); } + [Fact] + public void It_does_not_generate_the_aspnet_https_development_certificate_if_the_sentinel_exists() + { + _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(true); + + var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( + _nugetCachePrimerMock.Object, + _nugetCacheSentinelMock.Object, + _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, + _environmentProviderMock.Object, + _reporterMock.Object, + CliFallbackFolderPath, + _pathAdder.Object); + + dotnetFirstTimeUseConfigurer.Configure(); + + _reporterMock.Verify(r => r.WriteLine(It.Is(str => str == LocalizableStrings.AspNetCertificateInstalled)), Times.Never); + _aspNetCoreCertificateGeneratorMock.Verify(s => s.GenerateAspNetCoreDevelopmentCertificate(), Times.Never); + } + + [Fact] + public void It_does_not_generate_the_aspnet_https_development_certificate_when_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environment_variable() + { + _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false); + _environmentProviderMock + .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false)) + .Returns(true); + + var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( + _nugetCachePrimerMock.Object, + _nugetCacheSentinelMock.Object, + _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, + _environmentProviderMock.Object, + _reporterMock.Object, + CliFallbackFolderPath, + _pathAdder.Object); + + dotnetFirstTimeUseConfigurer.Configure(); + + _reporterMock.Verify(r => r.WriteLine(It.Is(str => str == LocalizableStrings.AspNetCertificateInstalled)), Times.Never); + _aspNetCoreCertificateGeneratorMock.Verify(s => s.GenerateAspNetCoreDevelopmentCertificate(), Times.Never); + } + + [Fact] + public void It_does_not_generate_the_aspnet_https_development_certificate_when_the_user_has_set_the_DOTNET_GENERATE_ASPNET_CERTIFICATE_environment_variable() + { + _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false); + _environmentProviderMock + .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true)) + .Returns(false); + + var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( + _nugetCachePrimerMock.Object, + _nugetCacheSentinelMock.Object, + _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, + _environmentProviderMock.Object, + _reporterMock.Object, + CliFallbackFolderPath, + _pathAdder.Object); + + dotnetFirstTimeUseConfigurer.Configure(); + + _reporterMock.Verify(r => r.WriteLine(It.Is(str => str == LocalizableStrings.AspNetCertificateInstalled)), Times.Never); + _aspNetCoreCertificateGeneratorMock.Verify(s => s.GenerateAspNetCoreDevelopmentCertificate(), Times.Never); + } + + [Fact] + public void It_generates_the_aspnet_https_development_certificate_if_the_sentinel_does_not_exist() + { + _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false); + _environmentProviderMock.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true)) + .Returns(true); + + var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( + _nugetCachePrimerMock.Object, + _nugetCacheSentinelMock.Object, + _firstTimeUseNoticeSentinelMock.Object, + _aspNetCertificateSentinelMock.Object, + _aspNetCoreCertificateGeneratorMock.Object, + _environmentProviderMock.Object, + _reporterMock.Object, + CliFallbackFolderPath, + _pathAdder.Object); + + dotnetFirstTimeUseConfigurer.Configure(); + + _reporterMock.Verify(r => r.WriteLine(It.Is(str => str == LocalizableStrings.FirstTimeWelcomeMessage))); + _reporterMock.Verify(r => r.WriteLine(It.Is(str => str == LocalizableStrings.NugetCachePrimeMessage))); + _reporterMock.Verify(r => r.WriteLine(It.Is(str => str == LocalizableStrings.AspNetCertificateInstalled))); + _aspNetCoreCertificateGeneratorMock.Verify(s => s.GenerateAspNetCoreDevelopmentCertificate(), Times.Once); + } + private class FakeCreateWillExistFirstTimeUseNoticeSentinel : IFirstTimeUseNoticeSentinel { private bool _exists;