From 034bcf2b570e690b03703f349b4e1026e1699ef3 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 28 Jun 2025 23:45:34 -0700 Subject: [PATCH] Deflake These tests should not have been marked as passing. test/js/node/test/parallel/test-cluster-worker-kill-signal.js test/js/node/test/parallel/test-child-process-prototype-tampering.mjs --- ...test-child-process-prototype-tampering.mjs | 91 ------------------- .../test-cluster-worker-kill-signal.js | 49 ---------- 2 files changed, 140 deletions(-) delete mode 100644 test/js/node/test/parallel/test-child-process-prototype-tampering.mjs delete mode 100644 test/js/node/test/parallel/test-cluster-worker-kill-signal.js diff --git a/test/js/node/test/parallel/test-child-process-prototype-tampering.mjs b/test/js/node/test/parallel/test-child-process-prototype-tampering.mjs deleted file mode 100644 index d94c4bdbc6..0000000000 --- a/test/js/node/test/parallel/test-child-process-prototype-tampering.mjs +++ /dev/null @@ -1,91 +0,0 @@ -import * as common from '../common/index.mjs'; -import * as fixtures from '../common/fixtures.mjs'; -import { EOL } from 'node:os'; -import { strictEqual, notStrictEqual, throws } from 'node:assert'; -import cp from 'node:child_process'; - -// TODO(LiviaMedeiros): test on different platforms -if (!common.isLinux) - common.skip(); - -const expectedCWD = process.cwd(); -const expectedUID = process.getuid(); - -for (const tamperedCwd of ['', '/tmp', '/not/existing/malicious/path', 42n]) { - Object.prototype.cwd = tamperedCwd; - - cp.exec('pwd', common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedCWD}${EOL}`); - })); - strictEqual(`${cp.execSync('pwd')}`, `${expectedCWD}${EOL}`); - cp.execFile('pwd', common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedCWD}${EOL}`); - })); - strictEqual(`${cp.execFileSync('pwd')}`, `${expectedCWD}${EOL}`); - cp.spawn('pwd').stdout.on('data', common.mustCall((out) => { - strictEqual(`${out}`, `${expectedCWD}${EOL}`); - })); - strictEqual(`${cp.spawnSync('pwd').stdout}`, `${expectedCWD}${EOL}`); - - delete Object.prototype.cwd; -} - -for (const tamperedUID of [0, 1, 999, 1000, 0n, 'gwak']) { - Object.prototype.uid = tamperedUID; - - cp.exec('id -u', common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedUID}${EOL}`); - })); - strictEqual(`${cp.execSync('id -u')}`, `${expectedUID}${EOL}`); - cp.execFile('id', ['-u'], common.mustSucceed((out) => { - strictEqual(`${out}`, `${expectedUID}${EOL}`); - })); - strictEqual(`${cp.execFileSync('id', ['-u'])}`, `${expectedUID}${EOL}`); - cp.spawn('id', ['-u']).stdout.on('data', common.mustCall((out) => { - strictEqual(`${out}`, `${expectedUID}${EOL}`); - })); - strictEqual(`${cp.spawnSync('id', ['-u']).stdout}`, `${expectedUID}${EOL}`); - - delete Object.prototype.uid; -} - -{ - Object.prototype.execPath = '/not/existing/malicious/path'; - - // Does not throw ENOENT - cp.fork(fixtures.path('empty.js')); - - delete Object.prototype.execPath; -} - -for (const shellCommandArgument of ['-L && echo "tampered"']) { - Object.prototype.shell = true; - const cmd = 'pwd'; - let cmdExitCode = ''; - - const program = cp.spawn(cmd, [shellCommandArgument], { cwd: expectedCWD }); - program.stderr.on('data', common.mustCall()); - program.stdout.on('data', common.mustNotCall()); - - program.on('exit', common.mustCall((code) => { - notStrictEqual(code, 0); - })); - - cp.execFile(cmd, [shellCommandArgument], { cwd: expectedCWD }, - common.mustCall((err) => { - notStrictEqual(err.code, 0); - }) - ); - - throws(() => { - cp.execFileSync(cmd, [shellCommandArgument], { cwd: expectedCWD }); - }, (e) => { - notStrictEqual(e.status, 0); - return true; - }); - - cmdExitCode = cp.spawnSync(cmd, [shellCommandArgument], { cwd: expectedCWD }).status; - notStrictEqual(cmdExitCode, 0); - - delete Object.prototype.shell; -} diff --git a/test/js/node/test/parallel/test-cluster-worker-kill-signal.js b/test/js/node/test/parallel/test-cluster-worker-kill-signal.js deleted file mode 100644 index 53e3739eba..0000000000 --- a/test/js/node/test/parallel/test-cluster-worker-kill-signal.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; -// test-cluster-worker-kill-signal.js -// verifies that when we're killing a worker using Worker.prototype.kill -// and the worker's process was killed with the given signal (SIGKILL) - - -const common = require('../common'); -const assert = require('assert'); -const cluster = require('cluster'); - -if (cluster.isWorker) { - // Make the worker run something - const http = require('http'); - const server = http.Server(() => { }); - - server.once('listening', common.mustCall()); - server.listen(0, '127.0.0.1'); - -} else if (cluster.isMaster) { - const KILL_SIGNAL = 'SIGKILL'; - - // Start worker - const worker = cluster.fork(); - - // When the worker is up and running, kill it - worker.once('listening', common.mustCall(() => { - worker.kill(KILL_SIGNAL); - })); - - // Check worker events and properties - worker.on('disconnect', common.mustCall(() => { - assert.strictEqual(worker.exitedAfterDisconnect, false); - assert.strictEqual(worker.state, 'disconnected'); - }, 1)); - - // Check that the worker died - worker.once('exit', common.mustCall((exitCode, signalCode) => { - const isWorkerProcessStillAlive = common.isAlive(worker.process.pid); - const numOfRunningWorkers = Object.keys(cluster.workers).length; - - assert.strictEqual(exitCode, null); - assert.strictEqual(signalCode, KILL_SIGNAL); - assert.strictEqual(isWorkerProcessStillAlive, false); - assert.strictEqual(numOfRunningWorkers, 0); - }, 1)); - - // Check if the cluster was killed as well - cluster.on('exit', common.mustCall(1)); -}