diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js index cf4f023f23..5fba61558e 100644 --- a/src/cli/commands/dns.js +++ b/src/cli/commands/dns.js @@ -9,7 +9,7 @@ module.exports = { builder: { recursive: { type: 'boolean', - default: false, + default: true, alias: 'r', desc: 'Resolve until the result is not a DNS link' }, diff --git a/src/core/runtime/dns-nodejs.js b/src/core/runtime/dns-nodejs.js index a3dd5a0e30..df7226e0b0 100644 --- a/src/core/runtime/dns-nodejs.js +++ b/src/core/runtime/dns-nodejs.js @@ -8,7 +8,9 @@ const errcode = require('err-code') const maxRecursiveDepth = 32 module.exports = (domain, opts, callback) => { - const recursive = opts.recursive && opts.recursive.toString() === 'true' + // recursive is true by default, it's set to false only if explicitly passed as argument in opts + const recursive = opts.recursive === undefined || opts.recursive.toString() === 'true' + let depth if (recursive) { depth = maxRecursiveDepth diff --git a/test/cli/dns.js b/test/cli/dns.js index 09286aa325..2f7a9fab10 100644 --- a/test/cli/dns.js +++ b/test/cli/dns.js @@ -3,6 +3,7 @@ const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') +const isIPFS = require('is-ipfs') describe('dns', () => runOnAndOff((thing) => { let ipfs @@ -12,19 +13,33 @@ describe('dns', () => runOnAndOff((thing) => { ipfs = thing.ipfs }) - it('resolve ipfs.io dns', function () { + it('recursively resolve ipfs.io dns', function () { this.timeout(60 * 1000) return ipfs('dns ipfs.io').then((res) => { - expect(res.substr(0, 6)).to.eql('/ipns/') + expect(res.substr(0, 6)).to.eql('/ipfs/') + const resultingDomainOrCid = res.split('/')[2].trim() + expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true) }) }) - it('resolve _dnslink.ipfs.io dns', function () { + it('recursively resolve _dnslink.ipfs.io dns', function () { this.timeout(60 * 1000) return ipfs('dns _dnslink.ipfs.io').then((res) => { + expect(res.substr(0, 6)).to.eql('/ipfs/') + const resultingDomainOrCid = res.split('/')[2].trim() + expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true) + }) + }) + + it('non-recursive resolve ipfs.io', function () { + this.timeout(60 * 1000) + + return ipfs('dns --recursive false ipfs.io').then((res) => { expect(res.substr(0, 6)).to.eql('/ipns/') + const resultingDomainOrCid = res.split('/')[2].trim() + expect(isIPFS.cid(resultingDomainOrCid)).to.eql(false) }) }) diff --git a/test/core/dns.spec.js b/test/core/dns.spec.js index cecd56b2fe..efba2c241d 100644 --- a/test/core/dns.spec.js +++ b/test/core/dns.spec.js @@ -39,8 +39,8 @@ describe('.dns', () => { // skipping because there is an error in https://ipfs.io/api/v0/dns?arg=ipfs.io // unskip once this is resolved: https://github.com/ipfs/go-ipfs/issues/6086 - it.skip('should resolve ipfs.io', () => { - return ipfs.dns('ipfs.io').then(res => { + it.skip('should non-recursively resolve ipfs.io', () => { + return ipfs.dns('ipfs.io', { recursive: false }).then(res => { // matches pattern /ipns/ expect(res).to.match(/\/ipns\/.+$/) })