Skip to content

Commit

Permalink
test: add fix so that test exits if port 42 is unprivileged
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
7suyash7 authored and juanarbol committed Jan 31, 2023
1 parent a9db45e commit 896027c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/parallel/test-cluster-bind-privileged-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 896027c

Please sign in to comment.