Skip to content

Commit

Permalink
test: use spawnSyncAndExitWithoutError()
Browse files Browse the repository at this point in the history
Use `spawnSyncAndExitWithoutError()` in
`test/parallel/test-macos-app-sandbox.js`.

Refs: nodejs#54802 (comment)
  • Loading branch information
lpinca committed Jan 9, 2025
1 parent dc5d0f9 commit 3871b83
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions test/parallel/test-macos-app-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const child_process = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');

const nodeBinary = process.execPath;

Expand Down Expand Up @@ -42,30 +43,26 @@ fs.copyFileSync(
nodeBinary,
appExecutablePath);


// Sign the app bundle with sandbox entitlements:
assert.strictEqual(
child_process.spawnSync('/usr/bin/codesign', [
'--entitlements', fixtures.path(
'macos-app-sandbox', 'node_sandboxed.entitlements'),
'--force', '-s', '-',
appBundlePath,
]).status,
0);
spawnSyncAndExitWithoutError('/usr/bin/codesign', [
'--entitlements',
fixtures.path('macos-app-sandbox', 'node_sandboxed.entitlements'),
'--force',
'-s',
'-',
appBundlePath,
]);

// Sandboxed app shouldn't be able to read the home dir
assert.notStrictEqual(
child_process.spawnSync(appExecutablePath, [
'-e', 'fs.readdirSync(process.argv[1])', os.homedir(),
]).status,
0);
spawnSyncAndExitWithoutError(appExecutablePath, [
'-e',
'fs.readdirSync(process.argv[1])',
os.homedir(),
]);

if (process.stdin.isTTY) {
// Run the sandboxed node instance with inherited tty stdin
const spawnResult = child_process.spawnSync(
appExecutablePath, ['-e', ''],
{ stdio: 'inherit' }
);

assert.strictEqual(spawnResult.signal, null);
spawnSyncAndExitWithoutError(appExecutablePath, ['-e', ''], {
stdio: 'inherit',
});
}

0 comments on commit 3871b83

Please sign in to comment.