Skip to content

Commit

Permalink
test: assume priv ports start at 1024 if it can't be changed
Browse files Browse the repository at this point in the history
An update to test/parallel/test-cluster-bind-privileged-port.js
checks the lowest privileged port to ensure 42 is privileged
This only works on kernels > 4.1. On older kernels, this is
locked at 1024 so the check is not needed.

Fixes: nodejs/node#45838
  • Loading branch information
Kevin Lentin committed Feb 7, 2023
1 parent 8e6e215 commit 526eed0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/parallel/test-cluster-bind-privileged-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
const { readFileSync } = require('fs');
const { readFileSync, statSync } = require('fs');

if (common.isLinux) {
const unprivilegedPortStart = parseInt(readFileSync('/proc/sys/net/ipv4/ip_unprivileged_port_start'));
if (unprivilegedPortStart <= 42) {
common.skip('Port 42 is unprivileged');
const procFileName = '/proc/sys/net/ipv4/ip_unprivileged_port_start';
// Does not exist for Kernel < 4.1 where answer is 1024. So only test limit if limit exists
if (statSync(procFileName, { throwIfNoEntry: false })) {
const unprivilegedPortStart = parseInt(readFileSync(procFileName));
if (unprivilegedPortStart <= 42) {
common.skip('Port 42 is unprivileged');
}
}
}

Expand Down

0 comments on commit 526eed0

Please sign in to comment.