-
Notifications
You must be signed in to change notification settings - Fork 30.1k
/
test-dns-ipv6.js
207 lines (164 loc) Β· 4.87 KB
/
test-dns-ipv6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
'use strict';
const common = require('../common');
if (!common.hasIPv6)
common.skip('this test, no IPv6 support');
const assert = require('assert');
const dns = require('dns');
const net = require('net');
const isIPv6 = net.isIPv6;
let running = false;
const queue = [];
function TEST(f) {
function next() {
const f = queue.shift();
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) {
const req = dns.resolve6('ipv6.google.com',
common.mustCall((err, ips) => {
assert.ifError(err);
assert.ok(ips.length > 0);
for (let i = 0; i < ips.length; i++)
assert.ok(isIPv6(ips[i]));
done();
}));
checkWrap(req);
});
TEST(function test_reverse_ipv6(done) {
const req = dns.reverse('2001:4860:4860::8888',
common.mustCall((err, domains) => {
assert.ifError(err);
assert.ok(domains.length > 0);
for (let i = 0; i < domains.length; i++)
assert.ok(typeof domains[i] === 'string');
done();
}));
checkWrap(req);
});
TEST(function test_lookup_ipv6_explicit(done) {
const req = dns.lookup('ipv6.google.com', 6,
common.mustCall((err, ip, family) => {
assert.ifError(err);
assert.ok(isIPv6(ip));
assert.strictEqual(family, 6);
done();
}));
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) {
if (err) throw err;
assert.ok(net.isIPv6(ip));
assert.strictEqual(family, 6);
done();
});
checkWrap(req);
});
*/
TEST(function test_lookup_ipv6_explicit_object(done) {
const req = dns.lookup('ipv6.google.com', {
family: 6
}, common.mustCall((err, ip, family) => {
assert.ifError(err);
assert.ok(isIPv6(ip));
assert.strictEqual(family, 6);
done();
}));
checkWrap(req);
});
TEST(function test_lookup_ipv6_hint(done) {
const req = dns.lookup('www.google.com', {
family: 6,
hints: dns.V4MAPPED
}, common.mustCall((err, ip, family) => {
if (err) {
// FreeBSD does not support V4MAPPED
if (common.isFreeBSD) {
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;
}
assert.ifError(err);
}
assert.ok(isIPv6(ip));
assert.strictEqual(family, 6);
done();
}));
checkWrap(req);
});
TEST(function test_lookup_ip_ipv6(done) {
const req = dns.lookup('::1',
common.mustCall((err, ip, family) => {
assert.ifError(err);
assert.ok(isIPv6(ip));
assert.strictEqual(family, 6);
done();
}));
checkWrap(req);
});
TEST(function test_lookup_all_ipv6(done) {
const req = dns.lookup(
'www.google.com',
{all: true, family: 6},
common.mustCall((err, ips) => {
assert.ifError(err);
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
ips.forEach((ip) => {
assert.ok(isIPv6(ip.address),
`Invalid IPv6: ${ip.address.toString()}`);
assert.strictEqual(ip.family, 6);
});
done();
})
);
checkWrap(req);
});
TEST(function test_lookupservice_ip_ipv6(done) {
const req = dns.lookupService(
'::1', 80,
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();
})
);
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) {
if (err) throw err;
assert.ok(net.isIPv6(ip));
assert.strictEqual(family, 6);
done();
});
checkWrap(req);
}); */