diff options
author | James M Snell <jasnell@gmail.com> | 2016-03-15 20:46:53 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-03-21 12:08:57 -0700 |
commit | d0edabecbf072dded07f85897691b0ff1b0bb99b (patch) | |
tree | 94bd34ef0412869b2f0bc9191a59128f1bbf5063 /test | |
parent | 287bdabe407bcfae7a82f0189351ac0191d6e4d1 (diff) | |
download | android-node-v8-d0edabecbf072dded07f85897691b0ff1b0bb99b.tar.gz android-node-v8-d0edabecbf072dded07f85897691b0ff1b0bb99b.tar.bz2 android-node-v8-d0edabecbf072dded07f85897691b0ff1b0bb99b.zip |
net: strict checking for internal/net isLegalPort
Add stricter testing for the isLegalPort method in internal/net.
This ensures that odd inputs such as isLegalPort(true) and
isLegalPort([1]) aren't acceptable as valid port inputs.
PR-URL: https://github.com/nodejs/node/pull/5733
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-net-internal.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/test/parallel/test-net-internal.js b/test/parallel/test-net-internal.js index b59b92d0fb..0c8d1cf9e1 100644 --- a/test/parallel/test-net-internal.js +++ b/test/parallel/test-net-internal.js @@ -4,12 +4,17 @@ require('../common'); const assert = require('assert'); -const net = require('internal/net'); - -assert.strictEqual(net.isLegalPort(''), false); -assert.strictEqual(net.isLegalPort('0'), true); -assert.strictEqual(net.isLegalPort(0), true); -assert.strictEqual(net.isLegalPort(65536), false); -assert.strictEqual(net.isLegalPort('65535'), true); -assert.strictEqual(net.isLegalPort(undefined), false); -assert.strictEqual(net.isLegalPort(null), true); +const isLegalPort = require('internal/net').isLegalPort; + +for (var n = 0; n <= 0xFFFF; n++) { + assert(isLegalPort(n)); + assert(isLegalPort('' + n)); + assert(`0x${n.toString(16)}`); + assert(`0o${n.toString(8)}`); + assert(`0b${n.toString(2)}`); +} + +const bad = [-1, 'a', {}, [], false, true, 0xFFFF + 1, Infinity, + -Infinity, NaN, undefined, null, '', ' ', 1.1, '0x', + '-0x1', '-0o1', '-0b1', '0o', '0b']; +bad.forEach((i) => assert(!isLegalPort(i))); |