From 526eed0ed3250297bf8db4217a8d47f371a409d8 Mon Sep 17 00:00:00 2001 From: Kevin Lentin Date: Tue, 7 Feb 2023 18:12:39 +1100 Subject: [PATCH] test: assume priv ports start at 1024 if it can't be changed 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: https://github.com/nodejs/node/issues/45838 --- test/parallel/test-cluster-bind-privileged-port.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-cluster-bind-privileged-port.js b/test/parallel/test-cluster-bind-privileged-port.js index 11a8aa66593..a67b1658bba 100644 --- a/test/parallel/test-cluster-bind-privileged-port.js +++ b/test/parallel/test-cluster-bind-privileged-port.js @@ -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'); + } } }