diff --git a/test/parallel/test-policy-parse-integrity.js b/test/parallel/test-policy-parse-integrity.js index 9241f1e7843b64..d042ccee0a49af 100644 --- a/test/parallel/test-policy-parse-integrity.js +++ b/test/parallel/test-policy-parse-integrity.js @@ -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, @@ -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, @@ -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' + } +}); diff --git a/test/parallel/test-policy-scopes-integrity.js b/test/parallel/test-policy-scopes-integrity.js index b506c92c41f625..b61fc3199cd4e0 100644 --- a/test/parallel/test-policy-scopes-integrity.js +++ b/test/parallel/test-policy-scopes-integrity.js @@ -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