From 065abca3ecef313d11dd9ad67eb186eeb70ba260 Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Sat, 4 Apr 2020 10:43:26 -0400 Subject: [PATCH 1/3] Add a nonce option and Render testing Fix for #393, allows passing a nonce through the new `RenderOptions` API added in #451. --- src/MiniProfiler.Shared/Internal/Render.cs | 6 +- src/MiniProfiler.Shared/RenderOptions.cs | 6 ++ tests/MiniProfiler.Tests/RenderTests.cs | 108 +++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 tests/MiniProfiler.Tests/RenderTests.cs diff --git a/src/MiniProfiler.Shared/Internal/Render.cs b/src/MiniProfiler.Shared/Internal/Render.cs index 992e10d69..77caf44a3 100644 --- a/src/MiniProfiler.Shared/Internal/Render.cs +++ b/src/MiniProfiler.Shared/Internal/Render.cs @@ -28,7 +28,7 @@ public static string Includes( var sb = StringBuilderCache.Get(); var options = profiler.Options; - sb.Append(""; + Assert.Equal(expected, result); + } + + [Fact] + public void OptionsSet() + { + var profiler = GetBasicProfiler(); + var renderOptions = new RenderOptions() + { + ColorScheme = ColorScheme.Auto, + MaxTracesToShow = 12, + Nonce = "myNonce", + PopupToggleKeyboardShortcut = "Alt+Q", + Position = RenderPosition.Right, + ShowControls = true, + ShowTimeWithChildren = true, + ShowTrivial = true, + StartHidden = true, + TrivialDurationThresholdMilliseconds = 23 + }; + var result = Render.Includes(profiler, "/", true, renderOptions, new List() { profiler.Id }); + Output.WriteLine("Result: " + result); + + Assert.NotNull(result); + Assert.Contains("id=\"mini-profiler\"", result); + + var expected = $@""; + Assert.Equal(expected, result); + } + + [Theory] + [InlineData(null, @"data-scheme=""Light""")] + [InlineData(ColorScheme.Auto, @"data-scheme=""Auto""")] + [InlineData(ColorScheme.Dark, @"data-scheme=""Dark""")] + [InlineData(ColorScheme.Light, @"data-scheme=""Light""")] + public void ColorSchemes(ColorScheme? scheme, string expected) + { + var profiler = GetBasicProfiler(); + var renderOptions = new RenderOptions() { ColorScheme = scheme }; + + var result = Render.Includes(profiler, " / ", true, renderOptions); + Output.WriteLine("Result: " + result); + + Assert.NotNull(result); + Assert.Contains(expected, result); + } + + [Theory] + [InlineData(null, @"data-position=""Left""")] + [InlineData(RenderPosition.BottomLeft, @"data-position=""BottomLeft""")] + [InlineData(RenderPosition.BottomRight, @"data-position=""BottomRight""")] + [InlineData(RenderPosition.Left, @"data-position=""Left""")] + [InlineData(RenderPosition.Right, @"data-position=""Right""")] + public void Positions(RenderPosition? position, string expected) + { + var profiler = GetBasicProfiler(); + var renderOptions = new RenderOptions() { Position = position }; + + var result = Render.Includes(profiler, " / ", true, renderOptions); + Output.WriteLine("Result: " + result); + + Assert.NotNull(result); + Assert.Contains(expected, result); + } + + [Fact] + public void Nonce() + { + var profiler = GetBasicProfiler(); + var renderOptions = new RenderOptions(); + + // Default + var result = Render.Includes(profiler, "/", true, renderOptions); + Output.WriteLine("Result: " + result); + Assert.DoesNotContain("nonce", result); + + // With nonce + var nonce = Guid.NewGuid().ToString(); + renderOptions.Nonce = nonce; + result = Render.Includes(profiler, "/", true, renderOptions); + Assert.Contains($@"nonce=""{nonce}""", result); + } + } +} From 57bcecb2f0587aafeb7744d85385e60dcc5edf7a Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Sat, 4 Apr 2020 10:59:34 -0400 Subject: [PATCH 2/3] Add nonce to tag helper and docs ...and go ahead and update release notes in general. --- docs/AspDotNetCore.md | 2 +- docs/Releases.md | 12 ++++++++++++ .../Samples.AspNetCore3/Views/Shared/_Layout.cshtml | 2 +- .../MiniProfilerScriptTagHelper.cs | 7 +++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/AspDotNetCore.md b/docs/AspDotNetCore.md index a3afdad70..ee694b1e0 100644 --- a/docs/AspDotNetCore.md +++ b/docs/AspDotNetCore.md @@ -94,7 +94,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF ```html ``` -Note: `` has many options like `max-traces`, `position`, etc. [You can find them in code here](https://github.com/MiniProfiler/dotnet/blob/master/src/MiniProfiler.AspNetCore.Mvc/MiniProfilerScriptTagHelper.cs). +Note: `` has many options like `max-traces`, `position`, `color-scheme`, `nonce`, etc. [You can find them in code here](https://github.com/MiniProfiler/dotnet/blob/master/src/MiniProfiler.AspNetCore.Mvc/MiniProfilerScriptTagHelper.cs). Note #2: The above tag helper registration may go away in future versions of ASP.NET Core, they're working on smoother alternatives here. diff --git a/docs/Releases.md b/docs/Releases.md index 74f926e2c..099d5fc11 100644 --- a/docs/Releases.md +++ b/docs/Releases.md @@ -5,6 +5,18 @@ layout: "default" ### Release Notes This page tracks major changes included in any update starting with version 4.0.0.3 +#### Version 4.2.0 (In preview) +- Added `