diff --git a/test/internet/test-dns-cares-domains.js b/test/internet/test-dns-cares-domains.js index 62c1847ea29adf..6609758a7daf17 100644 --- a/test/internet/test-dns-cares-domains.js +++ b/test/internet/test-dns-cares-domains.js @@ -1,5 +1,6 @@ 'use strict'; -require('../common'); +const common = require('../common'); +const { addresses } = require('../common/internet'); const assert = require('assert'); const dns = require('dns'); const domain = require('domain'); @@ -20,8 +21,8 @@ const methods = [ methods.forEach(function(method) { const d = domain.create(); d.run(function() { - dns[method]('google.com', function() { + dns[method](addresses.INET_HOST, common.mustCall(() => { assert.strictEqual(process.domain, d, `${method} retains domain`); - }); + })); }); }); diff --git a/test/internet/test-dns-ipv4.js b/test/internet/test-dns-ipv4.js index d3d5ba22009675..4c6e0ae6865e3f 100644 --- a/test/internet/test-dns-ipv4.js +++ b/test/internet/test-dns-ipv4.js @@ -1,5 +1,6 @@ 'use strict'; const common = require('../common'); +const { addresses } = require('../common/internet'); const assert = require('assert'); const dns = require('dns'); const net = require('net'); @@ -38,68 +39,72 @@ function checkWrap(req) { } TEST(function test_resolve4(done) { - const req = dns.resolve4('www.google.com', - common.mustCall((err, ips) => { - assert.ifError(err); + const req = dns.resolve4( + addresses.INET4_HOST, + common.mustCall((err, ips) => { + assert.ifError(err); - assert.ok(ips.length > 0); + assert.ok(ips.length > 0); - for (let i = 0; i < ips.length; i++) { - assert.ok(isIPv4(ips[i])); - } + for (let i = 0; i < ips.length; i++) { + assert.ok(isIPv4(ips[i])); + } - done(); - })); + done(); + })); checkWrap(req); }); TEST(function test_reverse_ipv4(done) { - const req = dns.reverse('8.8.8.8', - common.mustCall((err, domains) => { - assert.ifError(err); + const req = dns.reverse( + addresses.INET4_IP, + common.mustCall((err, domains) => { + assert.ifError(err); - assert.ok(domains.length > 0); + assert.ok(domains.length > 0); - for (let i = 0; i < domains.length; i++) { - assert.ok(domains[i]); - assert.ok(typeof domains[i] === 'string'); - } + for (let i = 0; i < domains.length; i++) { + assert.ok(domains[i]); + assert.ok(typeof domains[i] === 'string'); + } - done(); - })); + done(); + })); checkWrap(req); }); TEST(function test_lookup_ipv4_explicit(done) { - const req = dns.lookup('www.google.com', 4, - common.mustCall((err, ip, family) => { - assert.ifError(err); - assert.ok(net.isIPv4(ip)); - assert.strictEqual(family, 4); + const req = dns.lookup( + addresses.INET4_HOST, 4, + common.mustCall((err, ip, family) => { + assert.ifError(err); + assert.ok(net.isIPv4(ip)); + assert.strictEqual(family, 4); - done(); - })); + done(); + })); checkWrap(req); }); TEST(function test_lookup_ipv4_implicit(done) { - const req = dns.lookup('www.google.com', - common.mustCall((err, ip, family) => { - assert.ifError(err); - assert.ok(net.isIPv4(ip)); - assert.strictEqual(family, 4); + const req = dns.lookup( + addresses.INET4_HOST, + common.mustCall((err, ip, family) => { + assert.ifError(err); + assert.ok(net.isIPv4(ip)); + assert.strictEqual(family, 4); - done(); - })); + done(); + })); checkWrap(req); }); TEST(function test_lookup_ipv4_explicit_object(done) { - const req = dns.lookup('www.google.com', { + const req = dns.lookup(addresses.INET4_HOST, { family: 4 }, common.mustCall((err, ip, family) => { assert.ifError(err); @@ -113,7 +118,7 @@ TEST(function test_lookup_ipv4_explicit_object(done) { }); TEST(function test_lookup_ipv4_hint_addrconfig(done) { - const req = dns.lookup('www.google.com', { + const req = dns.lookup(addresses.INET4_HOST, { hints: dns.ADDRCONFIG }, common.mustCall((err, ip, family) => { assert.ifError(err); @@ -154,7 +159,7 @@ TEST(function test_lookup_localhost_ipv4(done) { TEST(function test_lookup_all_ipv4(done) { const req = dns.lookup( - 'www.google.com', + addresses.INET4_HOST, { all: true, family: 4 }, common.mustCall((err, ips) => { assert.ifError(err); diff --git a/test/internet/test-dns-ipv6.js b/test/internet/test-dns-ipv6.js index a91b108456c027..8b1a8936802729 100644 --- a/test/internet/test-dns-ipv6.js +++ b/test/internet/test-dns-ipv6.js @@ -1,5 +1,6 @@ 'use strict'; const common = require('../common'); +const { addresses } = require('../common/internet'); if (!common.hasIPv6) common.skip('this test, no IPv6 support'); @@ -38,53 +39,57 @@ function checkWrap(req) { } TEST(function test_resolve6(done) { - const req = dns.resolve6('ipv6.google.com', - common.mustCall((err, ips) => { - assert.ifError(err); + const req = dns.resolve6( + addresses.INET6_HOST, + common.mustCall((err, ips) => { + assert.ifError(err); - assert.ok(ips.length > 0); + assert.ok(ips.length > 0); - for (let i = 0; i < ips.length; i++) - assert.ok(isIPv6(ips[i])); + for (let i = 0; i < ips.length; i++) + assert.ok(isIPv6(ips[i])); - done(); - })); + done(); + })); checkWrap(req); }); TEST(function test_reverse_ipv6(done) { - const req = dns.reverse('2001:4860:4860::8888', - common.mustCall((err, domains) => { - assert.ifError(err); + const req = dns.reverse( + addresses.INET6_IP, + common.mustCall((err, domains) => { + assert.ifError(err); - assert.ok(domains.length > 0); + assert.ok(domains.length > 0); - for (let i = 0; i < domains.length; i++) - assert.ok(typeof domains[i] === 'string'); + for (let i = 0; i < domains.length; i++) + assert.ok(typeof domains[i] === 'string'); - done(); - })); + 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); + const req = dns.lookup( + addresses.INET6_HOST, + 6, + common.mustCall((err, ip, family) => { + assert.ifError(err); + assert.ok(isIPv6(ip)); + assert.strictEqual(family, 6); - done(); - })); + 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) { + var req = dns.lookup(addresses.INET6_HOST, function(err, ip, family) { assert.ifError(err); assert.ok(net.isIPv6(ip)); assert.strictEqual(family, 6); @@ -97,7 +102,7 @@ TEST(function test_lookup_ipv6_implicit(done) { */ TEST(function test_lookup_ipv6_explicit_object(done) { - const req = dns.lookup('ipv6.google.com', { + const req = dns.lookup(addresses.INET6_HOST, { family: 6 }, common.mustCall((err, ip, family) => { assert.ifError(err); @@ -111,7 +116,7 @@ TEST(function test_lookup_ipv6_explicit_object(done) { }); TEST(function test_lookup_ipv6_hint(done) { - const req = dns.lookup('www.google.com', { + const req = dns.lookup(addresses.INET6_HOST, { family: 6, hints: dns.V4MAPPED }, common.mustCall((err, ip, family) => { @@ -120,7 +125,7 @@ TEST(function test_lookup_ipv6_hint(done) { if (common.isFreeBSD) { assert(err instanceof Error); assert.strictEqual(err.code, 'EAI_BADFLAGS'); - assert.strictEqual(err.hostname, 'www.google.com'); + assert.strictEqual(err.hostname, addresses.INET_HOST); assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message)); done(); return; @@ -139,21 +144,22 @@ TEST(function test_lookup_ipv6_hint(done) { }); 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); + const req = dns.lookup( + '::1', + common.mustCall((err, ip, family) => { + assert.ifError(err); + assert.ok(isIPv6(ip)); + assert.strictEqual(family, 6); - done(); - })); + done(); + })); checkWrap(req); }); TEST(function test_lookup_all_ipv6(done) { const req = dns.lookup( - 'www.google.com', + addresses.INET6_HOST, { all: true, family: 6 }, common.mustCall((err, ips) => { assert.ifError(err); diff --git a/test/internet/test-dns-setserver-in-callback-of-resolve4.js b/test/internet/test-dns-setserver-in-callback-of-resolve4.js index 9ee853b5e4080b..2ef7e91f701efd 100644 --- a/test/internet/test-dns-setserver-in-callback-of-resolve4.js +++ b/test/internet/test-dns-setserver-in-callback-of-resolve4.js @@ -5,8 +5,11 @@ // a crash or not. If it doesn't crash, the test succeeded. const common = require('../common'); +const { addresses } = require('../common/internet'); const dns = require('dns'); -dns.resolve4('google.com', common.mustCall(function(/* err, nameServers */) { - dns.setServers([ '8.8.8.8' ]); -})); +dns.resolve4( + addresses.INET4_HOST, + common.mustCall(function(/* err, nameServers */) { + dns.setServers([ addresses.DNS4_SERVER ]); + })); diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 03bf4bb7f835b2..20d44118d782a3 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -21,6 +21,7 @@ 'use strict'; const common = require('../common'); +const { addresses } = require('../common/internet'); const assert = require('assert'); const dns = require('dns'); const net = require('net'); @@ -74,7 +75,9 @@ TEST(function test_reverse_bogus(done) { }); TEST(function test_resolve4_ttl(done) { - const req = dns.resolve4('google.com', { ttl: true }, function(err, result) { + const req = dns.resolve4(addresses.INET4_HOST, { + ttl: true + }, function(err, result) { assert.ifError(err); assert.ok(result.length > 0); @@ -95,7 +98,9 @@ TEST(function test_resolve4_ttl(done) { }); TEST(function test_resolve6_ttl(done) { - const req = dns.resolve6('google.com', { ttl: true }, function(err, result) { + const req = dns.resolve6(addresses.INET6_HOST, { + ttl: true + }, function(err, result) { assert.ifError(err); assert.ok(result.length > 0); @@ -116,7 +121,7 @@ TEST(function test_resolve6_ttl(done) { }); TEST(function test_resolveMx(done) { - const req = dns.resolveMx('gmail.com', function(err, result) { + const req = dns.resolveMx(addresses.MX_HOST, function(err, result) { assert.ifError(err); assert.ok(result.length > 0); @@ -138,7 +143,7 @@ TEST(function test_resolveMx(done) { }); TEST(function test_resolveMx_failure(done) { - const req = dns.resolveMx('something.invalid', function(err, result) { + const req = dns.resolveMx(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -151,7 +156,7 @@ TEST(function test_resolveMx_failure(done) { }); TEST(function test_resolveNs(done) { - const req = dns.resolveNs('rackspace.com', function(err, names) { + const req = dns.resolveNs(addresses.NS_HOST, function(err, names) { assert.ifError(err); assert.ok(names.length > 0); @@ -168,7 +173,7 @@ TEST(function test_resolveNs(done) { }); TEST(function test_resolveNs_failure(done) { - const req = dns.resolveNs('something.invalid', function(err, result) { + const req = dns.resolveNs(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -181,7 +186,7 @@ TEST(function test_resolveNs_failure(done) { }); TEST(function test_resolveSrv(done) { - const req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) { + const req = dns.resolveSrv(addresses.SRV_HOST, function(err, result) { assert.ifError(err); assert.ok(result.length > 0); @@ -205,7 +210,7 @@ TEST(function test_resolveSrv(done) { }); TEST(function test_resolveSrv_failure(done) { - const req = dns.resolveSrv('something.invalid', function(err, result) { + const req = dns.resolveSrv(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -218,7 +223,7 @@ TEST(function test_resolveSrv_failure(done) { }); TEST(function test_resolvePtr(done) { - const req = dns.resolvePtr('8.8.8.8.in-addr.arpa', function(err, result) { + const req = dns.resolvePtr(addresses.PTR_HOST, function(err, result) { assert.ifError(err); assert.ok(result.length > 0); @@ -235,7 +240,7 @@ TEST(function test_resolvePtr(done) { }); TEST(function test_resolvePtr_failure(done) { - const req = dns.resolvePtr('something.invalid', function(err, result) { + const req = dns.resolvePtr(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -248,7 +253,7 @@ TEST(function test_resolvePtr_failure(done) { }); TEST(function test_resolveNaptr(done) { - const req = dns.resolveNaptr('sip2sip.info', function(err, result) { + const req = dns.resolveNaptr(addresses.NAPTR_HOST, function(err, result) { assert.ifError(err); assert.ok(result.length > 0); @@ -272,7 +277,7 @@ TEST(function test_resolveNaptr(done) { }); TEST(function test_resolveNaptr_failure(done) { - const req = dns.resolveNaptr('something.invalid', function(err, result) { + const req = dns.resolveNaptr(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -285,7 +290,7 @@ TEST(function test_resolveNaptr_failure(done) { }); TEST(function test_resolveSoa(done) { - const req = dns.resolveSoa('nodejs.org', function(err, result) { + const req = dns.resolveSoa(addresses.SOA_HOST, function(err, result) { assert.ifError(err); assert.ok(result); assert.strictEqual(typeof result, 'object'); @@ -318,7 +323,7 @@ TEST(function test_resolveSoa(done) { }); TEST(function test_resolveSoa_failure(done) { - const req = dns.resolveSoa('something.invalid', function(err, result) { + const req = dns.resolveSoa(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -331,7 +336,7 @@ TEST(function test_resolveSoa_failure(done) { }); TEST(function test_resolveCname(done) { - const req = dns.resolveCname('www.microsoft.com', function(err, names) { + const req = dns.resolveCname(addresses.CNAME_HOST, function(err, names) { assert.ifError(err); assert.ok(names.length > 0); @@ -348,7 +353,7 @@ TEST(function test_resolveCname(done) { }); TEST(function test_resolveCname_failure(done) { - const req = dns.resolveCname('something.invalid', function(err, result) { + const req = dns.resolveCname(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -362,7 +367,7 @@ TEST(function test_resolveCname_failure(done) { TEST(function test_resolveTxt(done) { - const req = dns.resolveTxt('google.com', function(err, records) { + const req = dns.resolveTxt(addresses.TXT_HOST, function(err, records) { assert.ifError(err); assert.strictEqual(records.length, 1); assert.ok(util.isArray(records[0])); @@ -374,7 +379,7 @@ TEST(function test_resolveTxt(done) { }); TEST(function test_resolveTxt_failure(done) { - const req = dns.resolveTxt('something.invalid', function(err, result) { + const req = dns.resolveTxt(addresses.INVALID_HOST, function(err, result) { assert.ok(err instanceof Error); assert.strictEqual(err.errno, 'ENOTFOUND'); @@ -388,12 +393,12 @@ TEST(function test_resolveTxt_failure(done) { TEST(function test_lookup_failure(done) { - const req = dns.lookup('this.hostname.is.invalid', 4, (err, ip, family) => { + const req = dns.lookup(addresses.INVALID_HOST, 4, (err, ip, family) => { assert.ok(err instanceof Error); assert.strictEqual(err.errno, dns.NOTFOUND); assert.strictEqual(err.errno, 'ENOTFOUND'); assert.ok(!/ENOENT/.test(err.message)); - assert.ok(err.message.includes('this.hostname.is.invalid')); + assert.ok(err.message.includes(addresses.INVALID_HOST)); done(); }); @@ -461,7 +466,9 @@ TEST(function test_lookup_null_all(done) { TEST(function test_lookup_all_mixed(done) { - const req = dns.lookup('www.google.com', { all: true }, function(err, ips) { + const req = dns.lookup(addresses.INET_HOST, { + all: true + }, function(err, ips) { assert.ifError(err); assert.ok(Array.isArray(ips)); assert.ok(ips.length > 0); @@ -511,11 +518,11 @@ TEST(function test_reverse_failure(done) { TEST(function test_lookup_failure(done) { - const req = dns.lookup('this.hostname.is.invalid', (err) => { + const req = dns.lookup(addresses.INVALID_HOST, (err) => { assert(err instanceof Error); assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code... - assert.strictEqual(err.hostname, 'this.hostname.is.invalid'); - assert.ok(err.message.includes('this.hostname.is.invalid')); + assert.strictEqual(err.hostname, addresses.INVALID_HOST); + assert.ok(err.message.includes(addresses.INVALID_HOST)); done(); }); @@ -525,7 +532,7 @@ TEST(function test_lookup_failure(done) { TEST(function test_resolve_failure(done) { - const req = dns.resolve4('this.hostname.is.invalid', (err) => { + const req = dns.resolve4(addresses.INVALID_HOST, (err) => { assert(err instanceof Error); switch (err.code) { @@ -537,8 +544,8 @@ TEST(function test_resolve_failure(done) { break; } - assert.strictEqual(err.hostname, 'this.hostname.is.invalid'); - assert.ok(err.message.includes('this.hostname.is.invalid')); + assert.strictEqual(err.hostname, addresses.INVALID_HOST); + assert.ok(err.message.includes(addresses.INVALID_HOST)); done(); }); @@ -549,15 +556,16 @@ TEST(function test_resolve_failure(done) { let getaddrinfoCallbackCalled = false; -console.log('looking up nodejs.org...'); +console.log(`looking up ${addresses.INET4_HOST}..`); const cares = process.binding('cares_wrap'); const req = new cares.GetAddrInfoReqWrap(); -cares.getaddrinfo(req, 'nodejs.org', 4, /* hints */ 0, /* verbatim */ true); +cares.getaddrinfo(req, addresses.INET4_HOST, 4, + /* hints */ 0, /* verbatim */ true); req.oncomplete = function(err, domains) { assert.strictEqual(err, 0); - console.log('nodejs.org = ', domains); + console.log(`${addresses.INET4_HOST} = ${domains}`); assert.ok(Array.isArray(domains)); assert.ok(domains.length >= 1); assert.strictEqual(typeof domains[0], 'string'); @@ -572,10 +580,14 @@ process.on('exit', function() { }); -assert.doesNotThrow(() => dns.lookup('nodejs.org', 6, common.mustCall())); +assert.doesNotThrow(() => + dns.lookup(addresses.INET6_HOST, 6, common.mustCall())); -assert.doesNotThrow(() => dns.lookup('nodejs.org', {}, common.mustCall())); +assert.doesNotThrow(() => + dns.lookup(addresses.INET_HOST, {}, common.mustCall())); -assert.doesNotThrow(() => dns.lookupService('0.0.0.0', '0', common.mustCall())); +assert.doesNotThrow(() => + dns.lookupService('0.0.0.0', '0', common.mustCall())); -assert.doesNotThrow(() => dns.lookupService('0.0.0.0', 0, common.mustCall())); +assert.doesNotThrow(() => + dns.lookupService('0.0.0.0', 0, common.mustCall())); diff --git a/test/internet/test-http-https-default-ports.js b/test/internet/test-http-https-default-ports.js index 567b045dc6eacf..5f1b9eddb4f416 100644 --- a/test/internet/test-http-https-default-ports.js +++ b/test/internet/test-http-https-default-ports.js @@ -21,6 +21,7 @@ 'use strict'; const common = require('../common'); +const { addresses } = require('../common/internet'); if (!common.hasCrypto) common.skip('missing crypto'); @@ -29,10 +30,10 @@ const https = require('https'); const http = require('http'); -https.get('https://www.google.com/', common.mustCall(function(res) { +https.get(`https://${addresses.INET_HOST}/`, common.mustCall(function(res) { res.resume(); })); -http.get('http://www.google.com/', common.mustCall(function(res) { +http.get(`http://${addresses.INET_HOST}/`, common.mustCall(function(res) { res.resume(); }));