Skip to content

[browser][WBT] EventPipe - end to end test #115945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/testing/scenarios/BuildWasmAppsJobsList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Wasm.Build.Tests.Blazor.NativeTests
Wasm.Build.Tests.Blazor.NoopNativeRebuildTest
Wasm.Build.Tests.Blazor.WorkloadRequiredTests
Wasm.Build.Tests.Blazor.SignalRClientTests
Wasm.Build.Tests.Blazor.EventPipeDiagnosticsTests
Wasm.Build.Tests.BuildPublishTests
Wasm.Build.Tests.ConfigSrcTests
Wasm.Build.Tests.DllImportTests
Expand Down
3 changes: 3 additions & 0 deletions src/mono/browser/runtime/diagnostics/diagnostics-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export function cleanupClient () {
}

export function setupJsClient (client:IDiagnosticClient) {
if (nextJsClient.promise_control.isDone) {
throw new Error("multiple clients in parallel are not allowed");
}
nextJsClient.promise_control.resolve(client);
}

Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public BlazorRunOptions(
string BrowserPath = "",
string Locale = "en-US",
int? ExpectedExitCode = 0,
int? TimeoutSeconds = 10,
string CustomBundleDir = "",
bool CheckCounter = true,
Func<IPage, Task>? Test = null,
Expand All @@ -48,6 +49,7 @@ public BlazorRunOptions(
Locale,
ExpectedExitCode,
CustomBundleDir,
TimeoutSeconds,
ExecuteAfterLoaded
)
{
Expand Down
344 changes: 344 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract record RunOptions
string Locale = "en-US",
int? ExpectedExitCode = 0,
string CustomBundleDir = "",
int? TimeoutSeconds = 10,
Func<RunOptions, IPage, Task>? ExecuteAfterLoaded = null
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private async Task<RunResult> BrowserRunTest(string runArgs,
await blazorOp.Test(page);

_testOutput.WriteLine($"Waiting for additional 10secs to see if any errors are reported");
int exitCode = await runner.WaitForExitMessageAsync(TimeSpan.FromSeconds(10));
int exitCode = await runner.WaitForExitMessageAsync(TimeSpan.FromSeconds(runOptions.TimeoutSeconds ?? 0));
if (runOptions.ExpectedExitCode is not null && exitCode != runOptions.ExpectedExitCode)
throw new Exception($"Expected exit code {runOptions.ExpectedExitCode} but got {exitCode}.\nconsoleOutput={string.Join("\n", consoleOutput)}");

Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Playwright" Version="1.47.0" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.350" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.10" />
<ProjectReference Include="$(RepoRoot)src\tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj" />

<None Include="$(BrowserProjectRoot)\test-main.js" CopyToOutputDirectory="PreserveNewest" />
Expand Down
53 changes: 53 additions & 0 deletions src/mono/wasm/host/DevServer/DevServerStartup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Net.WebSockets;
using System.Threading.Tasks;
Expand Down Expand Up @@ -115,6 +116,58 @@ public static void Configure(IApplicationBuilder app, IOptions<DevServerOptions>
}
}
});

// Add general-purpose file upload endpoint when DEVSERVER_UPLOAD_PATH is set
string? fileUploadPath = Environment.GetEnvironmentVariable("DEVSERVER_UPLOAD_PATH");
if (!string.IsNullOrEmpty(fileUploadPath))
{
// Ensure the upload directory exists
if (!Directory.Exists(fileUploadPath))
{
Directory.CreateDirectory(fileUploadPath!);
}

// Route with filename parameter
endpoints.MapPost("/upload/{filename}", async context =>
{
try
{
// Get the filename from the route
var routeValues = context.Request.RouteValues;
string? rawFileName = routeValues["filename"]?.ToString();

// Generate a unique name if none provided
if (string.IsNullOrEmpty(rawFileName))
{
rawFileName = $"upload_{Guid.NewGuid():N}";
}

// Sanitize filename - IMPORTANT: Only use GetFileName to strip any path components
// This prevents directory traversal attacks like "../../../etc/passwd"
string fileName = Path.GetFileName(rawFileName);

if (string.IsNullOrEmpty(fileName))
{
fileName = $"upload_{Guid.NewGuid():N}";
}

string filePath = Path.Combine(fileUploadPath!, fileName);

using (var outputStream = new FileStream(filePath, FileMode.Create))
{
await context.Request.Body.CopyToAsync(outputStream);
}

await context.Response.WriteAsync($"File saved to {filePath}");
}
catch (Exception ex)
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync($"Error processing upload: {ex.Message}");
}
});
}

});

ServerURLsProvider.ResolveServerUrlsOnApplicationStarted(app, logger, applicationLifetime, realUrlsAvailableTcs, "/_framework/debug");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0-alpha.2.25073.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0-alpha.2.25073.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0-alpha.2.25073.4" PrivateAssets="all" Condition="'$(WBTDevServer)' != 'true'" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"runtimeOptions": {
"wasmHostProperties": {
"perHostConfig": [
{
"name": "browser",
"html-path": "index.html",
"Host": "browser"
}
]
}
}
}