Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions test/parallel/test-cluster-bind-privileged-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@

'use strict';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');

const { execSync } = require('child_process');
const sysctlOutput = execSync('sysctl net.ipv4.ip_unprivileged_port_start').toString();
Comment thread
7suyash7 marked this conversation as resolved.
Outdated
const unprivilegedPortStart = parseInt(sysctlOutput.split(' ')[1], 10);
Comment thread
7suyash7 marked this conversation as resolved.
Outdated

if (common.isLinux) {
if (unprivilegedPortStart === 42) {
Comment thread
7suyash7 marked this conversation as resolved.
Outdated
common.skip('42 is unprivileged');
Comment thread
7suyash7 marked this conversation as resolved.
Outdated
}
}

// Skip on OS X Mojave. https://github.com/nodejs/node/issues/21679
if (common.isOSX)
Expand All @@ -35,19 +48,17 @@ if (common.isWindows)
if (process.getuid() === 0)
common.skip('Test is not supposed to be run as root.');

const assert = require('assert');
Comment thread
7suyash7 marked this conversation as resolved.
const cluster = require('cluster');
const net = require('net');

if (cluster.isPrimary) {
Comment thread
7suyash7 marked this conversation as resolved.
cluster.fork().on('exit', common.mustCall((exitCode) => {
assert.strictEqual(exitCode, 0);
}));
cluster.fork().on('exit', (exitCode) => {
assert.strictEqual(exitCode, 1);
});
} else {
const s = net.createServer(common.mustNotCall());
s.listen(42, common.mustNotCall('listen should have failed'));
s.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'EACCES');
process.disconnect();
}));
s.listen(unprivilegedPortStart, (err) => {
if (err && err.code === 'EACCES') {
process.disconnect();
} else {
process.exit(0);
}
});
}