bUnit-dev / bUnit

bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
https://bunit.dev
MIT License
1.16k stars 109 forks source link

BUnitBrowserFile ignores MaximumAllowedFileSize #1503

Closed MorneZaayman closed 4 months ago

MorneZaayman commented 4 months ago

When testing the MaximumAllowedFileSize for a component that includes an InputFile component, I picked up that the BUnit.BUnitBrowserFile implementation ignores the MaximumAllowedFileSize argument, and allows any file size to be uploaded.

To replicate, you need to render a component containing an InputFile component (or the InputFile component directly), and set the MaximumAllowedFileSize to something small, say 512 (bytes). Then generate a random file containing say 1024 bytes and upload it. The BUnitBrowserFile implementation allows the file to be uploaded.

Expected behavior:

The BUnitBrowserFile implementation throws an exception just like the built in Blazor InputFile component does.

Version info:

linkdotnet commented 4 months ago

Hey @MorneZaayman

That is a fair point. That said - I will provide a fix that will throw in your described case.

MorneZaayman commented 4 months ago

Dankeschön. Wow PR already up - you're fast!

linkdotnet commented 4 months ago

Sehr gern. We could release a pre-release if you want - depending on your policy.

MorneZaayman commented 4 months ago

I appreciate it, but there's no need for that, as long as it won't be months before it is released. We have some other work to complete before this goes live anyway, so we can deal with the failing test in the meantime.

linkdotnet commented 4 months ago

No I don't think so - @egil It might make sense to release even that version as we patch the CVE in STJ as well. Otherwise folks might have to do the same just because bUnit uses an old STJ version (due to its dependencies)

egil commented 4 months ago

Let's do it @linkdotnet. Send a release out.

linkdotnet commented 4 months ago

Version 1.30 is out @MorneZaayman - This includes the new fix

MorneZaayman commented 3 months ago

Thanks for the quick turnaround. Sorry for the delay in getting back to you - I was away on leave and then catching up when I returned. I've tested with the latest release and it's working perfectly 👍🏻.