Skip to content

Commit c8cf0ce

Browse files
committed
test: check allowed port argument values
Existing test only covered ports pass as options, add tests for argument behaviour to avoid regressions. Ref: #14205
1 parent 40fb0da commit c8cf0ce

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/parallel/test-net-listen-port-option.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,33 @@ net.Server().listen({ port: '0' }, close);
2626
net.Server().listen({ port: port }, common.fail);
2727
}, /invalid listen argument/i);
2828
});
29+
30+
// Repeat the tests, passing port as an argument, which validates somewhat
31+
// differently.
32+
33+
net.Server().listen(undefined, close);
34+
net.Server().listen('0', close);
35+
36+
// 'nan', skip, treated as a path, not a port
37+
//'+Infinity', skip, treated as a path, not a port
38+
//'-Infinity' skip, treated as a path, not a port
39+
40+
// The numbers that are out of range are treated as 0
41+
net.Server().listen(-1, close);
42+
// Use a float larger than 1024, because EACCESS happens for low ports
43+
net.Server().listen(1234.56, close);
44+
net.Server().listen(0x10000, close);
45+
net.Server().listen(1 / 0, close);
46+
net.Server().listen(-1 / 0, close);
47+
48+
// null is treated as 0
49+
net.Server().listen(null, close);
50+
51+
// false/true are converted to 0/1, arguably a bug, but fixing would be
52+
// semver-major. Note that true fails because ports that low can't be listened
53+
// on by unprivileged processes.
54+
net.Server().listen(false, close);
55+
56+
net.Server().listen(true).on('error', common.mustCall(function(err) {
57+
assert.strictEqual(err.code, 'EACCES');
58+
}));

0 commit comments

Comments
 (0)