| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d291e3a commit 8958af4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,8 @@ const packageFilepath = path.join(tmpdirPath, 'package.json'); | |||
| 44 | 44 | const packageURL = pathToFileURL(packageFilepath); | |
| 45 | 45 | const packageBody = '{"main": "dep.js"}'; | |
| 46 | 46 | ||
| 47 | - function test({ shouldFail, integrity }) { | ||
| 47 | + function test({ shouldFail, integrity, manifest = {} }) { | ||
| 48 | + manifest.resources = {}; | ||
| 48 | 49 | const resources = { | |
| 49 | 50 | [packageURL]: { | |
| 50 | 51 | body: packageBody, | |
@@ -55,9 +56,6 @@ function test({ shouldFail, integrity }) { | |||
| 55 | 56 | integrity | |
| 56 | 57 | } | |
| 57 | 58 | }; | |
| 58 | - const manifest = { | ||
| 59 | - resources: {}, | ||
| 60 | - }; | ||
| 61 | 59 | for (const [url, { body, integrity }] of Object.entries(resources)) { | |
| 62 | 60 | manifest.resources[url] = { | |
| 63 | 61 | integrity, | |
@@ -96,3 +94,17 @@ test({ | |||
| 96 | 94 | depBody | |
| 97 | 95 | )}`, | |
| 98 | 96 | }); | |
| 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 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -280,3 +280,36 @@ const assert = require('assert'); | |||
| 280 | 280 | } | |
| 281 | 281 | } | |
| 282 | 282 | // #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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments