Skip to content

Commit

Permalink
test: check allowed port argument values
Browse files Browse the repository at this point in the history
Existing test only covered ports pass as options, add tests for
argument behaviour to avoid regressions.

Ref: #14205
  • Loading branch information
sam-github committed Jul 17, 2017
1 parent 40fb0da commit c8cf0ce
Showing 1 changed file with 30 additions and 0 deletions.
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');
}));

0 comments on commit c8cf0ce

Please sign in to comment.