Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: make dns recursive by default
Browse files Browse the repository at this point in the history
  • Loading branch information
niinpatel committed Mar 20, 2019
1 parent 4e63c6c commit 1d87bb0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down
4 changes: 3 additions & 1 deletion src/core/runtime/dns-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions test/cli/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})
})

Expand Down
4 changes: 2 additions & 2 deletions test/core/dns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/<ipnsaddress>
expect(res).to.match(/\/ipns\/.+$/)
})
Expand Down

0 comments on commit 1d87bb0

Please sign in to comment.