-
Notifications
You must be signed in to change notification settings - Fork 28.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 <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
- 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 | ||
); | ||
}); | ||
} |