diff --git a/src/dns.js b/src/dns.js index 75ae0db71..35984d182 100644 --- a/src/dns.js +++ b/src/dns.js @@ -183,7 +183,7 @@ async function removeDnsRecords(location, domain, type, values) { async function waitForDnsRecord(location, domain, type, value, options) { assert.strictEqual(typeof location, 'string'); assert.strictEqual(typeof domain, 'string'); - assert(type === 'A' || type === 'TXT'); + assert(type === 'A' || type === 'AAAA' || type === 'TXT'); assert.strictEqual(typeof value, 'string'); assert(options && typeof options === 'object'); // { interval: 5000, times: 50000 } diff --git a/src/dns/waitfordns.js b/src/dns/waitfordns.js index a93ca3324..6373c55e6 100644 --- a/src/dns/waitfordns.js +++ b/src/dns/waitfordns.js @@ -8,14 +8,15 @@ const assert = require('assert'), debug = require('debug')('box:dns/waitfordns'), dns = require('../dns.js'); -function resolveIp(hostname, options, callback) { +function resolveIp(hostname, type, options, callback) { assert.strictEqual(typeof hostname, 'string'); + assert(type === 'A' || type === 'AAAA'); assert.strictEqual(typeof options, 'object'); assert.strictEqual(typeof callback, 'function'); // try A record at authoritative server - debug(`resolveIp: Checking if ${hostname} has A record at ${options.server}`); - dns.resolve(hostname, 'A', options, function (error, results) { + debug(`resolveIp: Checking if ${hostname} has ${type} record at ${options.server}`); + dns.resolve(hostname, type, options, function (error, results) { if (!error && results.length !== 0) return callback(null, results); // try CNAME record at authoritative server @@ -25,7 +26,7 @@ function resolveIp(hostname, options, callback) { // recurse lookup the CNAME record debug(`resolveIp: Resolving ${hostname}'s CNAME record ${results[0]}`); - dns.resolve(results[0], 'A', { server: '127.0.0.1', timeout: options.timeout }, callback); + dns.resolve(results[0], type, { server: '127.0.0.1', timeout: options.timeout }, callback); }); }); } @@ -46,7 +47,7 @@ function isChangeSynced(hostname, type, value, nameserver, callback) { async.every(nsIps, function (nsIp, iteratorCallback) { const resolveOptions = { server: nsIp, timeout: 5000 }; - const resolver = type === 'A' ? resolveIp.bind(null, hostname) : dns.resolve.bind(null, hostname, 'TXT'); + const resolver = type === 'A' || type === 'AAAA' ? resolveIp.bind(null, hostname, type) : dns.resolve.bind(null, hostname, 'TXT'); resolver(resolveOptions, function (error, answer) { if (error && error.code === 'TIMEOUT') { @@ -60,7 +61,7 @@ function isChangeSynced(hostname, type, value, nameserver, callback) { } let match; - if (type === 'A') { + if (type === 'A' || type === 'AAAA') { match = answer.length === 1 && answer[0] === value; } else if (type === 'TXT') { // answer is a 2d array of strings match = answer.some(function (a) { return value === a.join(''); }); @@ -79,7 +80,7 @@ function isChangeSynced(hostname, type, value, nameserver, callback) { function waitForDns(hostname, zoneName, type, value, options, callback) { assert.strictEqual(typeof hostname, 'string'); assert.strictEqual(typeof zoneName, 'string'); - assert(type === 'A' || type === 'TXT'); + assert(type === 'A' || type === 'AAAA' || type === 'TXT'); assert.strictEqual(typeof value, 'string'); assert(options && typeof options === 'object'); // { interval: 5000, times: 50000 } assert.strictEqual(typeof callback, 'function');