2017-01-03 21:16:48 +00:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2016-09-17 08:22:42 +00:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2010-04-07 22:37:08 +00:00
|
|
|
|
2016-09-17 08:22:42 +00:00
|
|
|
const dns = require('dns');
|
2018-06-11 18:56:33 +00:00
|
|
|
const dnsPromises = dns.promises;
|
|
|
|
|
|
|
|
(async function() {
|
|
|
|
let res;
|
|
|
|
|
|
|
|
res = await dnsPromises.lookup(null);
|
|
|
|
assert.strictEqual(res.address, null);
|
|
|
|
assert.strictEqual(res.family, 4);
|
|
|
|
|
|
|
|
res = await dnsPromises.lookup('127.0.0.1');
|
|
|
|
assert.strictEqual(res.address, '127.0.0.1');
|
|
|
|
assert.strictEqual(res.family, 4);
|
2010-04-07 22:37:08 +00:00
|
|
|
|
2018-06-11 18:56:33 +00:00
|
|
|
res = await dnsPromises.lookup('::1');
|
|
|
|
assert.strictEqual(res.address, '::1');
|
|
|
|
assert.strictEqual(res.family, 6);
|
|
|
|
})();
|
2010-04-07 22:37:08 +00:00
|
|
|
|
|
|
|
// Try resolution without callback
|
|
|
|
|
2016-09-09 17:34:55 +00:00
|
|
|
dns.lookup(null, common.mustCall((error, result, addressType) => {
|
|
|
|
assert.ifError(error);
|
2016-09-17 08:22:42 +00:00
|
|
|
assert.strictEqual(null, result);
|
|
|
|
assert.strictEqual(4, addressType);
|
|
|
|
}));
|
2010-04-07 22:37:08 +00:00
|
|
|
|
2016-09-09 17:34:55 +00:00
|
|
|
dns.lookup('127.0.0.1', common.mustCall((error, result, addressType) => {
|
|
|
|
assert.ifError(error);
|
2016-09-17 08:22:42 +00:00
|
|
|
assert.strictEqual('127.0.0.1', result);
|
|
|
|
assert.strictEqual(4, addressType);
|
|
|
|
}));
|
2010-04-07 23:04:33 +00:00
|
|
|
|
2016-09-09 17:34:55 +00:00
|
|
|
dns.lookup('::1', common.mustCall((error, result, addressType) => {
|
|
|
|
assert.ifError(error);
|
2016-09-17 08:22:42 +00:00
|
|
|
assert.strictEqual('::1', result);
|
|
|
|
assert.strictEqual(6, addressType);
|
|
|
|
}));
|
2010-04-07 23:04:33 +00:00
|
|
|
|
2017-07-12 23:58:59 +00:00
|
|
|
[
|
|
|
|
// Try calling resolve with an unsupported type.
|
|
|
|
'HI',
|
|
|
|
// Try calling resolve with an unsupported type that's an object key
|
|
|
|
'toString'
|
|
|
|
].forEach((val) => {
|
2018-06-11 18:56:33 +00:00
|
|
|
const err = {
|
|
|
|
code: 'ERR_INVALID_OPT_VALUE',
|
|
|
|
type: TypeError,
|
|
|
|
message: `The value "${val}" is invalid for option "rrtype"`
|
|
|
|
};
|
|
|
|
|
2017-07-12 23:58:59 +00:00
|
|
|
common.expectsError(
|
|
|
|
() => dns.resolve('www.google.com', val),
|
2018-06-11 18:56:33 +00:00
|
|
|
err
|
2017-07-12 23:58:59 +00:00
|
|
|
);
|
2018-06-11 18:56:33 +00:00
|
|
|
|
|
|
|
common.expectsError(() => dnsPromises.resolve('www.google.com', val), err);
|
2017-07-12 23:58:59 +00:00
|
|
|
});
|
2016-03-22 13:40:36 +00:00
|
|
|
|
2011-10-18 23:12:07 +00:00
|
|
|
// Windows doesn't usually have an entry for localhost 127.0.0.1 in
|
|
|
|
// C:\Windows\System32\drivers\etc\hosts
|
|
|
|
// so we disable this test on Windows.
|
2015-07-29 11:48:04 +00:00
|
|
|
if (!common.isWindows) {
|
2016-09-17 08:22:42 +00:00
|
|
|
dns.reverse('127.0.0.1', common.mustCall(function(error, domains) {
|
|
|
|
assert.ifError(error);
|
2011-10-18 23:12:07 +00:00
|
|
|
assert.ok(Array.isArray(domains));
|
2016-09-17 08:22:42 +00:00
|
|
|
}));
|
2018-06-11 18:56:33 +00:00
|
|
|
|
|
|
|
(async function() {
|
|
|
|
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
|
|
|
|
})();
|
2011-10-18 23:12:07 +00:00
|
|
|
}
|