2018-08-06 21:40:30 +00:00
|
|
|
// Flags: --expose-internals
|
2017-01-17 01:37:14 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2018-08-23 13:28:41 +00:00
|
|
|
const { internalBinding } = require('internal/test/binding');
|
|
|
|
const cares = internalBinding('cares_wrap');
|
2017-01-17 01:37:14 +00:00
|
|
|
const dns = require('dns');
|
2018-06-11 18:56:33 +00:00
|
|
|
const dnsPromises = dns.promises;
|
|
|
|
|
2017-01-17 01:37:14 +00:00
|
|
|
// Stub `getaddrinfo` to *always* error.
|
2018-08-06 21:40:30 +00:00
|
|
|
cares.getaddrinfo = () => internalBinding('uv').UV_ENOENT;
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-06-11 18:56:33 +00:00
|
|
|
{
|
|
|
|
const err = {
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: /^The "hostname" argument must be one of type string or falsy/
|
|
|
|
};
|
|
|
|
|
|
|
|
common.expectsError(() => dns.lookup(1, {}), err);
|
|
|
|
common.expectsError(() => dnsPromises.lookup(1, {}), err);
|
|
|
|
}
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2017-12-06 14:32:42 +00:00
|
|
|
common.expectsError(() => {
|
2017-01-17 01:37:14 +00:00
|
|
|
dns.lookup(false, 'cb');
|
2017-12-06 14:32:42 +00:00
|
|
|
}, {
|
2017-07-12 23:58:59 +00:00
|
|
|
code: 'ERR_INVALID_CALLBACK',
|
|
|
|
type: TypeError
|
2017-12-06 14:32:42 +00:00
|
|
|
});
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2017-12-06 14:32:42 +00:00
|
|
|
common.expectsError(() => {
|
2017-01-17 01:37:14 +00:00
|
|
|
dns.lookup(false, 'options', 'cb');
|
2017-12-06 14:32:42 +00:00
|
|
|
}, {
|
2017-07-12 23:58:59 +00:00
|
|
|
code: 'ERR_INVALID_CALLBACK',
|
|
|
|
type: TypeError
|
2017-12-06 14:32:42 +00:00
|
|
|
});
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-06-11 18:56:33 +00:00
|
|
|
{
|
|
|
|
const err = {
|
|
|
|
code: 'ERR_INVALID_OPT_VALUE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'The value "100" is invalid for option "hints"'
|
|
|
|
};
|
|
|
|
const options = {
|
2017-01-17 01:37:14 +00:00
|
|
|
hints: 100,
|
|
|
|
family: 0,
|
|
|
|
all: false
|
2018-06-11 18:56:33 +00:00
|
|
|
};
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-06-11 18:56:33 +00:00
|
|
|
common.expectsError(() => { dnsPromises.lookup(false, options); }, err);
|
|
|
|
common.expectsError(() => {
|
|
|
|
dns.lookup(false, options, common.mustNotCall());
|
|
|
|
}, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const err = {
|
|
|
|
code: 'ERR_INVALID_OPT_VALUE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'The value "20" is invalid for option "family"'
|
|
|
|
};
|
|
|
|
const options = {
|
2017-01-17 01:37:14 +00:00
|
|
|
hints: 0,
|
|
|
|
family: 20,
|
|
|
|
all: false
|
2018-06-11 18:56:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
common.expectsError(() => { dnsPromises.lookup(false, options); }, err);
|
|
|
|
common.expectsError(() => {
|
|
|
|
dns.lookup(false, options, common.mustNotCall());
|
|
|
|
}, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
(async function() {
|
|
|
|
let res;
|
|
|
|
|
|
|
|
res = await dnsPromises.lookup(false, {
|
|
|
|
hints: 0,
|
|
|
|
family: 0,
|
|
|
|
all: true
|
|
|
|
});
|
|
|
|
assert.deepStrictEqual(res, []);
|
|
|
|
|
|
|
|
res = await dnsPromises.lookup('127.0.0.1', {
|
|
|
|
hints: 0,
|
|
|
|
family: 4,
|
|
|
|
all: true
|
|
|
|
});
|
|
|
|
assert.deepStrictEqual(res, [{ address: '127.0.0.1', family: 4 }]);
|
|
|
|
|
|
|
|
res = await dnsPromises.lookup('127.0.0.1', {
|
|
|
|
hints: 0,
|
|
|
|
family: 4,
|
|
|
|
all: false
|
|
|
|
});
|
|
|
|
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
|
|
|
|
})();
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-02-09 01:32:04 +00:00
|
|
|
dns.lookup(false, {
|
|
|
|
hints: 0,
|
|
|
|
family: 0,
|
|
|
|
all: true
|
|
|
|
}, common.mustCall((error, result, addressType) => {
|
|
|
|
assert.ifError(error);
|
|
|
|
assert.deepStrictEqual(result, []);
|
|
|
|
assert.strictEqual(addressType, undefined);
|
|
|
|
}));
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-02-09 01:32:04 +00:00
|
|
|
dns.lookup('127.0.0.1', {
|
|
|
|
hints: 0,
|
|
|
|
family: 4,
|
|
|
|
all: true
|
|
|
|
}, common.mustCall((error, result, addressType) => {
|
|
|
|
assert.ifError(error);
|
|
|
|
assert.deepStrictEqual(result, [{
|
|
|
|
address: '127.0.0.1',
|
|
|
|
family: 4
|
|
|
|
}]);
|
|
|
|
assert.strictEqual(addressType, undefined);
|
|
|
|
}));
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-02-09 01:32:04 +00:00
|
|
|
dns.lookup('127.0.0.1', {
|
|
|
|
hints: 0,
|
|
|
|
family: 4,
|
|
|
|
all: false
|
|
|
|
}, common.mustCall((error, result, addressType) => {
|
|
|
|
assert.ifError(error);
|
|
|
|
assert.deepStrictEqual(result, '127.0.0.1');
|
|
|
|
assert.strictEqual(addressType, 4);
|
|
|
|
}));
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-02-09 01:32:04 +00:00
|
|
|
let tickValue = 0;
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-02-09 01:32:04 +00:00
|
|
|
dns.lookup('example.com', common.mustCall((error, result, addressType) => {
|
|
|
|
assert(error);
|
|
|
|
assert.strictEqual(tickValue, 1);
|
|
|
|
assert.strictEqual(error.code, 'ENOENT');
|
2018-04-01 05:38:47 +00:00
|
|
|
const descriptor = Object.getOwnPropertyDescriptor(error, 'message');
|
2018-09-13 20:40:11 +00:00
|
|
|
// The error message should be non-enumerable.
|
|
|
|
assert.strictEqual(descriptor.enumerable, false);
|
2018-02-09 01:32:04 +00:00
|
|
|
}));
|
2017-01-17 01:37:14 +00:00
|
|
|
|
2018-02-09 01:32:04 +00:00
|
|
|
// Make sure that the error callback is called
|
|
|
|
// on next tick.
|
|
|
|
tickValue = 1;
|