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: #54802 (comment)
  • Loading branch information
lpinca committed Jan 9, 2025
1 parent dc5d0f9 commit 396e17c
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions test/parallel/test-macos-app-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ if (process.config.variables.node_builtin_modules_path)

const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const child_process = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
const {
spawnSyncAndExit,

Check failure on line 14 in test/parallel/test-macos-app-sandbox.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 2 spaces but found 4
spawnSyncAndExitWithoutError

Check failure on line 15 in test/parallel/test-macos-app-sandbox.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 2 spaces but found 4
} = require('../common/child_process');

const nodeBinary = process.execPath;

Expand Down Expand Up @@ -42,30 +44,29 @@ 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('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);
spawnSyncAndExit(
appExecutablePath,
['-e', 'fs.readdirSync(process.argv[1])', os.homedir()],
{
status: 1,
signal: null,
},
);

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 396e17c

Please sign in to comment.