Skip to content

Commit 8958af4

Browse 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

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

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

Lines 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
constpackageURL=pathToFileURL(packageFilepath);
4545
constpackageBody='{"main": "dep.js"}';
4646

47-
functiontest({ shouldFail, integrity }){
47+
functiontest({ shouldFail, integrity, manifest ={}}){
48+
manifest.resources={};
4849
constresources={
4950
[packageURL]: {
5051
body: packageBody,
@@ -55,9 +56,6 @@ function test({ shouldFail, integrity }) {
5556
integrity
5657
}
5758
};
58-
constmanifest={
59-
resources: {},
60-
};
6159
for(const[url,{ body, integrity }]ofObject.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+
});

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

Lines 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+
constmanifest=newManifest({
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+
newManifest({
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)