Skip to content

Commit d44d5d6

Browse files
authored
[browser][WBT] EventPipe - end to end test (#115945)
1 parent 9376d46 commit d44d5d6

File tree

10 files changed

+422
-2
lines changed

10 files changed

+422
-2
lines changed

eng/testing/scenarios/BuildWasmAppsJobsList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Wasm.Build.Tests.Blazor.NativeTests
1515
Wasm.Build.Tests.Blazor.NoopNativeRebuildTest
1616
Wasm.Build.Tests.Blazor.WorkloadRequiredTests
1717
Wasm.Build.Tests.Blazor.SignalRClientTests
18+
Wasm.Build.Tests.Blazor.EventPipeDiagnosticsTests
1819
Wasm.Build.Tests.BuildPublishTests
1920
Wasm.Build.Tests.ConfigSrcTests
2021
Wasm.Build.Tests.DllImportTests

src/mono/browser/runtime/diagnostics/diagnostics-js.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ export function cleanupClient () {
140140
}
141141

142142
export function setupJsClient (client:IDiagnosticClient) {
143+
if (nextJsClient.promise_control.isDone) {
144+
throw new Error("multiple clients in parallel are not allowed");
145+
}
143146
nextJsClient.promise_control.resolve(client);
144147
}
145148

src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public BlazorRunOptions(
2929
string BrowserPath = "",
3030
string Locale = "en-US",
3131
int? ExpectedExitCode = 0,
32+
int? TimeoutSeconds = 10,
3233
string CustomBundleDir = "",
3334
bool CheckCounter = true,
3435
Func<IPage, Task>? Test = null,
@@ -48,6 +49,7 @@ public BlazorRunOptions(
4849
Locale,
4950
ExpectedExitCode,
5051
CustomBundleDir,
52+
TimeoutSeconds,
5153
ExecuteAfterLoaded
5254
)
5355
{

src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs

Lines changed: 346 additions & 0 deletions
Large diffs are not rendered by default.

src/mono/wasm/Wasm.Build.Tests/BrowserStructures/RunOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public abstract record RunOptions
2727
string Locale = "en-US",
2828
int? ExpectedExitCode = 0,
2929
string CustomBundleDir = "",
30+
int? TimeoutSeconds = 10,
3031
Func<RunOptions, IPage, Task>? ExecuteAfterLoaded = null
3132
);
3233

src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private async Task<RunResult> BrowserRunTest(string runArgs,
335335
await blazorOp.Test(page);
336336

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

src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<ItemGroup>
4949
<PackageReference Include="Microsoft.Playwright" Version="1.47.0" />
5050
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.350" />
51+
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.10" />
5152
<ProjectReference Include="$(RepoRoot)src\tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj" />
5253

5354
<None Include="$(BrowserProjectRoot)\test-main.js" CopyToOutputDirectory="PreserveNewest" />

src/mono/wasm/host/DevServer/DevServerStartup.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.IO;
56
using System.Net.WebSockets;
67
using System.Threading.Tasks;
@@ -115,6 +116,58 @@ public static void Configure(IApplicationBuilder app, IOptions<DevServerOptions>
115116
}
116117
}
117118
});
119+
120+
// Add general-purpose file upload endpoint when DEVSERVER_UPLOAD_PATH is set
121+
string? fileUploadPath = Environment.GetEnvironmentVariable("DEVSERVER_UPLOAD_PATH");
122+
if (!string.IsNullOrEmpty(fileUploadPath))
123+
{
124+
// Ensure the upload directory exists
125+
if (!Directory.Exists(fileUploadPath))
126+
{
127+
Directory.CreateDirectory(fileUploadPath!);
128+
}
129+
130+
// Route with filename parameter
131+
endpoints.MapPost("/upload/{filename}", async context =>
132+
{
133+
try
134+
{
135+
// Get the filename from the route
136+
var routeValues = context.Request.RouteValues;
137+
string? rawFileName = routeValues["filename"]?.ToString();
138+
139+
// Generate a unique name if none provided
140+
if (string.IsNullOrEmpty(rawFileName))
141+
{
142+
rawFileName = $"upload_{Guid.NewGuid():N}";
143+
}
144+
145+
// Sanitize filename - IMPORTANT: Only use GetFileName to strip any path components
146+
// This prevents directory traversal attacks like "../../../etc/passwd"
147+
string fileName = Path.GetFileName(rawFileName);
148+
149+
if (string.IsNullOrEmpty(fileName))
150+
{
151+
fileName = $"upload_{Guid.NewGuid():N}";
152+
}
153+
154+
string filePath = Path.Combine(fileUploadPath!, fileName);
155+
156+
using (var outputStream = new FileStream(filePath, FileMode.Create))
157+
{
158+
await context.Request.Body.CopyToAsync(outputStream);
159+
}
160+
161+
await context.Response.WriteAsync($"File saved to {filePath}");
162+
}
163+
catch (Exception ex)
164+
{
165+
context.Response.StatusCode = 500;
166+
await context.Response.WriteAsync($"Error processing upload: {ex.Message}");
167+
}
168+
});
169+
}
170+
118171
});
119172

120173
ServerURLsProvider.ResolveServerUrlsOnApplicationStarted(app, logger, applicationLifetime, realUrlsAvailableTcs, "/_framework/debug");

src/mono/wasm/testassets/BlazorBasicTestApp/App/BlazorBasicTestApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

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

1515
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"runtimeOptions": {
3+
"wasmHostProperties": {
4+
"perHostConfig": [
5+
{
6+
"name": "browser",
7+
"html-path": "index.html",
8+
"Host": "browser"
9+
}
10+
]
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)