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 7a9d1ebc4a5ad7..b2de9206dd3842 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) => { @@ -232,6 +238,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 080c3907a60baf..6caa37be20b766 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, cache = GetCacheControl(a.Key, resources) }; @@ -286,7 +286,7 @@ public string TransformResourcesToAssets(BootJsonData config, bool bundlerFriend { virtualPath = resources.fingerprinting?[a.Key] ?? a.Key, name = a.Key, - integrity = a.Value, + hash = a.Value, cache = GetCacheControl(a.Key, resources) }; @@ -326,7 +326,7 @@ public string TransformResourcesToAssets(BootJsonData config, bool bundlerFriend { virtualPath = a.Key, name = assetName, - integrity = a.Value.Values.First(), + hash = a.Value.Values.First(), cache = GetCacheControl(assetName, resources) }; 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 f879acedeba611..16563259a399d9 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs @@ -358,7 +358,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; } public string cache { get; set; } } @@ -368,7 +368,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; } public string cache { get; set; } } @@ -378,7 +378,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; } public string cache { get; set; } }