Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: check allowed port argument values #14232

Closed
Closed
Changes from all 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
30 changes: 30 additions & 0 deletions test/parallel/test-net-listen-port-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,33 @@ net.Server().listen({ port: '0' }, close);
net.Server().listen({ port: port }, common.fail);
}, /invalid listen argument/i);
});

// Repeat the tests, passing port as an argument, which validates somewhat
// differently.

net.Server().listen(undefined, close);
net.Server().listen('0', close);

// 'nan', skip, treated as a path, not a port
//'+Infinity', skip, treated as a path, not a port
//'-Infinity' skip, treated as a path, not a port

// The numbers that are out of range are treated as 0
net.Server().listen(-1, close);
// Use a float larger than 1024, because EACCESS happens for low ports
net.Server().listen(1234.56, close);
net.Server().listen(0x10000, close);
net.Server().listen(1 / 0, close);
net.Server().listen(-1 / 0, close);

// null is treated as 0
net.Server().listen(null, close);

// false/true are converted to 0/1, arguably a bug, but fixing would be
// semver-major. Note that true fails because ports that low can't be listened
// on by unprivileged processes.
net.Server().listen(false, close);

net.Server().listen(true).on('error', common.mustCall(function(err) {
assert.strictEqual(err.code, 'EACCES');
}));