Skip to content
Closed
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
10 changes: 5 additions & 5 deletions src/mono/browser/runtime/dotnet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,17 @@ type Asset = {
};
type WasmAsset = Asset & {
name: string;
hash?: string | null | "";
integrity?: string | null | "";
};
type AssemblyAsset = Asset & {
virtualPath: string;
name: string;
hash?: string | null | "";
integrity?: string | null | "";
};
type PdbAsset = Asset & {
virtualPath: string;
name: string;
hash?: string | null | "";
integrity?: string | null | "";
};
type JsAsset = Asset & {
/**
Expand All @@ -315,12 +315,12 @@ type SymbolsAsset = Asset & {
type VfsAsset = Asset & {
virtualPath: string;
name: string;
hash?: string | null | "";
integrity?: string | null | "";
};
type IcuAsset = Asset & {
virtualPath: string;
name: string;
hash?: string | null | "";
integrity?: string | null | "";
};
/**
* A "key" is name of the file, a "value" is optional hash for integrity check.
Expand Down
7 changes: 7 additions & 0 deletions src/mono/browser/runtime/loader/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ function convert_single_asset (assetsCollection: AssetEntryInternal[], resource:

const assetEntry = resource[0] as AssetEntryInternal;
assetEntry.behavior = behavior;
if ((assetEntry as any).integrity) {
assetEntry.hash = (assetEntry as any).integrity;
}

set_single_asset(assetEntry);

Expand Down Expand Up @@ -308,6 +311,10 @@ export function prepareAssets () {
const addAsset = (asset: Asset, behavior: AssetBehaviors, isCore: boolean) => {
const assetEntry = asset as AssetEntryInternal;
assetEntry.behavior = behavior;
if ((asset as any).integrity) {
assetEntry.hash = (asset as any).integrity;
}

if (isCore) {
assetEntry.isCore = true;
coreAssetsToLoad.push(assetEntry);
Expand Down
10 changes: 5 additions & 5 deletions src/mono/browser/runtime/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,19 @@ export type Asset = {

export type WasmAsset = Asset & {
name: string;
hash?: string | null | "";
integrity?: string | null | "";
}

export type AssemblyAsset = Asset & {
virtualPath: string;
name: string; // actually URL
hash?: string | null | "";
integrity?: string | null | "";
}

export type PdbAsset = Asset & {
virtualPath: string;
name: string; // actually URL
hash?: string | null | "";
integrity?: string | null | "";
}

export type JsAsset = Asset & {
Expand All @@ -282,13 +282,13 @@ export type SymbolsAsset = Asset & {
export type VfsAsset = Asset & {
virtualPath: string;
name: string; // actually URL
hash?: string | null | "";
integrity?: string | null | "";
}

export type IcuAsset = Asset & {
virtualPath: string;
name: string; // actually URL
hash?: string | null | "";
integrity?: string | null | "";
}

/**
Expand Down
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
Loading