2015-09-09 22:06:31 +00:00
|
|
|
'use strict';
|
2016-01-13 20:42:45 +00:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const dns = require('dns');
|
|
|
|
const net = require('net');
|
|
|
|
const isIPv6 = net.isIPv6;
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2016-01-13 20:42:45 +00:00
|
|
|
let running = false;
|
|
|
|
const queue = [];
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2015-10-19 19:30:11 +00:00
|
|
|
if (!common.hasIPv6) {
|
2016-05-11 19:34:52 +00:00
|
|
|
common.skip('this test, no IPv6 support');
|
2015-10-19 19:30:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-09 22:06:31 +00:00
|
|
|
function TEST(f) {
|
|
|
|
function next() {
|
2016-12-16 16:02:29 +00:00
|
|
|
const f = queue.shift();
|
2015-09-09 22:06:31 +00:00
|
|
|
if (f) {
|
|
|
|
running = true;
|
|
|
|
console.log(f.name);
|
|
|
|
f(done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function done() {
|
|
|
|
running = false;
|
|
|
|
process.nextTick(next);
|
|
|
|
}
|
|
|
|
|
|
|
|
queue.push(f);
|
|
|
|
|
|
|
|
if (!running) {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkWrap(req) {
|
|
|
|
assert.ok(typeof req === 'object');
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(function test_resolve6(done) {
|
2016-12-16 16:02:29 +00:00
|
|
|
const req = dns.resolve6('ipv6.google.com',
|
2017-01-01 05:39:57 +00:00
|
|
|
common.mustCall((err, ips) => {
|
|
|
|
assert.ifError(err);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
assert.ok(ips.length > 0);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
for (let i = 0; i < ips.length; i++)
|
|
|
|
assert.ok(isIPv6(ips[i]));
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
done();
|
|
|
|
}));
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST(function test_reverse_ipv6(done) {
|
2016-12-16 16:02:29 +00:00
|
|
|
const req = dns.reverse('2001:4860:4860::8888',
|
2017-01-01 05:39:57 +00:00
|
|
|
common.mustCall((err, domains) => {
|
|
|
|
assert.ifError(err);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
assert.ok(domains.length > 0);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
for (let i = 0; i < domains.length; i++)
|
|
|
|
assert.ok(typeof domains[i] === 'string');
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
done();
|
|
|
|
}));
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST(function test_lookup_ipv6_explicit(done) {
|
2016-12-16 16:02:29 +00:00
|
|
|
const req = dns.lookup('ipv6.google.com', 6,
|
2017-01-01 05:39:57 +00:00
|
|
|
common.mustCall((err, ip, family) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(isIPv6(ip));
|
|
|
|
assert.strictEqual(family, 6);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
done();
|
|
|
|
}));
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* This ends up just being too problematic to test
|
|
|
|
TEST(function test_lookup_ipv6_implicit(done) {
|
|
|
|
var req = dns.lookup('ipv6.google.com', function(err, ip, family) {
|
2016-12-30 15:54:01 +00:00
|
|
|
assert.ifError(err);
|
2015-09-09 22:06:31 +00:00
|
|
|
assert.ok(net.isIPv6(ip));
|
|
|
|
assert.strictEqual(family, 6);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST(function test_lookup_ipv6_explicit_object(done) {
|
2016-12-16 16:02:29 +00:00
|
|
|
const req = dns.lookup('ipv6.google.com', {
|
2015-09-09 22:06:31 +00:00
|
|
|
family: 6
|
2016-12-16 16:02:29 +00:00
|
|
|
}, common.mustCall((err, ip, family) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(isIPv6(ip));
|
2015-09-09 22:06:31 +00:00
|
|
|
assert.strictEqual(family, 6);
|
|
|
|
|
|
|
|
done();
|
2016-12-16 16:02:29 +00:00
|
|
|
}));
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST(function test_lookup_ipv6_hint(done) {
|
2016-12-16 16:02:29 +00:00
|
|
|
const req = dns.lookup('www.google.com', {
|
2015-09-09 22:06:31 +00:00
|
|
|
family: 6,
|
|
|
|
hints: dns.V4MAPPED
|
2016-12-16 16:02:29 +00:00
|
|
|
}, common.mustCall((err, ip, family) => {
|
2015-09-09 22:06:31 +00:00
|
|
|
if (err) {
|
|
|
|
// FreeBSD does not support V4MAPPED
|
2016-05-29 15:53:40 +00:00
|
|
|
if (common.isFreeBSD) {
|
2015-09-09 22:06:31 +00:00
|
|
|
assert(err instanceof Error);
|
|
|
|
assert.strictEqual(err.code, 'EAI_BADFLAGS');
|
|
|
|
assert.strictEqual(err.hostname, 'www.google.com');
|
|
|
|
assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message));
|
|
|
|
done();
|
|
|
|
return;
|
|
|
|
}
|
2016-12-16 16:02:29 +00:00
|
|
|
|
|
|
|
assert.ifError(err);
|
2015-09-09 22:06:31 +00:00
|
|
|
}
|
2016-12-16 16:02:29 +00:00
|
|
|
|
|
|
|
assert.ok(isIPv6(ip));
|
2015-09-09 22:06:31 +00:00
|
|
|
assert.strictEqual(family, 6);
|
|
|
|
|
|
|
|
done();
|
2016-12-16 16:02:29 +00:00
|
|
|
}));
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST(function test_lookup_ip_ipv6(done) {
|
2016-12-16 16:02:29 +00:00
|
|
|
const req = dns.lookup('::1',
|
2017-01-01 05:39:57 +00:00
|
|
|
common.mustCall((err, ip, family) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(isIPv6(ip));
|
|
|
|
assert.strictEqual(family, 6);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
2017-01-01 05:39:57 +00:00
|
|
|
done();
|
|
|
|
}));
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST(function test_lookup_all_ipv6(done) {
|
2016-12-16 16:02:29 +00:00
|
|
|
const req = dns.lookup(
|
2016-01-13 20:42:45 +00:00
|
|
|
'www.google.com',
|
|
|
|
{all: true, family: 6},
|
2016-12-16 16:02:29 +00:00
|
|
|
common.mustCall((err, ips) => {
|
|
|
|
assert.ifError(err);
|
2016-01-13 20:42:45 +00:00
|
|
|
assert.ok(Array.isArray(ips));
|
|
|
|
assert.ok(ips.length > 0);
|
|
|
|
|
2016-12-16 16:02:29 +00:00
|
|
|
ips.forEach((ip) => {
|
2016-01-13 20:42:45 +00:00
|
|
|
assert.ok(isIPv6(ip.address),
|
2017-04-28 01:06:42 +00:00
|
|
|
`Invalid IPv6: ${ip.address.toString()}`);
|
2016-01-13 20:42:45 +00:00
|
|
|
assert.strictEqual(ip.family, 6);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
2017-01-01 05:39:57 +00:00
|
|
|
})
|
|
|
|
);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST(function test_lookupservice_ip_ipv6(done) {
|
2017-01-01 05:39:57 +00:00
|
|
|
const req = dns.lookupService(
|
|
|
|
'::1', 80,
|
2016-12-16 16:02:29 +00:00
|
|
|
common.mustCall((err, host, service) => {
|
|
|
|
if (err) {
|
|
|
|
// Not skipping the test, rather checking an alternative result,
|
|
|
|
// i.e. that ::1 may not be configured (e.g. in /etc/hosts)
|
|
|
|
assert.strictEqual(err.code, 'ENOTFOUND');
|
|
|
|
return done();
|
|
|
|
}
|
|
|
|
assert.strictEqual(typeof host, 'string');
|
|
|
|
assert(host);
|
|
|
|
assert(['http', 'www', '80'].includes(service));
|
|
|
|
done();
|
2017-01-01 05:39:57 +00:00
|
|
|
})
|
|
|
|
);
|
2015-09-09 22:06:31 +00:00
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Disabled because it appears to be not working on linux. */
|
|
|
|
/* TEST(function test_lookup_localhost_ipv6(done) {
|
|
|
|
var req = dns.lookup('localhost', 6, function(err, ip, family) {
|
2016-12-30 15:54:01 +00:00
|
|
|
assert.ifError(err);
|
2015-09-09 22:06:31 +00:00
|
|
|
assert.ok(net.isIPv6(ip));
|
|
|
|
assert.strictEqual(family, 6);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
checkWrap(req);
|
|
|
|
}); */
|