diff --git a/src/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs b/src/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs index b50bedbe2b1aca..6e62d3edf324c9 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs @@ -105,4 +105,21 @@ public async Task OverrideBootConfigName(Configuration config, bool isPublish) m => Assert.Equal("Managed code has run", m) ); } + + [Fact, TestCategory("bundler-friendly")] + public async Task AssetIntegrity() + { + Configuration config = Configuration.Debug; + ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, $"AssetIntegrity"); + PublishProject(info, config); + + var result = await RunForPublishWithWebServer(new BrowserRunOptions( + Configuration: config, + TestScenario: "AssetIntegrity" + )); + Assert.False( + result.TestOutput.Any(m => !m.Contains(".js") && !m.Contains(".json") && m.Contains("has integrity ''")), + "There are assets without integrity hash" + ); + } } diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index 522cf6ee6c7936..74b9bed45db269 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js @@ -95,6 +95,12 @@ switch (testCase) { } }); break; + case "AssetIntegrity": + dotnet.withResourceLoader((type, name, defaultUri, integrity, behavior) => { + testOutput(`Asset '${name}' has integrity '${integrity}'`); + return defaultUri; + }); + break; case "OutErrOverrideWorks": dotnet.withModuleConfig({ out: (message) => { @@ -238,6 +244,7 @@ try { exit(0); break; case "DownloadResourceProgressTest": + case "AssetIntegrity": exit(0); break; case "OutErrOverrideWorks": diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs index e15923d45d0d6a..13a36e0e90a145 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs @@ -224,7 +224,7 @@ public string TransformResourcesToAssets(BootJsonData config, bool bundlerFriend var asset = new WasmAsset() { name = a.Key, - integrity = a.Value + hash = a.Value }; if (bundlerFriendly) @@ -284,7 +284,7 @@ public string TransformResourcesToAssets(BootJsonData config, bool bundlerFriend { virtualPath = resources.fingerprinting?[a.Key] ?? a.Key, name = a.Key, - integrity = a.Value + hash = a.Value }; if (bundlerFriendly) @@ -322,7 +322,7 @@ public string TransformResourcesToAssets(BootJsonData config, bool bundlerFriend { virtualPath = a.Key, name = $"../{a.Value.Keys.First()}", - integrity = a.Value.Values.First() + hash = a.Value.Values.First() }; if (bundlerFriendly) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs index 250fabdd5e9e67..72189864fd3b35 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs @@ -357,7 +357,7 @@ public class SymbolsAsset public class WasmAsset { public string name { get; set; } - public string integrity { get; set; } + public string hash { get; set; } public string resolvedUrl { get; set; } } @@ -366,7 +366,7 @@ public class GeneralAsset { public string virtualPath { get; set; } public string name { get; set; } - public string integrity { get; set; } + public string hash { get; set; } public string resolvedUrl { get; set; } } @@ -375,7 +375,7 @@ public class VfsAsset { public string virtualPath { get; set; } public string name { get; set; } - public string integrity { get; set; } + public string hash { get; set; } public string resolvedUrl { get; set; } }