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
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