From 761957471cad0152f066212caa70080d00b00cde Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 5 Jul 2024 13:55:53 +0000 Subject: [PATCH 1/5] Set version to '1.30-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 8396f0d52..6bad75a5d 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.29-preview", + "version": "1.30-preview", "assemblyVersion": { "precision": "revision" }, From 67b599d241113b58da8de9b37d24345cb95d37ff Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Sun, 7 Jul 2024 15:27:45 +0200 Subject: [PATCH 2/5] fix: Replace Tokens in docfx.json for release information (#1496) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06d6fb08b..31b34874a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -222,7 +222,7 @@ jobs: - name: 🍥 Replace tokens in files uses: cschleiden/replace-tokens@v1 with: - files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props"]' + files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props", "docs/site/docfx.json"]' env: RELEASE_VERSION: ${{ env.NBGV_SimpleVersion }}${{ env.NBGV_PrereleaseVersion }} RELEASE_NOTES: ${{ steps.changelog_reader.outputs.changes }} From 43c8855df51932422f8bbfaa2cdd42c674762b51 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 8 Jul 2024 08:51:52 +0200 Subject: [PATCH 3/5] fix: Add net7.0 for devcontainers --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d8902bdd6..90c45b483 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,7 @@ "features": { "ghcr.io/devcontainers/features/dotnet:2": { "version": "latest", - "additionalVersions": "6.0,5.0,3.1" + "additionalVersions": "7.0,6.0,5.0,3.1" } }, From ecc480a20c6cca706dd8838e51f6ea30da310f92 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 19 Jul 2024 16:49:28 +0200 Subject: [PATCH 4/5] fix: Bunit browser file exc (#1504) * chore: Align package versions * fix: BunitBrowserFile throws when filesize too big * chore: Fix CVE in System.Text.Json for production code * docs: Added changelog entry --- CHANGELOG.md | 4 ++++ Directory.Build.props | 2 +- .../bunit.benchmarks.assets.csproj | 2 +- docs/samples/tests/Directory.Build.props | 2 +- .../tests/razor/bunit.docs.razor.samples.csproj | 2 +- .../tests/xunit/bunit.docs.xunit.samples.csproj | 2 +- .../template/Company.BlazorTests1.csproj | 2 +- .../Extensions/InputFile/BUnitBrowserFile.cs | 7 ++++++- .../Extensions/InputFile/InputFileExtensions.cs | 8 +++++++- src/bunit.web/bunit.web.csproj | 15 +++++++++++++++ tests/Directory.Build.props | 8 ++++++++ tests/bunit.core.tests/bunit.core.tests.csproj | 2 +- .../bunit.generators.tests.csproj | 5 ++--- .../PersistentComponentStateSample.razor.cs | 2 +- tests/bunit.testassets/_Imports.razor | 1 - tests/bunit.testassets/bunit.testassets.csproj | 6 +++--- .../bunit.web.query.tests.csproj | 2 +- .../Extensions/InputFile/InputFileTests.cs | 16 +++++++++++++++- tests/bunit.web.tests/bunit.web.tests.csproj | 2 +- 19 files changed, 70 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99cfcca00..403e73988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Fixed + +- `UploadFile` doesn't throw an exception when the file size exceeds the maximum allowed size. Reported by [@MorneZaayman](https://github.com/MorneZaayman) in [#1503](https://github.com/bUnit-dev/bUnit/issues/1503). Fixed by [@linkdotnet](https://github.com/linkdotnet). + ## [1.29.5] - 2024-07-05 ### Fixed diff --git a/Directory.Build.props b/Directory.Build.props index 765ddd563..d9a96bfbf 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -52,7 +52,7 @@ - + - + diff --git a/docs/samples/tests/Directory.Build.props b/docs/samples/tests/Directory.Build.props index 8422a0457..e5b3bbe6b 100644 --- a/docs/samples/tests/Directory.Build.props +++ b/docs/samples/tests/Directory.Build.props @@ -13,7 +13,7 @@ - + diff --git a/docs/samples/tests/razor/bunit.docs.razor.samples.csproj b/docs/samples/tests/razor/bunit.docs.razor.samples.csproj index 601c8a4c3..9dff4b342 100644 --- a/docs/samples/tests/razor/bunit.docs.razor.samples.csproj +++ b/docs/samples/tests/razor/bunit.docs.razor.samples.csproj @@ -9,7 +9,7 @@ - + all diff --git a/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj b/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj index be96270c2..96ed4edf4 100644 --- a/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj +++ b/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj @@ -11,7 +11,7 @@ - + all diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index 36d78fdd7..4a443a344 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -25,7 +25,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/bunit.web/Extensions/InputFile/BUnitBrowserFile.cs b/src/bunit.web/Extensions/InputFile/BUnitBrowserFile.cs index 76e5dc8ae..a50a89176 100644 --- a/src/bunit.web/Extensions/InputFile/BUnitBrowserFile.cs +++ b/src/bunit.web/Extensions/InputFile/BUnitBrowserFile.cs @@ -27,7 +27,12 @@ public BUnitBrowserFile( public Stream OpenReadStream(long maxAllowedSize = 512000, CancellationToken cancellationToken = default) { + if (Size > maxAllowedSize) + { + throw new IOException($"Supplied file with size {Size} bytes exceeds the maximum of {maxAllowedSize} bytes."); + } + return new MemoryStream(Content); } } -#endif \ No newline at end of file +#endif diff --git a/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs b/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs index 3eb0de24c..39c6d7395 100644 --- a/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs +++ b/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs @@ -1,4 +1,5 @@ #if NET5_0_OR_GREATER +using System.Runtime.ExceptionServices; using Microsoft.AspNetCore.Components.Forms; namespace Bunit; @@ -36,6 +37,11 @@ public static void UploadFiles( { uploadTask.GetAwaiter().GetResult(); } + + if (uploadTask.Exception is { InnerException: not null } e) + { + ExceptionDispatchInfo.Capture(e.InnerException).Throw(); + } } } -#endif \ No newline at end of file +#endif diff --git a/src/bunit.web/bunit.web.csproj b/src/bunit.web/bunit.web.csproj index 9b453fc70..86401722d 100644 --- a/src/bunit.web/bunit.web.csproj +++ b/src/bunit.web/bunit.web.csproj @@ -31,6 +31,9 @@ + + + @@ -41,6 +44,9 @@ + + + @@ -52,6 +58,9 @@ + + + @@ -63,6 +72,9 @@ + + + @@ -74,6 +86,9 @@ + + + diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index e30b4b0b1..5c1e49b76 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -13,6 +13,14 @@ true true + + + + NU1903 + diff --git a/tests/bunit.core.tests/bunit.core.tests.csproj b/tests/bunit.core.tests/bunit.core.tests.csproj index 3fd9831b1..62e64bfdd 100644 --- a/tests/bunit.core.tests/bunit.core.tests.csproj +++ b/tests/bunit.core.tests/bunit.core.tests.csproj @@ -13,7 +13,7 @@ - + all diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index e0cdb9754..236bac0a1 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -14,7 +14,6 @@ - @@ -25,8 +24,8 @@ - - + + all runtime; build; native; contentfiles; analyzers diff --git a/tests/bunit.testassets/SampleComponents/PersistentComponentStateSample.razor.cs b/tests/bunit.testassets/SampleComponents/PersistentComponentStateSample.razor.cs index ae422117c..6f4532ff7 100644 --- a/tests/bunit.testassets/SampleComponents/PersistentComponentStateSample.razor.cs +++ b/tests/bunit.testassets/SampleComponents/PersistentComponentStateSample.razor.cs @@ -32,7 +32,7 @@ private WeatherForecast[] CreateForecasts() { return new WeatherForecast[] { - new WeatherForecast{ Temperature = 42 }, + new WeatherForecast{ Temperature = 42 }, }; } #endif diff --git a/tests/bunit.testassets/_Imports.razor b/tests/bunit.testassets/_Imports.razor index 53e2952cd..80f583e3a 100644 --- a/tests/bunit.testassets/_Imports.razor +++ b/tests/bunit.testassets/_Imports.razor @@ -1,4 +1,3 @@ -@using System.Net.Http @using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Web diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index 50e8110cc..d9746eafc 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -16,16 +16,16 @@ - + - + - + diff --git a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj index de2310ea6..f37f4ff1d 100644 --- a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj +++ b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj @@ -14,7 +14,7 @@ - + all diff --git a/tests/bunit.web.tests/Extensions/InputFile/InputFileTests.cs b/tests/bunit.web.tests/Extensions/InputFile/InputFileTests.cs index 465813e21..e0e63ad83 100644 --- a/tests/bunit.web.tests/Extensions/InputFile/InputFileTests.cs +++ b/tests/bunit.web.tests/Extensions/InputFile/InputFileTests.cs @@ -102,9 +102,23 @@ public void Test008() act.ShouldNotThrow(); } + + [Fact(DisplayName = "Uploading file exceeding the maximum file size will throw an exception")] + public void Test009() + { + var cut = RenderComponent(ps => ps.Add(p => p.MaxFileSize, 512)); + var file = InputFileContent.CreateFromText(new string('a', 513)); + + Action act = () => cut.FindComponent().UploadFiles(file); + + act.ShouldThrow(); + } private sealed class InputFileComponent : ComponentBase { + [Parameter] + public long MaxFileSize { get; set; } = 512000; + public string? Filename { get; private set; } public string? Content { get; private set; } public DateTimeOffset? LastChanged { get; private set; } @@ -127,7 +141,7 @@ private void OnChange(InputFileChangeEventArgs args) Filename = file.Name; LastChanged = file.LastModified; Size = file.Size; - using var stream = new StreamReader(file.OpenReadStream()); + using var stream = new StreamReader(file.OpenReadStream(MaxFileSize)); Content = stream.ReadToEnd(); } } diff --git a/tests/bunit.web.tests/bunit.web.tests.csproj b/tests/bunit.web.tests/bunit.web.tests.csproj index 386eb90b2..09885c8f4 100644 --- a/tests/bunit.web.tests/bunit.web.tests.csproj +++ b/tests/bunit.web.tests/bunit.web.tests.csproj @@ -13,7 +13,7 @@ - + all From 7ce3d3486ef7415e3c4fba61a2c7266a24b0a0f0 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 19 Jul 2024 20:57:28 +0000 Subject: [PATCH 5/5] Set version to '1.30' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 6bad75a5d..562f466f7 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.30-preview", + "version": "1.30", "assemblyVersion": { "precision": "revision" },