GeezerVison is showing github.com — test: skip SEA tests when SEA generation fails · nodejs/node@e992af8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/common/README.md +6-4Lines changed: 6 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1048,11 +1048,13 @@ Application functionality. | 1048 | 1048 | Skip the rest of the tests if single executable applications are not supported | 1049 | 1049 | in the current configuration. | 1050 | 1050 |
| 1051 | | -### `injectAndCodeSign(targetExecutable, resource)` | | 1051 | +### `generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow)` | 1052 | 1052 |
| 1053 | | -Uses Postect to inject the contents of the file at the path `resource` into | 1054 | | -the target executable file at the path `targetExecutable` and ultimately code | 1055 | | -sign the final binary. | | 1053 | +Copy `sourceExecutable` to `targetExecutable`, use postject to inject `seaBlob` | | 1054 | +into `targetExecutable` and sign it if necessary. | | 1055 | + | | 1056 | +If `verifyWorkflow` is false (default) and any of the steps fails, | | 1057 | +it skips the tests. Otherwise, an error is thrown. | 1056 | 1058 |
| 1057 | 1059 | ## tick Module | 1058 | 1060 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/common/sea.js +59-30Lines changed: 59 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const common = require('../common'); | 4 | 4 | const fixtures = require('../common/fixtures'); | 5 | 5 | const tmpdir = require('../common/tmpdir'); | | 6 | +const { inspect } = require('util'); | 6 | 7 |
| 7 | | -const { readFileSync } = require('fs'); | | 8 | +const { readFileSync, copyFileSync } = require('fs'); | 8 | 9 | const { | 9 | 10 | spawnSyncAndExitWithoutError, | 10 | 11 | } = require('../common/child_process'); | @@ -54,47 +55,75 @@ function skipIfSingleExecutableIsNotSupported() { | 54 | 55 | } | 55 | 56 | } | 56 | 57 |
| 57 | | -function injectAndCodeSign(targetExecutable, resource) { | | 58 | +function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow = false) { | | 59 | + try { | | 60 | + copyFileSync(sourceExecutable, targetExecutable); | | 61 | + } catch (e) { | | 62 | + const message = `Cannot copy ${sourceExecutable} to ${targetExecutable}: ${inspect(e)}`; | | 63 | + if (verifyWorkflow) { | | 64 | + throw new Error(message); | | 65 | + } | | 66 | + common.skip(message); | | 67 | + } | | 68 | + console.log(`Copied ${sourceExecutable} to ${targetExecutable}`); | | 69 | + | 58 | 70 | const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js'); | 59 | | - spawnSyncAndExitWithoutError(process.execPath, [ | 60 | | - postjectFile, | 61 | | - targetExecutable, | 62 | | - 'NODE_SEA_BLOB', | 63 | | - resource, | 64 | | - '--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2', | 65 | | - ...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [], | 66 | | - ], {}); | | 71 | + try { | | 72 | + spawnSyncAndExitWithoutError(process.execPath, [ | | 73 | + postjectFile, | | 74 | + targetExecutable, | | 75 | + 'NODE_SEA_BLOB', | | 76 | + seaBlob, | | 77 | + '--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2', | | 78 | + ...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [], | | 79 | + ]); | | 80 | + } catch (e) { | | 81 | + const message = `Cannot inject ${seaBlob} into ${targetExecutable}: ${inspect(e)}`; | | 82 | + if (verifyWorkflow) { | | 83 | + throw new Error(message); | | 84 | + } | | 85 | + common.skip(message); | | 86 | + } | | 87 | + console.log(`Injected ${seaBlob} into ${targetExecutable}`); | 67 | 88 |
| 68 | 89 | if (process.platform === 'darwin') { | 69 | | - spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ], {}); | 70 | | - spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ], {}); | | 90 | + try { | | 91 | + spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ], {}); | | 92 | + spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ], {}); | | 93 | + } catch (e) { | | 94 | + const message = `Cannot sign ${targetExecutable}: ${inspect(e)}`; | | 95 | + if (verifyWorkflow) { | | 96 | + throw new Error(message); | | 97 | + } | | 98 | + common.skip(message); | | 99 | + } | | 100 | + console.log(`Signed ${targetExecutable}`); | 71 | 101 | } else if (process.platform === 'win32') { | 72 | | - let signtoolFound = false; | 73 | 102 | try { | 74 | 103 | spawnSyncAndExitWithoutError('where', [ 'signtool' ], {}); | 75 | | - signtoolFound = true; | 76 | | - } catch (err) { | 77 | | - console.log(err.message); | 78 | | - } | 79 | | - if (signtoolFound) { | 80 | | - let certificatesFound = false; | 81 | | - let stderr; | 82 | | - try { | 83 | | - ({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], {})); | 84 | | - certificatesFound = true; | 85 | | - } catch (err) { | 86 | | - if (!/SignTool Error: No certificates were found that met all the given criteria/.test(stderr)) { | 87 | | - throw err; | 88 | | - } | | 104 | + } catch (e) { | | 105 | + const message = `Cannot find signtool: ${inspect(e)}`; | | 106 | + if (verifyWorkflow) { | | 107 | + throw new Error(message); | 89 | 108 | } | 90 | | - if (certificatesFound) { | 91 | | - spawnSyncAndExitWithoutError('signtool', 'verify', '/pa', 'SHA256', targetExecutable, {}); | | 109 | + common.skip(message); | | 110 | + } | | 111 | + let stderr; | | 112 | + try { | | 113 | + ({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], {})); | | 114 | + spawnSyncAndExitWithoutError('signtool', 'verify', '/pa', 'SHA256', targetExecutable, {}); | | 115 | + } catch (e) { | | 116 | + const message = `Cannot sign ${targetExecutable}: ${inspect(e)}\n${stderr}`; | | 117 | + if (verifyWorkflow) { | | 118 | + throw new Error(message); | 92 | 119 | } | | 120 | + common.skip(message); | 93 | 121 | } | | 122 | + console.log(`Signed ${targetExecutable}`); | 94 | 123 | } | 95 | 124 | } | 96 | 125 |
| 97 | 126 | module.exports = { | 98 | 127 | skipIfSingleExecutableIsNotSupported, | 99 | | - injectAndCodeSign, | | 128 | + generateSEA, | 100 | 129 | }; |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application-assets-raw.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const common = require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -56,8 +56,7 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se | 56 | 56 |
| 57 | 57 | assert(existsSync(seaPrepBlob)); | 58 | 58 |
| 59 | | - copyFileSync(process.execPath, outputFile); | 60 | | - injectAndCodeSign(outputFile, seaPrepBlob); | | 59 | + generateSEA(outputFile, process.execPath, seaPrepBlob); | 61 | 60 |
| 62 | 61 | spawnSyncAndExitWithoutError( | 63 | 62 | outputFile, | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application-assets.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const common = require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -109,8 +109,7 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se | 109 | 109 |
| 110 | 110 | assert(existsSync(seaPrepBlob)); | 111 | 111 |
| 112 | | - copyFileSync(process.execPath, outputFile); | 113 | | - injectAndCodeSign(outputFile, seaPrepBlob); | | 112 | + generateSEA(outputFile, process.execPath, seaPrepBlob); | 114 | 113 |
| 115 | 114 | spawnSyncAndExitWithoutError( | 116 | 115 | outputFile, | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application-disable-experimental-sea-warning.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -51,8 +51,7 @@ spawnSyncAndExitWithoutError( | 51 | 51 |
| 52 | 52 | assert(existsSync(seaPrepBlob)); | 53 | 53 |
| 54 | | -copyFileSync(process.execPath, outputFile); | 55 | | -injectAndCodeSign(outputFile, seaPrepBlob); | | 54 | +generateSEA(outputFile, process.execPath, seaPrepBlob); | 56 | 55 |
| 57 | 56 | spawnSyncAndExitWithoutError( | 58 | 57 | outputFile, | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application-empty.js +17-5Lines changed: 17 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | | -require('../common'); | | 3 | +const common = require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -13,7 +13,7 @@ skipIfSingleExecutableIsNotSupported(); | 13 | 13 | // script. | 14 | 14 |
| 15 | 15 | const tmpdir = require('../common/tmpdir'); | 16 | | -const { copyFileSync, writeFileSync, existsSync } = require('fs'); | | 16 | +const { writeFileSync, existsSync } = require('fs'); | 17 | 17 | const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | 18 | 18 | const assert = require('assert'); | 19 | 19 |
| @@ -38,8 +38,20 @@ spawnSyncAndExitWithoutError( | 38 | 38 |
| 39 | 39 | assert(existsSync(seaPrepBlob)); | 40 | 40 |
| 41 | | -copyFileSync(process.execPath, outputFile); | 42 | | -injectAndCodeSign(outputFile, seaPrepBlob); | | 41 | +// Verify the workflow. | | 42 | +try { | | 43 | + generateSEA(outputFile, process.execPath, seaPrepBlob, true); | | 44 | +} catch (e) { | | 45 | + if (/Cannot copy/.test(e.message)) { | | 46 | + common.skip(e.message); | | 47 | + } else if (common.isWindows) { | | 48 | + if (/Cannot sign/.test(e.message) || /Cannot find signtool/.test(e.message)) { | | 49 | + common.skip(e.message); | | 50 | + } | | 51 | + } | | 52 | + | | 53 | + throw e; | | 54 | +} | 43 | 55 |
| 44 | 56 | spawnSyncAndExitWithoutError( | 45 | 57 | outputFile, | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application-snapshot-and-code-cache.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -12,7 +12,7 @@ skipIfSingleExecutableIsNotSupported(); | 12 | 12 | // This tests "useCodeCache" is ignored when "useSnapshot" is true. | 13 | 13 |
| 14 | 14 | const tmpdir = require('../common/tmpdir'); | 15 | | -const { copyFileSync, writeFileSync, existsSync } = require('fs'); | | 15 | +const { writeFileSync, existsSync } = require('fs'); | 16 | 16 | const { | 17 | 17 | spawnSyncAndExitWithoutError | 18 | 18 | } = require('../common/child_process'); | @@ -62,8 +62,7 @@ const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' : | 62 | 62 |
| 63 | 63 | assert(existsSync(seaPrepBlob)); | 64 | 64 |
| 65 | | - copyFileSync(process.execPath, outputFile); | 66 | | - injectAndCodeSign(outputFile, seaPrepBlob); | | 65 | + generateSEA(outputFile, process.execPath, seaPrepBlob); | 67 | 66 |
| 68 | 67 | spawnSyncAndExitWithoutError( | 69 | 68 | outputFile, | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application-snapshot.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -12,7 +12,7 @@ skipIfSingleExecutableIsNotSupported(); | 12 | 12 | // This tests the snapshot support in single executable applications. | 13 | 13 |
| 14 | 14 | const tmpdir = require('../common/tmpdir'); | 15 | | -const { copyFileSync, writeFileSync, existsSync } = require('fs'); | | 15 | +const { writeFileSync, existsSync } = require('fs'); | 16 | 16 | const { | 17 | 17 | spawnSyncAndExit, | 18 | 18 | spawnSyncAndExitWithoutError | @@ -85,8 +85,7 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se | 85 | 85 |
| 86 | 86 | assert(existsSync(seaPrepBlob)); | 87 | 87 |
| 88 | | - copyFileSync(process.execPath, outputFile); | 89 | | - injectAndCodeSign(outputFile, seaPrepBlob); | | 88 | + generateSEA(outputFile, process.execPath, seaPrepBlob); | 90 | 89 |
| 91 | 90 | spawnSyncAndExitWithoutError( | 92 | 91 | outputFile, | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application-use-code-cache.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -56,8 +56,7 @@ spawnSyncAndExitWithoutError( | 56 | 56 |
| 57 | 57 | assert(existsSync(seaPrepBlob)); | 58 | 58 |
| 59 | | -copyFileSync(process.execPath, outputFile); | 60 | | -injectAndCodeSign(outputFile, seaPrepBlob); | | 59 | +generateSEA(outputFile, process.execPath, seaPrepBlob); | 61 | 60 |
| 62 | 61 | spawnSyncAndExitWithoutError( | 63 | 62 | outputFile, | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-single-executable-application.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | | - injectAndCodeSign, | | 6 | + generateSEA, | 7 | 7 | skipIfSingleExecutableIsNotSupported, | 8 | 8 | } = require('../common/sea'); | 9 | 9 |
| @@ -50,8 +50,7 @@ spawnSyncAndExitWithoutError( | 50 | 50 |
| 51 | 51 | assert(existsSync(seaPrepBlob)); | 52 | 52 |
| 53 | | -copyFileSync(process.execPath, outputFile); | 54 | | -injectAndCodeSign(outputFile, seaPrepBlob); | | 53 | +generateSEA(outputFile, process.execPath, seaPrepBlob); | 55 | 54 |
| 56 | 55 | spawnSyncAndExitWithoutError( | 57 | 56 | outputFile, | |
|