-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #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>
- Loading branch information
1 parent
a634554
commit e9b6fbb
Showing
2 changed files
with
42 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |