Skip to content

Commit

Permalink
test: add onerror test cases to policy
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde authored and targos committed Nov 3, 2020
1 parent d291e3a commit 8958af4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/parallel/test-policy-parse-integrity.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const packageFilepath = path.join(tmpdirPath, 'package.json');
const packageURL = pathToFileURL(packageFilepath);
const packageBody = '{"main": "dep.js"}';

function test({ shouldFail, integrity }) {
function test({ shouldFail, integrity, manifest = {} }) {
manifest.resources = {};
const resources = {
[packageURL]: {
body: packageBody,
Expand All @@ -55,9 +56,6 @@ function test({ shouldFail, integrity }) {
integrity
}
};
const manifest = {
resources: {},
};
for (const [url, { body, integrity }] of Object.entries(resources)) {
manifest.resources[url] = {
integrity,
Expand Down Expand Up @@ -96,3 +94,17 @@ test({
depBody
)}`,
});
test({
shouldFail: true,
integrity: `sha256-${hash('sha256', 'file:///')}`,
manifest: {
onerror: 'exit'
}
});
test({
shouldFail: false,
integrity: `sha256-${hash('sha256', 'file:///')}`,
manifest: {
onerror: 'log'
}
});
33 changes: 33 additions & 0 deletions test/parallel/test-policy-scopes-integrity.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,36 @@ const assert = require('assert');
}
}
// #endregion
// #startonerror
{
const manifest = new Manifest({
scopes: {
'file:///': {
integrity: true
}
},
onerror: 'throw'
});
assert.throws(
() => {
manifest.assertIntegrity('http://example.com');
},
/ERR_MANIFEST_ASSERT_INTEGRITY/
);
}
{
assert.throws(
() => {
new Manifest({
scopes: {
'file:///': {
integrity: true
}
},
onerror: 'unknown'
});
},
/ERR_MANIFEST_UNKNOWN_ONERROR/
);
}
// #endonerror

0 comments on commit 8958af4

Please sign in to comment.