--no-https option for RazorPagesWeb-CSharp template (#362)
This commit is contained in:
parent
5ae68a012c
commit
aca30fe8a2
|
|
@ -29,7 +29,7 @@
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="${MicrosoftAspNetCoreAuthenticationCookiesPackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="${MicrosoftAspNetCoreAuthenticationCookiesPackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="${MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="${MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="${MicrosoftAspNetCoreCookiePolicyPackageVersion}" />
|
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="${MicrosoftAspNetCoreCookiePolicyPackageVersion}" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="${MicrosoftAspNetCoreHttpsPolicyPackageVersion}" />
|
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="${MicrosoftAspNetCoreHttpsPolicyPackageVersion}" Condition="'$(RequiresHttps)' == 'True'"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="${MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="${MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="${MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="${MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion}" Condition="'$(IndividualLocalAuth)' == 'True'" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="${MicrosoftAspNetCoreMvcPackageVersion}" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="${MicrosoftAspNetCoreMvcPackageVersion}" />
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,10 @@
|
||||||
"UseBrowserLink": {
|
"UseBrowserLink": {
|
||||||
"longName": "use-browserlink",
|
"longName": "use-browserlink",
|
||||||
"shortName": ""
|
"shortName": ""
|
||||||
|
},
|
||||||
|
"NoHttps": {
|
||||||
|
"longName": "no-https",
|
||||||
|
"shortName": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"usageExamples": [
|
"usageExamples": [
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@
|
||||||
"HttpsPort": {
|
"HttpsPort": {
|
||||||
"type": "parameter",
|
"type": "parameter",
|
||||||
"datatype": "integer",
|
"datatype": "integer",
|
||||||
"description": "Port number to use for the HTTPS endpoint in launchSettings.json."
|
"description": "Port number to use for the HTTPS endpoint in launchSettings.json. This option is only applicable when the parameter no-https is not used (no-https will be ignored if either IndividualAuth or OrganizationalAuth is used)."
|
||||||
},
|
},
|
||||||
"HttpsPortGenerated": {
|
"HttpsPortGenerated": {
|
||||||
"type": "generated",
|
"type": "generated",
|
||||||
|
|
@ -299,7 +299,13 @@
|
||||||
},
|
},
|
||||||
"RequiresHttps": {
|
"RequiresHttps": {
|
||||||
"type": "computed",
|
"type": "computed",
|
||||||
"value": "(OrganizationalAuth || IndividualAuth)"
|
"value": "(OrganizationalAuth || IndividualAuth || !NoHttps)"
|
||||||
|
},
|
||||||
|
"NoHttps": {
|
||||||
|
"type": "parameter",
|
||||||
|
"datatype": "bool",
|
||||||
|
"defaultValue": "false",
|
||||||
|
"description": "Whether to turn off HTTPS. This option only applies if IndividualAuth or OrganizationalAuth are not being used."
|
||||||
},
|
},
|
||||||
"UseLocalDB": {
|
"UseLocalDB": {
|
||||||
"type": "parameter",
|
"type": "parameter",
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@
|
||||||
"supportedAuthentications": [
|
"supportedAuthentications": [
|
||||||
{
|
{
|
||||||
"auth": "None",
|
"auth": "None",
|
||||||
"authenticationType": "NoAuth"
|
"authenticationType": "NoAuth",
|
||||||
|
"allowUnsecured": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"auth": "Individual",
|
"auth": "Individual",
|
||||||
|
|
@ -61,5 +62,6 @@
|
||||||
],
|
],
|
||||||
"excludeLaunchSettings": false,
|
"excludeLaunchSettings": false,
|
||||||
"azureReplyUrlPortName": "HttpsPort",
|
"azureReplyUrlPortName": "HttpsPort",
|
||||||
"minFullFrameworkVersion": "4.6.1"
|
"minFullFrameworkVersion": "4.6.1",
|
||||||
|
"disableHttpsSymbol": "NoHttps"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,11 @@
|
||||||
"Company.WebApplication1": {
|
"Company.WebApplication1": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
|
//#if(RequiresHttps)
|
||||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||||
|
//#else
|
||||||
|
"applicationUrl": "http://localhost:5000",
|
||||||
|
//#endif
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ using Microsoft.AspNetCore.Identity;
|
||||||
#endif
|
#endif
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
#if (RequiresHttps)
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
using Microsoft.AspNetCore.HttpsPolicy;
|
||||||
|
#endif
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
#if (OrganizationalAuth)
|
#if (OrganizationalAuth)
|
||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||||
|
|
@ -144,10 +146,15 @@ namespace Company.WebApplication1
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Error");
|
app.UseExceptionHandler("/Error");
|
||||||
|
#if (RequiresHttps)
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
app.UseCookiePolicy();
|
app.UseCookiePolicy();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Templates.Test
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void RunDotNetNew(string templateName, string targetFrameworkOverride, string auth = null, string language = null, bool useLocalDB = false)
|
protected void RunDotNetNew(string templateName, string targetFrameworkOverride, string auth = null, string language = null, bool useLocalDB = false, bool noHttps = false)
|
||||||
{
|
{
|
||||||
var args = $"new {templateName}";
|
var args = $"new {templateName}";
|
||||||
|
|
||||||
|
|
@ -72,6 +72,11 @@ namespace Templates.Test
|
||||||
args += $" -uld";
|
args += $" -uld";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (noHttps)
|
||||||
|
{
|
||||||
|
args += $" --no-https";
|
||||||
|
}
|
||||||
|
|
||||||
// Only run one instance of 'dotnet new' at once, as a workaround for
|
// Only run one instance of 'dotnet new' at once, as a workaround for
|
||||||
// https://github.com/aspnet/templating/issues/63
|
// https://github.com/aspnet/templating/issues/63
|
||||||
lock (DotNetNewLock)
|
lock (DotNetNewLock)
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,22 @@ namespace Templates.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)]
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
|
||||||
public void RazorPagesTemplate_NoAuth_Works_NetFramework()
|
public void RazorPagesTemplate_NoAuth_Works_NetFramework()
|
||||||
=> RazorPagesTemplate_NoAuthImpl("net461");
|
=> RazorPagesTemplate_NoAuthImpl("net461");
|
||||||
|
|
||||||
|
[ConditionalFact]
|
||||||
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
|
public void RazorPagesTemplate_NoAuth_NoHttps_Works_NetFramework()
|
||||||
|
=> RazorPagesTemplate_NoAuthImpl("net471", true);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RazorPagesTemplate_NoAuth_Works_NetCore()
|
public void RazorPagesTemplate_NoAuth_Works_NetCore()
|
||||||
=> RazorPagesTemplate_NoAuthImpl(null);
|
=> RazorPagesTemplate_NoAuthImpl(null);
|
||||||
|
|
||||||
private void RazorPagesTemplate_NoAuthImpl(string targetFrameworkOverride)
|
private void RazorPagesTemplate_NoAuthImpl(string targetFrameworkOverride, bool noHttps = false)
|
||||||
{
|
{
|
||||||
RunDotNetNew("razor", targetFrameworkOverride);
|
RunDotNetNew("razor", targetFrameworkOverride, noHttps: noHttps);
|
||||||
|
|
||||||
AssertFileExists("Pages/Shared/_LoginPartial.cshtml", false);
|
AssertFileExists("Pages/Shared/_LoginPartial.cshtml", false);
|
||||||
|
|
||||||
|
|
@ -36,6 +40,18 @@ namespace Templates.Test
|
||||||
Assert.DoesNotContain("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents);
|
Assert.DoesNotContain("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents);
|
||||||
Assert.DoesNotContain("Microsoft.Extensions.SecretManager.Tools", projectFileContents);
|
Assert.DoesNotContain("Microsoft.Extensions.SecretManager.Tools", projectFileContents);
|
||||||
|
|
||||||
|
if (targetFrameworkOverride != null)
|
||||||
|
{
|
||||||
|
if (noHttps)
|
||||||
|
{
|
||||||
|
Assert.DoesNotContain("Microsoft.AspNetCore.HttpsPolicy", projectFileContents);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.Contains("Microsoft.AspNetCore.HttpsPolicy", projectFileContents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var publish in new[] { false, true })
|
foreach (var publish in new[] { false, true })
|
||||||
{
|
{
|
||||||
using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish))
|
using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish))
|
||||||
|
|
@ -48,11 +64,15 @@ namespace Templates.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalFact(Skip = "https://github.com/aspnet/templating/issues/378")]
|
[ConditionalFact(Skip = "https://github.com/aspnet/templating/issues/378")]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)]
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
|
||||||
public void RazorPagesTemplate_IndividualAuth_Works_NetFramework()
|
public void RazorPagesTemplate_IndividualAuth_Works_NetFramework()
|
||||||
=> RazorPagesTemplate_IndividualAuthImpl("net461");
|
=> RazorPagesTemplate_IndividualAuthImpl("net461");
|
||||||
|
|
||||||
|
[ConditionalFact(Skip = "https://github.com/aspnet/templating/issues/378")]
|
||||||
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
|
public void RazorPagesTemplate_WithIndividualAuth_NoHttpsSetToTrue_UsesHttps_NetFramework()
|
||||||
|
=> RazorPagesTemplate_IndividualAuthImpl("net471", false, true);
|
||||||
|
|
||||||
[Fact(Skip = "https://github.com/aspnet/templating/issues/378")]
|
[Fact(Skip = "https://github.com/aspnet/templating/issues/378")]
|
||||||
public void RazorPagesTemplate_IndividualAuth_Works_NetCore()
|
public void RazorPagesTemplate_IndividualAuth_Works_NetCore()
|
||||||
=> RazorPagesTemplate_IndividualAuthImpl(null);
|
=> RazorPagesTemplate_IndividualAuthImpl(null);
|
||||||
|
|
@ -61,7 +81,7 @@ namespace Templates.Test
|
||||||
public void RazorPagesTemplate_IndividualAuth_UsingLocalDB_Works_NetCore()
|
public void RazorPagesTemplate_IndividualAuth_UsingLocalDB_Works_NetCore()
|
||||||
=> RazorPagesTemplate_IndividualAuthImpl(null, true);
|
=> RazorPagesTemplate_IndividualAuthImpl(null, true);
|
||||||
|
|
||||||
private void RazorPagesTemplate_IndividualAuthImpl(string targetFrameworkOverride, bool useLocalDB = false)
|
private void RazorPagesTemplate_IndividualAuthImpl(string targetFrameworkOverride, bool useLocalDB = false, bool noHttps = false)
|
||||||
{
|
{
|
||||||
RunDotNetNew("razor", targetFrameworkOverride, auth: "Individual", useLocalDB: useLocalDB);
|
RunDotNetNew("razor", targetFrameworkOverride, auth: "Individual", useLocalDB: useLocalDB);
|
||||||
|
|
||||||
|
|
@ -74,6 +94,11 @@ namespace Templates.Test
|
||||||
}
|
}
|
||||||
Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents);
|
Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents);
|
||||||
|
|
||||||
|
if (targetFrameworkOverride != null)
|
||||||
|
{
|
||||||
|
Assert.Contains("Microsoft.AspNetCore.HttpsPolicy", projectFileContents);
|
||||||
|
}
|
||||||
|
|
||||||
RunDotNetEfCreateMigration("razorpages");
|
RunDotNetEfCreateMigration("razorpages");
|
||||||
|
|
||||||
AssertEmptyMigration("razorpages");
|
AssertEmptyMigration("razorpages");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue