From a465f2bc78236728146922d257371f1077ab5ed3 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 23 Oct 2017 02:04:07 +0800 Subject: [PATCH] test: introduce test/common/internet.addresses This commit introduces test/common/internet.address, which includes a set of addresses for doing internet tests. These addresses can be overriden using NODE_TEST_* environment variables. PR-URL: https://github.com/nodejs/node/pull/16390 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/common/README.md | 35 ++++++++++++++++++++++++++ test/common/dns.js | 4 ++- test/common/internet.js | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 test/common/internet.js diff --git a/test/common/README.md b/test/common/README.md index 46eb001df86cf6..32a14382ff5c51 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -10,6 +10,7 @@ This directory contains modules used to test the Node.js implementation. * [DNS module](#dns-module) * [Duplex pair helper](#duplex-pair-helper) * [Fixtures module](#fixtures-module) +* [Internet module](#internet-module) * [WPT module](#wpt-module) ## Benchmark Module @@ -498,6 +499,40 @@ Returns the result of Returns the result of `fs.readFileSync(path.join(fixtures.fixturesDir, 'keys', arg), 'enc')`. +## Internet Module + +The `common/internet` module provides utilities for working with +internet-related tests. + +### internet.addresses + +* [<Object>] + * `INET_HOST` [<String>] A generic host that has registered common + DNS records, supports both IPv4 and IPv6, and provides basic HTTP/HTTPS + services + * `INET4_HOST` [<String>] A host that provides IPv4 services + * `INET6_HOST` [<String>] A host that provides IPv6 services + * `INET4_IP` [<String>] An accessible IPv4 IP, defaults to the + Google Public DNS IPv4 address + * `INET6_IP` [<String>] An accessible IPv6 IP, defaults to the + Google Public DNS IPv6 address + * `INVALID_HOST` [<String>] An invalid host that cannot be resolved + * `MX_HOST` [<String>] A host with MX records registered + * `SRV_HOST` [<String>] A host with SRV records registered + * `PTR_HOST` [<String>] A host with PTR records registered + * `NAPTR_HOST` [<String>] A host with NAPTR records registered + * `SOA_HOST` [<String>] A host with SOA records registered + * `CNAME_HOST` [<String>] A host with CNAME records registered + * `NS_HOST` [<String>] A host with NS records registered + * `TXT_HOST` [<String>] A host with TXT records registered + * `DNS4_SERVER` [<String>] An accessible IPv4 DNS server + * `DNS6_SERVER` [<String>] An accessible IPv6 DNS server + +A set of addresses for internet-related tests. All properties are configurable +via `NODE_TEST_*` environment variables. For example, to configure +`internet.addresses.INET_HOST`, set the environment +vairable `NODE_TEST_INET_HOST` to a specified host. + ## WPT Module The wpt.js module is a port of parts of diff --git a/test/common/dns.js b/test/common/dns.js index 6ab3fcbc91278b..432d1b764dde29 100644 --- a/test/common/dns.js +++ b/test/common/dns.js @@ -287,4 +287,6 @@ function writeDNSPacket(parsed) { })); } -module.exports = { types, classes, writeDNSPacket, parseDNSPacket }; +module.exports = { + types, classes, writeDNSPacket, parseDNSPacket +}; diff --git a/test/common/internet.js b/test/common/internet.js new file mode 100644 index 00000000000000..48b532ca8e6606 --- /dev/null +++ b/test/common/internet.js @@ -0,0 +1,54 @@ +/* eslint-disable required-modules */ +'use strict'; + +// Utilities for internet-related tests + +const addresses = { + // A generic host that has registered common DNS records, + // supports both IPv4 and IPv6, and provides basic HTTP/HTTPS services + INET_HOST: 'nodejs.org', + // A host that provides IPv4 services + INET4_HOST: 'nodejs.org', + // A host that provides IPv6 services + INET6_HOST: 'nodejs.org', + // An accessible IPv4 IP, + // defaults to the Google Public DNS IPv4 address + INET4_IP: '8.8.8.8', + // An accessible IPv6 IP, + // defaults to the Google Public DNS IPv6 address + INET6_IP: '2001:4860:4860::8888', + // An invalid host that cannot be resolved + // See https://tools.ietf.org/html/rfc2606#section-2 + INVALID_HOST: 'something.invalid', + // A host with MX records registered + MX_HOST: 'nodejs.org', + // A host with SRV records registered + SRV_HOST: '_jabber._tcp.google.com', + // A host with PTR records registered + PTR_HOST: '8.8.8.8.in-addr.arpa', + // A host with NAPTR records registered + NAPTR_HOST: 'sip2sip.info', + // A host with SOA records registered + SOA_HOST: 'nodejs.org', + // A host with CNAME records registered + CNAME_HOST: 'blog.nodejs.org', + // A host with NS records registered + NS_HOST: 'nodejs.org', + // A host with TXT records registered + TXT_HOST: 'nodejs.org', + // An accessible IPv4 DNS server + DNS4_SERVER: '8.8.8.8', + // An accessible IPv4 DNS server + DNS6_SERVER: '2001:4860:4860::8888' +}; + +for (const key of Object.keys(addresses)) { + const envName = `NODE_TEST_${key}`; + if (process.env[envName]) { + addresses[key] = process.env[envName]; + } +} + +module.exports = { + addresses +};