Skip to content

Commit 896027c

Browse files
7suyash7juanarbol
authored andcommitted
test: add fix so that test exits if port 42 is unprivileged
PR-URL: #45904 Fixes: #45838 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a9db45e commit 896027c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

test/parallel/test-cluster-bind-privileged-port.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121

2222
'use strict';
2323
const common = require('../common');
24+
const assert = require('assert');
25+
const cluster = require('cluster');
26+
const net = require('net');
27+
const { execSync } = require('child_process');
28+
29+
if (common.isLinux) {
30+
const sysctlOutput = execSync('sysctl net.ipv4.ip_unprivileged_port_start').toString();
31+
const unprivilegedPortStart = parseInt(sysctlOutput.split(' ')[2], 10);
32+
if (unprivilegedPortStart <= 42) {
33+
common.skip('Port 42 is unprivileged');
34+
}
35+
}
2436

2537
// Skip on OS X Mojave. https://github.com/nodejs/node/issues/21679
2638
if (common.isOSX)
@@ -35,10 +47,6 @@ if (common.isWindows)
3547
if (process.getuid() === 0)
3648
common.skip('Test is not supposed to be run as root.');
3749

38-
const assert = require('assert');
39-
const cluster = require('cluster');
40-
const net = require('net');
41-
4250
if (cluster.isPrimary) {
4351
cluster.fork().on('exit', common.mustCall((exitCode) => {
4452
assert.strictEqual(exitCode, 0);

0 commit comments

Comments
 (0)