From 896027c00620101db39c55b8eef5e213dec792ee Mon Sep 17 00:00:00 2001 From: Suyash Nayan <89125422+7suyash7@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:40:48 +0530 Subject: [PATCH] test: add fix so that test exits if port 42 is unprivileged PR-URL: https://github.com/nodejs/node/pull/45904 Fixes: https://github.com/nodejs/node/issues/45838 Reviewed-By: Ben Noordhuis Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca --- .../test-cluster-bind-privileged-port.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-cluster-bind-privileged-port.js b/test/parallel/test-cluster-bind-privileged-port.js index b952ac1c6ce5d3..1249230177d2ec 100644 --- a/test/parallel/test-cluster-bind-privileged-port.js +++ b/test/parallel/test-cluster-bind-privileged-port.js @@ -21,6 +21,18 @@ 'use strict'; const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); +const { execSync } = require('child_process'); + +if (common.isLinux) { + const sysctlOutput = execSync('sysctl net.ipv4.ip_unprivileged_port_start').toString(); + const unprivilegedPortStart = parseInt(sysctlOutput.split(' ')[2], 10); + if (unprivilegedPortStart <= 42) { + common.skip('Port 42 is unprivileged'); + } +} // Skip on OS X Mojave. https://github.com/nodejs/node/issues/21679 if (common.isOSX) @@ -35,10 +47,6 @@ if (common.isWindows) if (process.getuid() === 0) common.skip('Test is not supposed to be run as root.'); -const assert = require('assert'); -const cluster = require('cluster'); -const net = require('net'); - if (cluster.isPrimary) { cluster.fork().on('exit', common.mustCall((exitCode) => { assert.strictEqual(exitCode, 0);