Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): correctly handle scripts when usi…
Browse files Browse the repository at this point in the history
…ng subresource-integrity option

Fixes #19829
  • Loading branch information
alan-agius4 authored and filipesilva committed Jan 25, 2021
1 parent 3db8c6e commit d0cc0cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
const { result } = await harness.executeOnce();

expect(result?.success).toBe(true);
harness.expectFile('dist/index.html').content.toContain('integrity=');
harness.expectFile('dist/index.html').content.not.toContain('integrity=');
});

it(`does not add integrity attribute when 'false'`, async () => {
Expand All @@ -32,7 +32,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
const { result } = await harness.executeOnce();

expect(result?.success).toBe(true);
harness.expectFile('dist/index.html').content.toContain('integrity=');
harness.expectFile('dist/index.html').content.not.toContain('integrity=');
});

it(`does add integrity attribute when 'true'`, async () => {
Expand All @@ -46,5 +46,25 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
expect(result?.success).toBe(true);
harness.expectFile('dist/index.html').content.toMatch(/integrity="\w+-[A-Za-z0-9\/\+=]+"/);
});

it(`does not issue a warning when 'true' and 'scripts' is set.`, async () => {
await harness.writeFile('src/script.js', '');

harness.useTarget('build', {
...BASE_OPTIONS,
subresourceIntegrity: true,
scripts: ['src/script.js'],
});

const { result, logs } = await harness.executeOnce();

expect(result?.success).toBe(true);
harness.expectFile('dist/index.html').content.toMatch(/integrity="\w+-[A-Za-z0-9\/\+=]+"/);
expect(logs).not.toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching(/subresource-integrity/),
}),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class ScriptsWebpackPlugin {
}

compilation.assets[filename] = source;
compilation.hooks.chunkAsset.call(chunk, filename);
}

apply(compiler: Compiler): void {
Expand Down

0 comments on commit d0cc0cb

Please sign in to comment.