diff options
author | Claudio Rodriguez <cjrodr@yahoo.com> | 2016-08-08 10:32:50 +0100 |
---|---|---|
committer | Claudio Rodriguez <cjrodr@yahoo.com> | 2016-09-08 22:21:31 +0100 |
commit | e9b6fbbf170d4ef0031d3194d4c0148269037030 (patch) | |
tree | 9278ec7243607b242a0ae99c1efa8eada60e1dba /test/parallel/test-dgram-createSocket-type.js | |
parent | a634554fca562e82d326967b809325f8ee5d3acd (diff) | |
download | android-node-v8-e9b6fbbf170d4ef0031d3194d4c0148269037030.tar.gz android-node-v8-e9b6fbbf170d4ef0031d3194d4c0148269037030.tar.bz2 android-node-v8-e9b6fbbf170d4ef0031d3194d4c0148269037030.zip |
dgram: prefer strict equality, type validation
- Enforces strict comparisons in dgram - bindState should
always be strictly equal to one of the defined constant states,
and newHandle type is a string.
- Check that the argument `type` in createSocket is not null
when it is of type 'object', before using its `type` property.
- Adds a test to check dgram.createSocket is properly
validating its `type` argument.
PR-URL: https://github.com/nodejs/node/pull/8011
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
Reviewed-By: Jackson Tian <shvyo1987@gmail.com>
Diffstat (limited to 'test/parallel/test-dgram-createSocket-type.js')
-rw-r--r-- | test/parallel/test-dgram-createSocket-type.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/parallel/test-dgram-createSocket-type.js b/test/parallel/test-dgram-createSocket-type.js new file mode 100644 index 0000000000..1d269ddeda --- /dev/null +++ b/test/parallel/test-dgram-createSocket-type.js @@ -0,0 +1,36 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const dgram = require('dgram'); +const invalidTypes = [ + 'test', + ['udp4'], + new String('udp4'), + 1, + {}, + true, + false, + null, + undefined +]; +const validTypes = [ + 'udp4', + 'udp6', + { type: 'udp4' }, + { type: 'udp6' } +]; + +// Error must be thrown with invalid types +invalidTypes.forEach((invalidType) => { + assert.throws(() => { + dgram.createSocket(invalidType); + }, /Bad socket type specified/); +}); + +// Error must not be thrown with valid types +validTypes.forEach((validType) => { + assert.doesNotThrow(() => { + const socket = dgram.createSocket(validType); + socket.close(); + }); +}); |