Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test: add onerror test cases to policy
Increase test coverage of lib/internal/policy/manifest.js

PR-URL: #35797
Refs: https://coverage.nodejs.org/coverage-642f2064c06793b7/lib/internal/policy/manifest.js.html#L60
Refs: https://coverage.nodejs.org/coverage-642f2064c06793b7/lib/internal/policy/manifest.js.html#L146
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
watilde authored and BethGriggs committed Dec 15, 2020
1 parent b19a85e commit 3bb7f36
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
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
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 3bb7f36

Please sign in to comment.