2017-01-03 22:16:48 +01: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 13:00:06 +02:00
|
|
|
'use strict';
|
2017-01-19 17:18:51 +01:00
|
|
|
const common = require('../common');
|
2016-01-13 21:42:45 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const dns = require('dns');
|
|
|
|
const net = require('net');
|
|
|
|
const isIPv4 = net.isIPv4;
|
|
|
|
const isIPv6 = net.isIPv6;
|
|
|
|
const util = require('util');
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
let expected = 0;
|
|
|
|
let completed = 0;
|
|
|
|
let running = false;
|
|
|
|
const queue = [];
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
function TEST(f) {
|
|
|
|
function next() {
|
2017-01-08 14:19:00 +01:00
|
|
|
const f = queue.shift();
|
2011-07-05 00:17:20 +02:00
|
|
|
if (f) {
|
|
|
|
running = true;
|
|
|
|
console.log(f.name);
|
|
|
|
f(done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function done() {
|
|
|
|
running = false;
|
|
|
|
completed++;
|
|
|
|
process.nextTick(next);
|
|
|
|
}
|
|
|
|
|
|
|
|
expected++;
|
|
|
|
queue.push(f);
|
|
|
|
|
|
|
|
if (!running) {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
function checkWrap(req) {
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof req, 'object');
|
2011-07-05 21:16:13 +02:00
|
|
|
}
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
TEST(function test_reverse_bogus(done) {
|
2017-01-19 17:18:51 +01:00
|
|
|
assert.throws(() => {
|
2017-02-03 20:54:19 +01:00
|
|
|
dns.reverse('bogus ip', common.mustNotCall());
|
2017-01-19 17:18:51 +01:00
|
|
|
}, /^Error: getHostByAddr EINVAL$/);
|
2011-07-05 00:17:20 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2016-10-26 07:51:34 +02:00
|
|
|
TEST(function test_resolve4_ttl(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolve4('google.com', { ttl: true }, function(err, result) {
|
2016-10-26 07:51:34 +02:00
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
const item = result[i];
|
2016-10-26 07:51:34 +02:00
|
|
|
assert.ok(item);
|
|
|
|
assert.strictEqual(typeof item, 'object');
|
|
|
|
assert.strictEqual(typeof item.ttl, 'number');
|
|
|
|
assert.strictEqual(typeof item.address, 'string');
|
|
|
|
assert.ok(item.ttl > 0);
|
|
|
|
assert.ok(isIPv4(item.address));
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2016-10-26 07:54:20 +02:00
|
|
|
TEST(function test_resolve6_ttl(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolve6('google.com', { ttl: true }, function(err, result) {
|
2016-10-26 07:54:20 +02:00
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
const item = result[i];
|
2016-10-26 07:54:20 +02:00
|
|
|
assert.ok(item);
|
|
|
|
assert.strictEqual(typeof item, 'object');
|
|
|
|
assert.strictEqual(typeof item.ttl, 'number');
|
|
|
|
assert.strictEqual(typeof item.address, 'string');
|
|
|
|
assert.ok(item.ttl > 0);
|
|
|
|
assert.ok(isIPv6(item.address));
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
TEST(function test_resolveMx(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveMx('gmail.com', function(err, result) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
const item = result[i];
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(item);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item, 'object');
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
assert.ok(item.exchange);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item.exchange, 'string');
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item.priority, 'number');
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
2016-02-08 10:54:02 +01:00
|
|
|
TEST(function test_resolveMx_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveMx('something.invalid', function(err, result) {
|
2016-02-08 10:54:02 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:54:02 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
TEST(function test_resolveNs(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveNs('rackspace.com', function(err, names) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(names.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < names.length; i++) {
|
|
|
|
const name = names[i];
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(name);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof name, 'string');
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
2016-02-08 10:54:02 +01:00
|
|
|
TEST(function test_resolveNs_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveNs('something.invalid', function(err, result) {
|
2016-02-08 10:54:02 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:54:02 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
TEST(function test_resolveSrv(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
const item = result[i];
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(item);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item, 'object');
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
assert.ok(item.name);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item.name, 'string');
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item.port, 'number');
|
|
|
|
assert.strictEqual(typeof item.priority, 'number');
|
|
|
|
assert.strictEqual(typeof item.weight, 'number');
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
2016-02-08 10:54:02 +01:00
|
|
|
TEST(function test_resolveSrv_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveSrv('something.invalid', function(err, result) {
|
2016-02-08 10:54:02 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:54:02 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2016-02-08 10:57:24 +01:00
|
|
|
TEST(function test_resolvePtr(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolvePtr('8.8.8.8.in-addr.arpa', function(err, result) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2016-02-08 10:57:24 +01:00
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
const item = result[i];
|
2016-02-08 10:57:24 +01:00
|
|
|
assert.ok(item);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item, 'string');
|
2016-02-08 10:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST(function test_resolvePtr_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolvePtr('something.invalid', function(err, result) {
|
2016-02-08 10:57:24 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:57:24 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2012-09-18 11:21:38 +02:00
|
|
|
TEST(function test_resolveNaptr(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveNaptr('sip2sip.info', function(err, result) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2012-09-18 11:21:38 +02:00
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
const item = result[i];
|
2012-09-18 11:21:38 +02:00
|
|
|
assert.ok(item);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof item, 'object');
|
|
|
|
|
|
|
|
assert.strictEqual(typeof item.flags, 'string');
|
|
|
|
assert.strictEqual(typeof item.service, 'string');
|
|
|
|
assert.strictEqual(typeof item.regexp, 'string');
|
|
|
|
assert.strictEqual(typeof item.replacement, 'string');
|
|
|
|
assert.strictEqual(typeof item.order, 'number');
|
|
|
|
assert.strictEqual(typeof item.preference, 'number');
|
2012-09-18 11:21:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2016-02-08 10:54:02 +01:00
|
|
|
TEST(function test_resolveNaptr_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveNaptr('something.invalid', function(err, result) {
|
2016-02-08 10:54:02 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:54:02 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
TEST(function test_resolveSoa(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveSoa('nodejs.org', function(err, result) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(result);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result, 'object');
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result.nsname, 'string');
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(result.nsname.length > 0);
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result.hostmaster, 'string');
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(result.hostmaster.length > 0);
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result.serial, 'number');
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok((result.serial > 0) && (result.serial < 4294967295));
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result.refresh, 'number');
|
2015-02-06 21:43:50 +01:00
|
|
|
assert.ok((result.refresh > 0) && (result.refresh < 2147483647));
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result.retry, 'number');
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok((result.retry > 0) && (result.retry < 2147483647));
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result.expire, 'number');
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok((result.expire > 0) && (result.expire < 2147483647));
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof result.minttl, 'number');
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok((result.minttl >= 0) && (result.minttl < 2147483647));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2016-02-08 10:54:02 +01:00
|
|
|
TEST(function test_resolveSoa_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveSoa('something.invalid', function(err, result) {
|
2016-02-08 10:54:02 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:54:02 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
TEST(function test_resolveCname(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveCname('www.microsoft.com', function(err, names) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(names.length > 0);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < names.length; i++) {
|
|
|
|
const name = names[i];
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(name);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof name, 'string');
|
2011-07-05 00:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
2016-02-08 10:54:02 +01:00
|
|
|
TEST(function test_resolveCname_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveCname('something.invalid', function(err, result) {
|
2016-02-08 10:54:02 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:54:02 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2011-10-03 16:50:09 +02:00
|
|
|
TEST(function test_resolveTxt(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveTxt('google.com', function(err, records) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(records.length, 1);
|
2014-04-30 18:14:55 +02:00
|
|
|
assert.ok(util.isArray(records[0]));
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(records[0][0].indexOf('v=spf1'), 0);
|
2011-10-03 16:50:09 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2016-02-08 10:54:02 +01:00
|
|
|
TEST(function test_resolveTxt_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolveTxt('something.invalid', function(err, result) {
|
2016-02-08 10:54:02 +01:00
|
|
|
assert.ok(err instanceof Error);
|
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
|
|
|
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(result, undefined);
|
2016-02-08 10:54:02 +01:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
2011-10-03 16:50:09 +02:00
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
TEST(function test_lookup_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(err instanceof Error);
|
2011-10-05 00:08:18 +02:00
|
|
|
assert.strictEqual(err.errno, dns.NOTFOUND);
|
2011-10-11 23:46:55 +02:00
|
|
|
assert.strictEqual(err.errno, 'ENOTFOUND');
|
2013-01-18 01:40:48 +01:00
|
|
|
assert.ok(!/ENOENT/.test(err.message));
|
2014-08-06 16:53:59 +02:00
|
|
|
assert.ok(/does\.not\.exist/.test(err.message));
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_lookup_null(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.lookup(null, function(err, ip, family) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.strictEqual(ip, null);
|
|
|
|
assert.strictEqual(family, 4);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-02-06 21:43:50 +01:00
|
|
|
TEST(function test_lookup_ip_all(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2015-02-06 21:43:50 +01:00
|
|
|
assert.ok(Array.isArray(ips));
|
|
|
|
assert.ok(ips.length > 0);
|
|
|
|
assert.strictEqual(ips[0].address, '127.0.0.1');
|
|
|
|
assert.strictEqual(ips[0].family, 4);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_lookup_null_all(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.lookup(null, {all: true}, function(err, ips, family) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2015-02-06 21:43:50 +01:00
|
|
|
assert.ok(Array.isArray(ips));
|
|
|
|
assert.strictEqual(ips.length, 0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_lookup_all_mixed(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.lookup('www.google.com', {all: true}, function(err, ips) {
|
2016-12-30 16:54:01 +01:00
|
|
|
assert.ifError(err);
|
2015-02-06 21:43:50 +01:00
|
|
|
assert.ok(Array.isArray(ips));
|
|
|
|
assert.ok(ips.length > 0);
|
|
|
|
|
|
|
|
ips.forEach(function(ip) {
|
|
|
|
if (isIPv4(ip.address))
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(ip.family, 4);
|
2015-02-06 21:43:50 +01:00
|
|
|
else if (isIPv6(ip.address))
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(ip.family, 6);
|
2015-02-06 21:43:50 +01:00
|
|
|
else
|
2017-01-19 17:18:51 +01:00
|
|
|
common.fail('unexpected IP address');
|
2015-02-06 21:43:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-21 00:43:00 +02:00
|
|
|
TEST(function test_lookupservice_invalid(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.lookupService('1.2.3.4', 80, function(err, host, service) {
|
2014-06-21 00:43:00 +02:00
|
|
|
assert(err instanceof Error);
|
|
|
|
assert.strictEqual(err.code, 'ENOTFOUND');
|
2014-08-06 16:53:59 +02:00
|
|
|
assert.ok(/1\.2\.3\.4/.test(err.message));
|
2014-06-21 00:43:00 +02:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-10-15 13:01:23 +02:00
|
|
|
TEST(function test_reverse_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.reverse('0.0.0.0', function(err) {
|
2013-10-15 13:01:23 +02:00
|
|
|
assert(err instanceof Error);
|
|
|
|
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
|
|
|
|
assert.strictEqual(err.hostname, '0.0.0.0');
|
2014-08-06 16:53:59 +02:00
|
|
|
assert.ok(/0\.0\.0\.0/.test(err.message));
|
2013-10-15 13:01:23 +02:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_lookup_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.lookup('nosuchhostimsure', function(err) {
|
2013-10-15 13:01:23 +02:00
|
|
|
assert(err instanceof Error);
|
|
|
|
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
|
|
|
|
assert.strictEqual(err.hostname, 'nosuchhostimsure');
|
2014-08-06 16:53:59 +02:00
|
|
|
assert.ok(/nosuchhostimsure/.test(err.message));
|
2013-10-15 13:01:23 +02:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_resolve_failure(done) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = dns.resolve4('nosuchhostimsure', function(err) {
|
2013-10-15 13:01:23 +02:00
|
|
|
assert(err instanceof Error);
|
2014-02-25 02:53:57 +01:00
|
|
|
|
2015-08-19 01:32:07 +02:00
|
|
|
switch (err.code) {
|
2014-02-25 02:53:57 +01:00
|
|
|
case 'ENOTFOUND':
|
|
|
|
case 'ESERVFAIL':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-15 13:01:23 +02:00
|
|
|
assert.strictEqual(err.hostname, 'nosuchhostimsure');
|
2014-08-06 16:53:59 +02:00
|
|
|
assert.ok(/nosuchhostimsure/.test(err.message));
|
2013-10-15 13:01:23 +02:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let getaddrinfoCallbackCalled = false;
|
2011-10-21 00:06:53 +02:00
|
|
|
|
2012-01-17 19:43:34 +01:00
|
|
|
console.log('looking up nodejs.org...');
|
2011-10-21 00:06:53 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const cares = process.binding('cares_wrap');
|
|
|
|
const req = new cares.GetAddrInfoReqWrap();
|
2015-12-27 07:08:08 +01:00
|
|
|
cares.getaddrinfo(req, 'nodejs.org', 4);
|
2013-08-12 17:28:38 +02:00
|
|
|
|
|
|
|
req.oncomplete = function(err, domains) {
|
|
|
|
assert.strictEqual(err, 0);
|
2012-01-17 19:43:34 +01:00
|
|
|
console.log('nodejs.org = ', domains);
|
2011-10-21 00:06:53 +02:00
|
|
|
assert.ok(Array.isArray(domains));
|
|
|
|
assert.ok(domains.length >= 1);
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(typeof domains[0], 'string');
|
2011-10-21 00:06:53 +02:00
|
|
|
getaddrinfoCallbackCalled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
console.log(completed + ' tests completed');
|
2016-10-08 01:38:47 +02:00
|
|
|
assert.strictEqual(running, false);
|
2011-10-21 00:06:53 +02:00
|
|
|
assert.strictEqual(expected, completed);
|
|
|
|
assert.ok(getaddrinfoCallbackCalled);
|
|
|
|
});
|