Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8958af4

Browse filesBrowse files
watildetargos
authored andcommitted
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>
1 parent d291e3a commit 8958af4
Copy full SHA for 8958af4

File tree

Expand file treeCollapse file tree

2 files changed

+49
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+49
-4
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-policy-parse-integrity.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-parse-integrity.js
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const packageFilepath = path.join(tmpdirPath, 'package.json');
4444
const packageURL = pathToFileURL(packageFilepath);
4545
const packageBody = '{"main": "dep.js"}';
4646

47-
function test({ shouldFail, integrity }) {
47+
function test({ shouldFail, integrity, manifest = {} }) {
48+
manifest.resources = {};
4849
const resources = {
4950
[packageURL]: {
5051
body: packageBody,
@@ -55,9 +56,6 @@ function test({ shouldFail, integrity }) {
5556
integrity
5657
}
5758
};
58-
const manifest = {
59-
resources: {},
60-
};
6159
for (const [url, { body, integrity }] of Object.entries(resources)) {
6260
manifest.resources[url] = {
6361
integrity,
@@ -96,3 +94,17 @@ test({
9694
depBody
9795
)}`,
9896
});
97+
test({
98+
shouldFail: true,
99+
integrity: `sha256-${hash('sha256', 'file:///')}`,
100+
manifest: {
101+
onerror: 'exit'
102+
}
103+
});
104+
test({
105+
shouldFail: false,
106+
integrity: `sha256-${hash('sha256', 'file:///')}`,
107+
manifest: {
108+
onerror: 'log'
109+
}
110+
});
Collapse file

‎test/parallel/test-policy-scopes-integrity.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-scopes-integrity.js
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,36 @@ const assert = require('assert');
280280
}
281281
}
282282
// #endregion
283+
// #startonerror
284+
{
285+
const manifest = new Manifest({
286+
scopes: {
287+
'file:///': {
288+
integrity: true
289+
}
290+
},
291+
onerror: 'throw'
292+
});
293+
assert.throws(
294+
() => {
295+
manifest.assertIntegrity('http://example.com');
296+
},
297+
/ERR_MANIFEST_ASSERT_INTEGRITY/
298+
);
299+
}
300+
{
301+
assert.throws(
302+
() => {
303+
new Manifest({
304+
scopes: {
305+
'file:///': {
306+
integrity: true
307+
}
308+
},
309+
onerror: 'unknown'
310+
});
311+
},
312+
/ERR_MANIFEST_UNKNOWN_ONERROR/
313+
);
314+
}
315+
// #endonerror

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.