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 | var dns = require('../dns'),
|
27 | net = require('net'),
|
28 | isIP = net.isIP,
|
29 | isIPv4 = net.isIPv4,
|
30 | isIPv6 = net.isIPv6;
|
31 |
|
32 | var platform = require('../lib/platform');
|
33 |
|
34 | platform.cache = false;
|
35 |
|
36 | function checkWrap(test, req) {
|
37 | test.ok(typeof req === 'object');
|
38 | }
|
39 |
|
40 | var fixed = false;
|
41 |
|
42 | var fixupDns = function () {
|
43 | console.log(platform.name_servers);
|
44 |
|
45 | platform.name_servers = [{
|
46 | address: '8.8.8.8',
|
47 | port: 53,
|
48 | }];
|
49 |
|
50 | platform.search_path = [];
|
51 |
|
52 | fixed = true;
|
53 | };
|
54 |
|
55 | platform.on('ready', fixupDns);
|
56 |
|
57 | if (platform.ready)
|
58 | fixupDns();
|
59 |
|
60 | exports.setUp = function (cb) {
|
61 | var checkReady = function() {
|
62 | if (fixed) {
|
63 | cb();
|
64 | } else {
|
65 | process.nextTick(checkReady);
|
66 | }
|
67 | }
|
68 | checkReady();
|
69 | };
|
70 |
|
71 | exports.resolve4 = function (test) {
|
72 | var req = dns.resolve4('www.google.com', function(err, ips) {
|
73 | test.ifError(err);
|
74 |
|
75 | test.ok(ips.length > 0);
|
76 |
|
77 | for (var i = 0; i < ips.length; i++) {
|
78 | test.ok(isIPv4(ips[i]));
|
79 | }
|
80 |
|
81 | test.done();
|
82 | });
|
83 |
|
84 | checkWrap(test, req);
|
85 | };
|
86 |
|
87 |
|
88 | exports.resolve6 = function (test) {
|
89 | var req = dns.resolve6('ipv6.google.com', function(err, ips) {
|
90 | test.ifError(err);
|
91 |
|
92 | test.ok(ips.length > 0);
|
93 |
|
94 | for (var i = 0; i < ips.length; i++) {
|
95 | test.ok(isIPv6(ips[i]));
|
96 | }
|
97 |
|
98 | test.done();
|
99 | });
|
100 |
|
101 | checkWrap(test, req);
|
102 | };
|
103 |
|
104 |
|
105 | exports.reverse_ipv4 = function (test) {
|
106 | var req = dns.reverse('8.8.8.8', function(err, domains) {
|
107 | test.ifError(err);
|
108 |
|
109 | test.ok(domains.length > 0);
|
110 |
|
111 | for (var i = 0; i < domains.length; i++) {
|
112 | test.ok(domains[i]);
|
113 | test.ok(typeof domains[i] === 'string');
|
114 | }
|
115 |
|
116 | test.done();
|
117 | });
|
118 |
|
119 | checkWrap(test, req);
|
120 | };
|
121 |
|
122 |
|
123 | exports.reverse_ipv6 = function (test) {
|
124 | var req = dns.reverse('2001:4860:4860::8888', function(err, domains) {
|
125 | test.ifError(err);
|
126 |
|
127 | test.ok(domains.length > 0);
|
128 |
|
129 | for (var i = 0; i < domains.length; i++) {
|
130 | test.ok(domains[i]);
|
131 | test.ok(typeof domains[i] === 'string');
|
132 | }
|
133 |
|
134 | test.done();
|
135 | });
|
136 |
|
137 | checkWrap(test, req);
|
138 | };
|
139 |
|
140 |
|
141 | exports.reverse_bogus = function (test) {
|
142 | var error;
|
143 |
|
144 | try {
|
145 | var req = dns.reverse('bogus ip', function() {
|
146 | test.ok(false);
|
147 | });
|
148 | } catch (e) {
|
149 | error = e;
|
150 | }
|
151 |
|
152 | test.ok(error instanceof Error);
|
153 | test.strictEqual(error.errno, 'ENOTIMP');
|
154 |
|
155 | test.done();
|
156 | };
|
157 |
|
158 |
|
159 | exports.resolveMx = function (test) {
|
160 | var req = dns.resolveMx('gmail.com', function(err, result) {
|
161 | test.ifError(err);
|
162 |
|
163 | test.ok(result.length > 0);
|
164 |
|
165 | for (var i = 0; i < result.length; i++) {
|
166 | var item = result[i];
|
167 | test.ok(item);
|
168 | test.ok(typeof item === 'object');
|
169 |
|
170 | test.ok(item.exchange);
|
171 | test.ok(typeof item.exchange === 'string');
|
172 |
|
173 | test.ok(typeof item.priority === 'number');
|
174 | }
|
175 |
|
176 | test.done();
|
177 | });
|
178 |
|
179 | checkWrap(test, req);
|
180 | };
|
181 |
|
182 |
|
183 | exports.resolveNs = function (test) {
|
184 | var req = dns.resolveNs('google.com', function(err, names) {
|
185 | test.ifError(err);
|
186 |
|
187 | if (names) {
|
188 | test.ok(names.length > 0);
|
189 |
|
190 | for (var i = 0; i < names.length; i++) {
|
191 | var name = names[i];
|
192 | test.ok(name);
|
193 | test.ok(typeof name === 'string');
|
194 | }
|
195 | } else {
|
196 | test.ok(names);
|
197 | }
|
198 |
|
199 | test.done();
|
200 | });
|
201 |
|
202 | checkWrap(test, req);
|
203 | };
|
204 |
|
205 |
|
206 | exports.resolveSrv = function (test) {
|
207 | var req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) {
|
208 | test.ifError(err);
|
209 |
|
210 | test.ok(result.length > 0);
|
211 |
|
212 | for (var i = 0; i < result.length; i++) {
|
213 | var item = result[i];
|
214 | test.ok(item);
|
215 | test.ok(typeof item === 'object');
|
216 |
|
217 | test.ok(item.name);
|
218 | test.ok(typeof item.name === 'string');
|
219 |
|
220 | test.ok(typeof item.port === 'number');
|
221 | test.ok(typeof item.priority === 'number');
|
222 | test.ok(typeof item.weight === 'number');
|
223 | }
|
224 |
|
225 | test.done();
|
226 | });
|
227 |
|
228 | checkWrap(test, req);
|
229 | };
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | exports.resolveTxt = function (test) {
|
253 | var req = dns.resolveTxt('google.com', function(err, records) {
|
254 | test.ifError(err);
|
255 | test.equal(records.length, 1);
|
256 | test.equal(records[0].indexOf('v=spf1'), 0);
|
257 | test.done();
|
258 | });
|
259 |
|
260 | checkWrap(test, req);
|
261 | };
|
262 |
|
263 |
|
264 | exports.lookup_ipv4_explicit = function (test) {
|
265 | var req = dns.lookup('www.google.com', 4, function(err, ip, family) {
|
266 | test.ifError(err);
|
267 | test.ok(net.isIPv4(ip));
|
268 | test.strictEqual(family, 4);
|
269 |
|
270 | test.done();
|
271 | });
|
272 |
|
273 | checkWrap(test, req);
|
274 | };
|
275 |
|
276 |
|
277 | exports.lookup_ipv4_implicit = function (test) {
|
278 | var req = dns.lookup('www.google.com', function(err, ip, family) {
|
279 | test.ifError(err);
|
280 | test.ok(net.isIPv4(ip));
|
281 | test.strictEqual(family, 4);
|
282 |
|
283 | test.done();
|
284 | });
|
285 |
|
286 | checkWrap(test, req);
|
287 | };
|
288 |
|
289 |
|
290 | exports.lookup_ipv6_explicit = function (test) {
|
291 | var req = dns.lookup('ipv6.google.com', 6, function(err, ip, family) {
|
292 | test.ifError(err);
|
293 | test.ok(net.isIPv6(ip));
|
294 | test.strictEqual(family, 6);
|
295 |
|
296 | test.done();
|
297 | });
|
298 |
|
299 | checkWrap(test, req);
|
300 | };
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | exports.lookup_failure = function (test) {
|
318 | var req = dns.lookup('does.not.exist', 4, function(err, ip, family) {
|
319 | test.ok(err instanceof Error);
|
320 | test.strictEqual(err.errno, dns.NOTFOUND);
|
321 | test.strictEqual(err.errno, 'ENOTFOUND');
|
322 |
|
323 | test.done();
|
324 | });
|
325 |
|
326 | checkWrap(test, req);
|
327 | };
|
328 |
|
329 | exports.lookup_null = function (test) {
|
330 | var req = dns.lookup(null, function(err, ip, family) {
|
331 | test.ifError(err);
|
332 | test.strictEqual(ip, null);
|
333 | test.strictEqual(family, 4);
|
334 |
|
335 | test.done();
|
336 | });
|
337 |
|
338 | checkWrap(test, req);
|
339 | };
|
340 |
|
341 |
|
342 | exports.lookup_ip_ipv4 = function (test) {
|
343 | var req = dns.lookup('127.0.0.1', function(err, ip, family) {
|
344 | test.ifError(err);
|
345 | test.strictEqual(ip, '127.0.0.1');
|
346 | test.strictEqual(family, 4);
|
347 |
|
348 | test.done();
|
349 | });
|
350 |
|
351 | checkWrap(test, req);
|
352 | };
|
353 |
|
354 |
|
355 |
|
356 | exports.lookup_ip_ipv6 = function (test) {
|
357 | var req = dns.lookup('::1', function(err, ip, family) {
|
358 | test.ifError(err);
|
359 | test.ok(net.isIPv6(ip));
|
360 | test.strictEqual(family, 6);
|
361 |
|
362 | test.done();
|
363 | });
|
364 |
|
365 | checkWrap(test, req);
|
366 | };
|
367 |
|
368 |
|
369 |
|
370 | exports.lookup_localhost_ipv4 = function (test) {
|
371 | var req = dns.lookup('localhost', 4, function(err, ip, family) {
|
372 | test.ifError(err);
|
373 | test.strictEqual(ip, '127.0.0.1');
|
374 | test.strictEqual(family, 4);
|
375 |
|
376 | test.done();
|
377 | });
|
378 |
|
379 | checkWrap(test, req);
|
380 | };
|
381 |
|
382 | exports.lookup_longname = function (test) {
|
383 | var name, request;
|
384 |
|
385 | var name = '************';
|
386 | name += name + '***************'
|
387 | name += name + '***************'
|
388 | name += name + '***************'
|
389 | name += name + '***************'
|
390 | name += name + '***************'
|
391 |
|
392 | request = dns.lookup(name, 4, function (err, ip, family) {
|
393 | test.ok(err, "we should fail");
|
394 | test.strictEqual(err.errno, dns.NOTFOUND);
|
395 |
|
396 | test.done();
|
397 | });
|
398 | checkWrap(test, request);
|
399 | };
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|