Skip to content

Commit

Permalink
test: add check to exit if port 42 is unprivileged
Browse files Browse the repository at this point in the history
  • Loading branch information
7suyash7 committed Dec 16, 2022
1 parent 0c93fd7 commit 11d4d4a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions test/parallel/test-cluster-bind-privileged-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ const cluster = require('cluster');
const net = require('net');

if (cluster.isPrimary) {
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(42, (err) => {
if (err && err.code === 'EACCES') {
// Port is unprivileged, exit successfully
process.disconnect();
} else {
// Port is privileged, or an unexpected error occurred
process.exit(0);
}
});
}

0 comments on commit 11d4d4a

Please sign in to comment.