Skip to content

Commit 06a10e1

Browse files
committed
tests: skip IPv6 tests with IPv4 host
The work done as part of revision 15ed85e was meant to prevent the IPv6 functional tests to fail when the MYSQLX_HOST environment variable pointed to an IPv4 address (and not a common hostname). It introduced some changes that resulted in over-complicated fixtures that supposedly allowed to work around those test failures. This was not really the case, because the "dns.lookup()" API returns only one IPv6 address which, in the case of a more convoluted setup, where multiple addresses can be available (even virtual ones) like the case of a NAT, will result in authentication failures due to the fact that the MySQL server is not able to perform the reverse lookup. Additionally, the "dns.lookup()" works as an identity function when the argument is an IPv4 address, which only leads to more confusion. When using an IPv4 address as the MYSQLX_HOST value, there is really not point in trying to run IPv6 tests at all. So, somehow "forcing" them to run using their IPv4 counterpart is not a great idea. This patch reverts some of the changes introduced in revision 15ed85e and simplifies the IPv6 test setup by ensuring that the record family of the address returned by "dns.lookup()" is, in fact the one for IPv6 addresses. If not, the lookup will result in an "undefined" address which will let the test harness naturally skip those tests. Change-Id: I30099a1c10d10726ffc40989a4720cff4baab237
1 parent 5947c95 commit 06a10e1

File tree

6 files changed

+33
-37
lines changed

6 files changed

+33
-37
lines changed

test/fixtures/getIPv4Address.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@
3232

3333
const dns = require('dns').promises;
3434

