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

Commit 19e001a

Browse files
committed
feat: make dns recursive by default
1 parent 088e578 commit 19e001a

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/cli/commands/dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
builder: {
1010
recursive: {
1111
type: 'boolean',
12-
default: false,
12+
default: true,
1313
alias: 'r',
1414
desc: 'Resolve until the result is not a DNS link'
1515
},

src/core/runtime/dns-nodejs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const errcode = require('err-code')
88
const maxRecursiveDepth = 32
99

1010
module.exports = (domain, opts, callback) => {
11-
const recursive = opts.recursive && opts.recursive.toString() === 'true'
11+
// recursive is true by default, it's set to false only if explicitly passed as argument in opts
12+
const recursive = opts.recursive === undefined || opts.recursive.toString() === 'true'
13+
1214
let depth
1315
if (recursive) {
1416
depth = maxRecursiveDepth

test/cli/dns.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const expect = require('chai').expect
55
const runOnAndOff = require('../utils/on-and-off')
6+
const isIPFS = require('is-ipfs')
67

78
describe('dns', () => runOnAndOff((thing) => {
89
let ipfs
@@ -12,19 +13,33 @@ describe('dns', () => runOnAndOff((thing) => {
1213
ipfs = thing.ipfs
1314
})
1415

15-
it('resolve ipfs.io dns', function () {
16+
it('recursively resolve ipfs.io dns', function () {
1617
this.timeout(60 * 1000)
1718

1819
return ipfs('dns ipfs.io').then((res) => {
19-
expect(res.substr(0, 6)).to.eql('/ipns/')
20+
expect(res.substr(0, 6)).to.eql('/ipfs/')
21+
const resultingDomainOrCid = res.split('/')[2].trim()
22+
expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true)
2023
})
2124
})
2225

23-
it('resolve _dnslink.ipfs.io dns', function () {
26+
it('recursively resolve _dnslink.ipfs.io dns', function () {
2427
this.timeout(60 * 1000)
2528

2629
return ipfs('dns _dnslink.ipfs.io').then((res) => {
30+
expect(res.substr(0, 6)).to.eql('/ipfs/')
31+
const resultingDomainOrCid = res.split('/')[2].trim()
32+
expect(isIPFS.cid(resultingDomainOrCid)).to.eql(true)
33+
})
34+
})
35+
36+
it('non-recursive resolve ipfs.io', function () {
37+
this.timeout(60 * 1000)
38+
39+
return ipfs('dns --recursive false ipfs.io').then((res) => {
2740
expect(res.substr(0, 6)).to.eql('/ipns/')
41+
const resultingDomainOrCid = res.split('/')[2].trim()
42+
expect(isIPFS.cid(resultingDomainOrCid)).to.eql(false)
2843
})
2944
})
3045

test/core/dns.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ describe('.dns', () => {
3939

4040
// skipping because there is an error in https://ipfs.io/api/v0/dns?arg=ipfs.io
4141
// unskip once this is resolved: https://github.com/ipfs/go-ipfs/issues/6086
42-
it.skip('should resolve ipfs.io', () => {
43-
return ipfs.dns('ipfs.io').then(res => {
42+
it.skip('should non-recursively resolve ipfs.io', () => {
43+
return ipfs.dns('ipfs.io', { recursive: false }).then(res => {
4444
// matches pattern /ipns/<ipnsaddress>
4545
expect(res).to.match(/\/ipns\/.+$/)
4646
})

0 commit comments

Comments
 (0)