summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaijiro Wachi <daijiro.wachi@gmail.com>2020-10-26 01:15:18 +0900
committerDaijiro Wachi <daijiro.wachi@gmail.com>2020-10-29 23:51:55 +0900
commit802c98d65de40f245781f591a0b3b38336d1af94 (patch)
tree58d8eb0c34cbbc002e7201ebcc40fffc77202f12
parentacdfc165709b2ead43d7a5c458a06ed0c718ec46 (diff)
downloadnode-new-802c98d65de40f245781f591a0b3b38336d1af94.tar.gz
test: add onerror test cases to policy
Increase test coverage of lib/internal/policy/manifest.js PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r--test/parallel/test-policy-parse-integrity.js20
-rw-r--r--test/parallel/test-policy-scopes-integrity.js33
2 files changed, 49 insertions, 4 deletions
diff --git a/test/parallel/test-policy-parse-integrity.js b/test/parallel/test-policy-parse-integrity.js
index 9241f1e784..d042ccee0a 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 b506c92c41..b61fc3199c 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