Skip to content

Commit

Permalink
Fix: SRI ignore ignoredUrls correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvaje committed Mar 6, 2019
1 parent 8455329 commit 8ebd132
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/hint-sri/src/hint.ts
Expand Up @@ -436,9 +436,14 @@ Actual: ${integrities.join(', ')}`;
}
}

private isNotIgnored(evt: FetchEnd) {
return !this.context.isUrlIgnored(evt.resource);
}

/** Validation entry point. */
private async validateResource(evt: FetchEnd, urls: URLs) {
const validations = [
this.isNotIgnored,
this.isInCache,
this.addToCache,
this.isScriptOrLink,
Expand Down
18 changes: 18 additions & 0 deletions packages/hint-sri/tests/tests-https.ts
Expand Up @@ -266,6 +266,15 @@ const configTestsLow: HintTest[] = [
}
];

const testsIgnoredUrls = [
{
name: `Page with a same-origin resource, SRI sha384 and baseline is 512, with the url ignored should pass`,
serverConfig: {
'/': generateHTMLPage('<link rel="stylesheet" href="/styles.css" integrity="sha384-lai7vFxeX5cfA6yRNCr/WHChPKVsaaYLX1IC1j+GOyS6RWj/BqI8bHH8AP2HPwv4">'),
'/styles.css': styles
}
}
];

hintRunner.testHint(hintPath, defaults, { https: true });
hintRunner.testHint(hintPath, configOriginAllTestsHttps, {
Expand All @@ -286,3 +295,12 @@ hintRunner.testHint(hintPath, configTestsLow, {
},
https: true
});
hintRunner.testHint(hintPath, testsIgnoredUrls, {
https: true,
ignoredUrls: [{
domain: '^https://localhost(\\:[0-9]{1,5})/styles\\.css',
hints: [
'sri'
]
}]
});
15 changes: 15 additions & 0 deletions packages/hint-sri/tests/tests-local.ts
Expand Up @@ -22,7 +22,22 @@ Actual: sha256-YCbKJH6PpUlk130udu/JepdKVpXjdEyzje+z1pE=`
}
];

const testsIgnoredUrls = [{
name: 'If the URL with no valid sri is ignored, it should pass',
path: path.join(__dirname, 'fixtures', 'local-no-pass')
}];

hintRunner.testLocalHint(hintPath, tests, {
hintOptions: { baseline: 'sha256' },
parsers: ['html']
});

hintRunner.testLocalHint(hintPath, testsIgnoredUrls, {
ignoredUrls: [{
domain: '^https://cdnjs.cloudflare.com/ajax/libs/jquery/3\\.3\\.1/core\\.js',
hints: [
'sri'
]
}],
parser: ['html']
});

0 comments on commit 8ebd132

Please sign in to comment.