Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/ModuleConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -232,6 +238,7 @@ try {
exit(0);
break;
case "DownloadResourceProgressTest":
case "AssetIntegrity":
exit(0);
break;
case "OutErrOverrideWorks":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down Expand Up @@ -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)
};

Expand Down Expand Up @@ -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)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand All @@ -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; }
}
Expand All @@ -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; }
}
Expand Down
Loading