Skip to content

Commit

Permalink
test: use spawnSyncAndExitWithoutError in test/common/sea.js
Browse files Browse the repository at this point in the history
To display more information when the command fails.

PR-URL: #49543
Refs: nodejs/reliability#658
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
joyeecheung authored and ruyadorno committed Sep 28, 2023
1 parent c079c73 commit f79b153
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions test/common/sea.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const common = require('../common');
const fixtures = require('../common/fixtures');

const { readFileSync } = require('fs');
const { execFileSync } = require('child_process');
const {
spawnSyncAndExitWithoutError,
} = require('../common/child_process');

function skipIfSingleExecutableIsNotSupported() {
if (!process.config.variables.single_executable_application)
Expand Down Expand Up @@ -45,38 +47,39 @@ function skipIfSingleExecutableIsNotSupported() {

function injectAndCodeSign(targetExecutable, resource) {
const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js');
execFileSync(process.execPath, [
spawnSyncAndExitWithoutError(process.execPath, [
postjectFile,
targetExecutable,
'NODE_SEA_BLOB',
resource,
'--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [],
]);
], {});

if (process.platform === 'darwin') {
execFileSync('codesign', [ '--sign', '-', targetExecutable ]);
execFileSync('codesign', [ '--verify', targetExecutable ]);
spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ], {});
spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ], {});
} else if (process.platform === 'win32') {
let signtoolFound = false;
try {
execFileSync('where', [ 'signtool' ]);
spawnSyncAndExitWithoutError('where', [ 'signtool' ], {});
signtoolFound = true;
} catch (err) {
console.log(err.message);
}
if (signtoolFound) {
let certificatesFound = false;
let stderr;
try {
execFileSync('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ]);
({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], {}));
certificatesFound = true;
} catch (err) {
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(err)) {
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(stderr)) {
throw err;
}
}
if (certificatesFound) {
execFileSync('signtool', 'verify', '/pa', 'SHA256', targetExecutable);
spawnSyncAndExitWithoutError('signtool', 'verify', '/pa', 'SHA256', targetExecutable, {});
}
}
}
Expand Down

0 comments on commit f79b153

Please sign in to comment.