2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-12-24 01:02:12 +01:00
|
|
|
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() {
|
|
|
|
var f = queue.shift();
|
|
|
|
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) {
|
2011-10-11 23:46:55 +02:00
|
|
|
assert.ok(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) {
|
|
|
|
var error;
|
|
|
|
|
|
|
|
try {
|
2015-12-27 07:08:08 +01:00
|
|
|
dns.reverse('bogus ip', function() {
|
2011-07-05 00:17:20 +02:00
|
|
|
assert.ok(false);
|
|
|
|
});
|
2011-10-05 00:08:18 +02:00
|
|
|
} catch (e) {
|
2011-07-05 00:17:20 +02:00
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.ok(error instanceof Error);
|
2013-08-12 17:28:38 +02:00
|
|
|
assert.strictEqual(error.errno, 'EINVAL');
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_resolveMx(done) {
|
|
|
|
var req = dns.resolveMx('gmail.com', function(err, result) {
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
var item = result[i];
|
|
|
|
assert.ok(item);
|
|
|
|
assert.ok(typeof item === 'object');
|
|
|
|
|
|
|
|
assert.ok(item.exchange);
|
|
|
|
assert.ok(typeof item.exchange === 'string');
|
|
|
|
|
|
|
|
assert.ok(typeof item.priority === 'number');
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_resolveNs(done) {
|
|
|
|
var req = dns.resolveNs('rackspace.com', function(err, names) {
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
assert.ok(names.length > 0);
|
|
|
|
|
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var name = names[i];
|
|
|
|
assert.ok(name);
|
|
|
|
assert.ok(typeof name === 'string');
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_resolveSrv(done) {
|
|
|
|
var req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) {
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
var item = result[i];
|
|
|
|
assert.ok(item);
|
|
|
|
assert.ok(typeof item === 'object');
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
assert.ok(item.name);
|
|
|
|
assert.ok(typeof item.name === 'string');
|
2011-07-05 00:17:20 +02:00
|
|
|
|
|
|
|
assert.ok(typeof item.port === 'number');
|
|
|
|
assert.ok(typeof item.priority === 'number');
|
|
|
|
assert.ok(typeof item.weight === 'number');
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
2012-09-18 11:21:38 +02:00
|
|
|
TEST(function test_resolveNaptr(done) {
|
|
|
|
var req = dns.resolveNaptr('sip2sip.info', function(err, result) {
|
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
assert.ok(result.length > 0);
|
|
|
|
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
var item = result[i];
|
|
|
|
assert.ok(item);
|
|
|
|
assert.ok(typeof item === 'object');
|
|
|
|
|
|
|
|
assert.ok(typeof item.flags === 'string');
|
|
|
|
assert.ok(typeof item.service === 'string');
|
|
|
|
assert.ok(typeof item.regexp === 'string');
|
|
|
|
assert.ok(typeof item.replacement === 'string');
|
|
|
|
assert.ok(typeof item.order === 'number');
|
|
|
|
assert.ok(typeof item.preference === 'number');
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
2011-07-05 00:17:20 +02:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
TEST(function test_resolveSoa(done) {
|
|
|
|
var req = dns.resolveSoa('nodejs.org', function(err, result) {
|
|
|
|
if (err) throw err;
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(result);
|
|
|
|
assert.ok(typeof result === 'object');
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(typeof result.nsname === 'string');
|
|
|
|
assert.ok(result.nsname.length > 0);
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(typeof result.hostmaster === 'string');
|
|
|
|
assert.ok(result.hostmaster.length > 0);
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(typeof result.serial === 'number');
|
|
|
|
assert.ok((result.serial > 0) && (result.serial < 4294967295));
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(typeof result.refresh === 'number');
|
2015-02-06 21:43:50 +01:00
|
|
|
assert.ok((result.refresh > 0) && (result.refresh < 2147483647));
|
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(typeof result.retry === 'number');
|
|
|
|
assert.ok((result.retry > 0) && (result.retry < 2147483647));
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(typeof result.expire === 'number');
|
|
|
|
assert.ok((result.expire > 0) && (result.expire < 2147483647));
|
2015-02-06 21:43:50 +01:00
|
|
|
|
2013-10-21 15:47:57 +02:00
|
|
|
assert.ok(typeof result.minttl === 'number');
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
TEST(function test_resolveCname(done) {
|
2012-09-26 01:56:42 +02:00
|
|
|
var req = dns.resolveCname('www.microsoft.com', function(err, names) {
|
2011-07-05 00:17:20 +02:00
|
|
|
if (err) throw err;
|
|
|
|
|
|
|
|
assert.ok(names.length > 0);
|
|
|
|
|
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
var name = names[i];
|
|
|
|
assert.ok(name);
|
|
|
|
assert.ok(typeof name === 'string');
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2011-07-05 21:16:13 +02:00
|
|
|
checkWrap(req);
|
2011-07-05 00:17:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-10-03 16:50:09 +02:00
|
|
|
TEST(function test_resolveTxt(done) {
|
|
|
|
var req = dns.resolveTxt('google.com', function(err, records) {
|
|
|
|
if (err) throw err;
|
|
|
|
assert.equal(records.length, 1);
|
2014-04-30 18:14:55 +02:00
|
|
|
assert.ok(util.isArray(records[0]));
|
|
|
|
assert.equal(records[0][0].indexOf('v=spf1'), 0);
|
2011-10-03 16:50:09 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-07-05 00:17:20 +02:00
|
|
|
TEST(function test_lookup_failure(done) {
|
|
|
|
var req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
|
|
|
|
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) {
|
|
|
|
var req = dns.lookup(null, function(err, ip, family) {
|
|
|
|
if (err) throw err;
|
|
|
|
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) {
|
|
|
|
var req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) {
|
|
|
|
if (err) throw err;
|
|
|
|
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) {
|
|
|
|
var req = dns.lookup(null, {all: true}, function(err, ips, family) {
|
|
|
|
if (err) throw err;
|
|
|
|
assert.ok(Array.isArray(ips));
|
|
|
|
assert.strictEqual(ips.length, 0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
TEST(function test_lookup_all_mixed(done) {
|
|
|
|
var req = dns.lookup('www.google.com', {all: true}, function(err, ips) {
|
|
|
|
if (err) throw err;
|
|
|
|
assert.ok(Array.isArray(ips));
|
|
|
|
assert.ok(ips.length > 0);
|
|
|
|
|
|
|
|
ips.forEach(function(ip) {
|
|
|
|
if (isIPv4(ip.address))
|
|
|
|
assert.equal(ip.family, 4);
|
|
|
|
else if (isIPv6(ip.address))
|
|
|
|
assert.equal(ip.family, 6);
|
|
|
|
else
|
|
|
|
assert(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-21 00:43:00 +02:00
|
|
|
TEST(function test_lookupservice_invalid(done) {
|
|
|
|
var req = dns.lookupService('1.2.3.4', 80, function(err, host, service) {
|
|
|
|
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) {
|
|
|
|
var req = dns.reverse('0.0.0.0', function(err) {
|
|
|
|
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) {
|
|
|
|
var req = dns.lookup('nosuchhostimsure', function(err) {
|
|
|
|
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) {
|
|
|
|
var req = dns.resolve4('nosuchhostimsure', function(err) {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-10-21 00:06:53 +02:00
|
|
|
var getaddrinfoCallbackCalled = false;
|
|
|
|
|
2012-01-17 19:43:34 +01:00
|
|
|
console.log('looking up nodejs.org...');
|
2011-10-21 00:06:53 +02:00
|
|
|
|
2014-12-09 05:29:47 +01:00
|
|
|
var cares = process.binding('cares_wrap');
|
|
|
|
var 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);
|
|
|
|
assert.ok(typeof domains[0] == 'string');
|
|
|
|
getaddrinfoCallbackCalled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
console.log(completed + ' tests completed');
|
|
|
|
assert.equal(running, false);
|
|
|
|
assert.strictEqual(expected, completed);
|
|
|
|
assert.ok(getaddrinfoCallbackCalled);
|
|
|
|
});
|