35-
module.exports = function ({ host } = {}) {
36-
return dns.lookup(host, { family: 4 })
37-
.then(({ address }) => address)
38-
// Ultimately, if the IPv4 address cannot be obtained, it should be
39-
// "undefined".
35+
const RECORD_FAMILY = 4;
36+
37+
module.exports = function (host) {
38+
// If the IPv4 address cannot be obtained, it should be "undefined".
39+
return dns.lookup(host, { family: RECORD_FAMILY })
40+
.then(({ address, family }) => {
41+
if (family !== RECORD_FAMILY) {
42+
return;
43+
}
44+
45+
return address;
46+
})
4047
.catch(() => undefined);
4148
};

test/fixtures/getIPv6Address.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,18 @@
3131
'use strict';
3232

3333
const dns = require('dns').promises;
34-
const getIPv4Address = require('./getIPv4Address');
3534

36-
module.exports = function ({ host, port } = {}) {
37-
// The host can be a common name, IPv4 or IPv6 address.
38-
// "dns.lookup()"" does not work with IP addresses, so we first need to
39-
// ensure we use the resolved common name instead.
40-
// So, we can start by retrieving the IPv4 address.
41-
return getIPv4Address({ host })
42-
.then(address => {
43-
// Then we use the IPv4 address to obtain the common name.
44-
return dns.lookupService(address, port);
45-
})
46-
.then(({ hostname }) => {
47-
// We can then use the common name to finally obtain any available
48-
// IPv6 address. Of course, if the original host is already
49-
// provided as a common name, there is one extra step involved,
50-
// but, at least, we tried our best to obtain an address.
51-
return dns.lookup(hostname, { family: 6 });
52-
})
53-
.then(({ address }) => {
35+
const RECORD_FAMILY = 6;
36+
37+
module.exports = function (host) {
38+
// If the IPv6 address cannot be obtained, it should be "undefined".
39+
return dns.lookup(host, { family: RECORD_FAMILY })
40+
.then(({ address, family }) => {
41+
if (family !== RECORD_FAMILY) {
42+
return;
43+
}
44+
5445
return address;
5546
})
56-
// Ultimately, if the IPv6 address cannot be obtained, it should be
57-
// "undefined".
5847
.catch(() => undefined);
5948
};

test/functional/default/connection/dns-srv.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
7878
}];
7979

8080
beforeEach('setup fake DNS server in the current host', () => {
81-
return fixtures.getIPv4Address({ host: os.hostname() })
81+
return fixtures.getIPv4Address(os.hostname())
8282
.then(host => {
8383
return fixtures.createRecordServer({ host, service: baseConfig.host, records });
8484
})
@@ -121,7 +121,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
121121
let originalServers, fakeServer;
122122

123123
beforeEach('setup fake DNS server in the current host', () => {
124-
return fixtures.getIPv4Address({ host: os.hostname() })
124+
return fixtures.getIPv4Address(os.hostname())
125125
.then(host => {
126126
return fixtures.createRecordServer({ host, service: baseConfig.host, records: [] });
127127
})

test/functional/default/connection/ipv6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('connecting to the MySQL server using IPv6', () => {
4343
const baseConfig = { schema: undefined, socket: undefined };
4444

4545
beforeEach('resolve IPv6 address', () => {
46-
return fixtures.getIPv6Address({ host: config.host, port: config.port })
46+
return fixtures.getIPv6Address(config.host)
4747
.then(address => {
4848
host = address;
4949
});

test/functional/extended/connection/dns-srv.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
4949

5050
return mysqlx.getSession(`mysqlx+srv://${srvConfig.user}:${srvConfig.password}@${srvConfig.host}`)
5151
.then(session => {
52-
return fixtures.getIPv4Address({ host: session.inspect().host })
52+
return fixtures.getIPv4Address(session.inspect().host)
5353
.then(address => {
5454
expect(address).to.equal(endpoint.address);
5555
return session.close();
@@ -71,7 +71,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
7171

7272
return mysqlx.getSession(srvConfig)
7373
.then(session => {
74-
return fixtures.getIPv4Address({ host: session.inspect().host })
74+
return fixtures.getIPv4Address(session.inspect().host)
7575
.then(address => {
7676
expect(address).to.equal(endpoints[0].address);
7777
return session.close();
@@ -84,7 +84,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
8484
return mysqlx.getSession(srvConfig);
8585
})
8686
.then(session => {
87-
return fixtures.getIPv4Address({ host: session.inspect().host })
87+
return fixtures.getIPv4Address(session.inspect().host)
8888
.then(address => {
8989
expect(address).to.equal(endpoints[1].address);
9090
return session.close();
@@ -97,7 +97,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
9797
return mysqlx.getSession(srvConfig);
9898
})
9999
.then(session => {
100-
return fixtures.getIPv4Address({ host: session.inspect().host })
100+
return fixtures.getIPv4Address(session.inspect().host)
101101
.then(address => {
102102
expect(address).to.equal(endpoints[0].address);
103103
return session.close();
@@ -124,7 +124,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
124124

125125
return pool.getSession()
126126
.then(session => {
127-
return fixtures.getIPv4Address({ host: session.inspect().host });
127+
return fixtures.getIPv4Address(session.inspect().host);
128128
})
129129
.then(address => {
130130
expect(address).to.equal(endpoints[0].address);
@@ -136,7 +136,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
136136
return pool.getSession();
137137
})
138138
.then(session => {
139-
return fixtures.getIPv4Address({ host: session.inspect().host });
139+
return fixtures.getIPv4Address(session.inspect().host);
140140
})
141141
.then(address => {
142142
expect(address).to.equal(endpoints[1].address);
@@ -148,7 +148,7 @@ describe('connecting to the MySQL server using DNS SRV', () => {
148148
return pool.getSession();
149149
})
150150
.then(session => {
151-
return fixtures.getIPv4Address({ host: session.inspect().host });
151+
return fixtures.getIPv4Address(session.inspect().host);
152152
})
153153
.then(address => {
154154
expect(address).to.equal(endpoints[0].address);

test/functional/extended/connection/failures.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe('connection failures', () => {
198198
return expect.fail();
199199
})
200200
.catch(err => {
201-
return fixtures.getIPv4Address({ host: serverShutdownConfig.host })
201+
return fixtures.getIPv4Address(serverShutdownConfig.host)
202202
.then(address => {
203203
expect(err.code).to.equal('ECONNREFUSED');
204204
expect(err.address).to.equal(address);

0 commit comments

Comments
 (0)