Skip to content

Commit

Permalink
Added HTTPS redirect flag and test
Browse files Browse the repository at this point in the history
  • Loading branch information
UnicodingUnicorn committed Aug 26, 2019
1 parent 7e344ef commit 8229a25
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 240 deletions.
11 changes: 10 additions & 1 deletion src/UniversalDashboard.UITest/Integration/Https.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ Describe "Https" {

Stop-UDDashboard -Server $Dashboard
}

It "should redirect HTTP" {
$Dashboard = Start-UDDashboard -Port 10001 -Certificate $Cert

$Request = Invoke-WebRequest http://localhost:10001/dashboard
$Request.StatusCode | Should be 200

Stop-UDDashboard -Server $Dashboard
}
}

Get-UDDashboard | Stop-UDDashboard
Expand All @@ -57,4 +66,4 @@ Describe "Https" {
Remove-Item $CertPath -Force
}
}
}
}
7 changes: 5 additions & 2 deletions src/UniversalDashboard/Server/ServerStartup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
await context.Next(context.HttpContext);
}
});

app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(env.ContentRootPath),
Expand All @@ -120,6 +121,8 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
ContentTypeProvider = provider
});

app.UseHttpsRedirection();

var dashboardService = app.ApplicationServices.GetService(typeof(IDashboardService)) as IDashboardService;

if (dashboardService?.DashboardOptions?.PublishedFolders != null) {
Expand Down Expand Up @@ -147,4 +150,4 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
app.UseMvc();
}
}
}
}
Loading

0 comments on commit 8229a25

Please sign in to comment.