Skip to content

Commit 239c02d

Browse files
committed
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: nodejs#16390 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 16bf5fe commit 239c02d

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

test/common/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This directory contains modules used to test the Node.js implementation.
1010
* [DNS module](#dns-module)
1111
* [Duplex pair helper](#duplex-pair-helper)
1212
* [Fixtures module](#fixtures-module)
13+
* [Internet module](#internet-module)
1314
* [tmpdir module](#tmpdir-module)
1415
* [WPT module](#wpt-module)
1516

@@ -483,6 +484,40 @@ Returns the result of
483484
Returns the result of
484485
`fs.readFileSync(path.join(fixtures.fixturesDir, 'keys', arg), 'enc')`.
485486

487+
## Internet Module
488+
489+
The `common/internet` module provides utilities for working with
490+
internet-related tests.
491+
492+
### internet.addresses
493+
494+
* [&lt;Object>]
495+
* `INET_HOST` [&lt;String>] A generic host that has registered common
496+
DNS records, supports both IPv4 and IPv6, and provides basic HTTP/HTTPS
497+
services
498+
* `INET4_HOST` [&lt;String>] A host that provides IPv4 services
499+
* `INET6_HOST` [&lt;String>] A host that provides IPv6 services
500+
* `INET4_IP` [&lt;String>] An accessible IPv4 IP, defaults to the
501+
Google Public DNS IPv4 address
502+
* `INET6_IP` [&lt;String>] An accessible IPv6 IP, defaults to the
503+
Google Public DNS IPv6 address
504+
* `INVALID_HOST` [&lt;String>] An invalid host that cannot be resolved
505+
* `MX_HOST` [&lt;String>] A host with MX records registered
506+
* `SRV_HOST` [&lt;String>] A host with SRV records registered
507+
* `PTR_HOST` [&lt;String>] A host with PTR records registered
508+
* `NAPTR_HOST` [&lt;String>] A host with NAPTR records registered
509+
* `SOA_HOST` [&lt;String>] A host with SOA records registered
510+
* `CNAME_HOST` [&lt;String>] A host with CNAME records registered
511+
* `NS_HOST` [&lt;String>] A host with NS records registered
512+
* `TXT_HOST` [&lt;String>] A host with TXT records registered
513+
* `DNS4_SERVER` [&lt;String>] An accessible IPv4 DNS server
514+
* `DNS6_SERVER` [&lt;String>] An accessible IPv6 DNS server
515+
516+
A set of addresses for internet-related tests. All properties are configurable
517+
via `NODE_TEST_*` environment variables. For example, to configure
518+
`internet.addresses.INET_HOST`, set the environment
519+
vairable `NODE_TEST_INET_HOST` to a specified host.
520+
486521
## tmpdir Module
487522

488523
The `tmpdir` module supports the use of a temporary directory for testing.

test/common/dns.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,6 @@ function writeDNSPacket(parsed) {
287287
}));
288288
}
289289

290-
module.exports = { types, classes, writeDNSPacket, parseDNSPacket };
290+
module.exports = {
291+
types, classes, writeDNSPacket, parseDNSPacket
292+
};

test/common/internet.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-disable required-modules */
2+
'use strict';
3+
4+
// Utilities for internet-related tests
5+
6+
const addresses = {
7+
// A generic host that has registered common DNS records,
8+
// supports both IPv4 and IPv6, and provides basic HTTP/HTTPS services
9+
INET_HOST: 'nodejs.org',
10+
// A host that provides IPv4 services
11+
INET4_HOST: 'nodejs.org',
12+
// A host that provides IPv6 services
13+
INET6_HOST: 'nodejs.org',
14+
// An accessible IPv4 IP,
15+
// defaults to the Google Public DNS IPv4 address
16+
INET4_IP: '8.8.8.8',
17+
// An accessible IPv6 IP,
18+
// defaults to the Google Public DNS IPv6 address
19+
INET6_IP: '2001:4860:4860::8888',
20+
// An invalid host that cannot be resolved
21+
// See https://tools.ietf.org/html/rfc2606#section-2
22+
INVALID_HOST: 'something.invalid',
23+
// A host with MX records registered
24+
MX_HOST: 'nodejs.org',
25+
// A host with SRV records registered
26+
SRV_HOST: '_jabber._tcp.google.com',
27+
// A host with PTR records registered
28+
PTR_HOST: '8.8.8.8.in-addr.arpa',
29+
// A host with NAPTR records registered
30+
NAPTR_HOST: 'sip2sip.info',
31+
// A host with SOA records registered
32+
SOA_HOST: 'nodejs.org',
33+
// A host with CNAME records registered
34+
CNAME_HOST: 'blog.nodejs.org',
35+
// A host with NS records registered
36+
NS_HOST: 'nodejs.org',
37+
// A host with TXT records registered
38+
TXT_HOST: 'nodejs.org',
39+
// An accessible IPv4 DNS server
40+
DNS4_SERVER: '8.8.8.8',
41+
// An accessible IPv4 DNS server
42+
DNS6_SERVER: '2001:4860:4860::8888'
43+
};
44+
45+
for (const key of Object.keys(addresses)) {
46+
const envName = `NODE_TEST_${key}`;
47+
if (process.env[envName]) {
48+
addresses[key] = process.env[envName];
49+
}
50+
}
51+
52+
module.exports = {
53+
addresses
54+
};

0 commit comments

Comments
 (0)