Skip to content
Permalink
Browse files

Fix: SRI ignore ignoredUrls correctly

Fix #1990
  • Loading branch information...
sarvaje authored and molant committed Mar 6, 2019
1 parent 8bed0b0 commit 9c279b9643bf700be46ef7ad96a6d4d343cfce04
Showing with 38 additions and 0 deletions.
  1. +5 −0 packages/hint-sri/src/hint.ts
  2. +18 −0 packages/hint-sri/tests/tests-https.ts
  3. +15 −0 packages/hint-sri/tests/tests-local.ts
@@ -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,
@@ -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, {
@@ -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'
]
}]
});
@@ -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 9c279b9

Please sign in to comment.
You can’t perform that action at this time.