mirror of https://github.com/lukechilds/node.git
Browse Source
- 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>v7.x
Claudio Rodriguez
9 years ago
2 changed files with 42 additions and 6 deletions
@ -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(); |
|||
}); |
|||
}); |
Loading…
Reference in new issue