-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dns: type check for dns.setServers argument.
Added type check for argument for dns.setServers and dnsPromises.setServers. PR-URL: #21944 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
- Loading branch information
Showing
2 changed files
with
96 additions
and
1 deletion.
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,87 @@ | ||
'use strict'; | ||
require('../common'); | ||
const { addresses } = require('../common/internet'); | ||
const assert = require('assert'); | ||
const dns = require('dns'); | ||
const resolver = new dns.promises.Resolver(); | ||
const dnsPromises = dns.promises; | ||
const promiseResolver = new dns.promises.Resolver(); | ||
|
||
{ | ||
[ | ||
null, | ||
undefined, | ||
Number(addresses.DNS4_SERVER), | ||
addresses.DNS4_SERVER, | ||
{ | ||
address: addresses.DNS4_SERVER | ||
} | ||
].forEach((val) => { | ||
const errObj = { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError [ERR_INVALID_ARG_TYPE]', | ||
message: 'The "servers" argument must be of type Array. Received type ' + | ||
typeof val | ||
}; | ||
assert.throws( | ||
() => { | ||
dns.setServers(val); | ||
}, errObj | ||
); | ||
assert.throws( | ||
() => { | ||
resolver.setServers(val); | ||
}, errObj | ||
); | ||
assert.throws( | ||
() => { | ||
dnsPromises.setServers(val); | ||
}, errObj | ||
); | ||
assert.throws( | ||
() => { | ||
promiseResolver.setServers(val); | ||
}, errObj | ||
); | ||
}); | ||
} | ||
|
||
{ | ||
[ | ||
[null], | ||
[undefined], | ||
[Number(addresses.DNS4_SERVER)], | ||
[ | ||
{ | ||
address: addresses.DNS4_SERVER | ||
} | ||
] | ||
].forEach((val) => { | ||
const errObj = { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError [ERR_INVALID_ARG_TYPE]', | ||
message: 'The "servers[0]" argument must be of type string. ' + | ||
`Received type ${typeof val[0]}` | ||
}; | ||
assert.throws( | ||
() => { | ||
dns.setServers(val); | ||
}, errObj | ||
); | ||
assert.throws( | ||
() => { | ||
resolver.setServers(val); | ||
}, errObj | ||
); | ||
assert.throws( | ||
() => { | ||
dnsPromises.setServers(val); | ||
}, errObj | ||
); | ||
assert.throws( | ||
() => { | ||
promiseResolver.setServers(val); | ||
}, errObj | ||
); | ||
}); | ||
} |