Skip to content

Commit

Permalink
option for 0 redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed Mar 31, 2021
1 parent 618d530 commit 7a488de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function createDatDNS (datDnsOpts) {
var ignoreCachedMiss = opts && opts.ignoreCachedMiss
var noDnsOverHttps = opts && opts.noDnsOverHttps
var noWellknownDat = opts && opts.noWellknownDat
var followRedirects = (opts && opts.followRedirects) || DEFAULT_FOLLOW_REDIRECTS
var followRedirects = (opts && opts.followRedirects >= 0) ? opts.followRedirects : DEFAULT_FOLLOW_REDIRECTS
return maybe(cb, _asyncToGenerator(function * () {
// parse the name as needed
var nameParsed = url.parse(name)
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ tape('Fail test against dns-test-setup-2.dat-ecosystem.org (well-known, multiple
})
})

tape('Fail with zero redirects dns-test-setup-2.dat-ecosystem.org (well-known, multiple, exceeding redirects)', function (t) {
const datDnsHop3 = require('./index')({ recordName: 'dat-hop-3' })
datDnsHop3.resolveName('dns-test-setup-2.dat-ecosystem.org', {noDnsOverHttps: true, ignoreCache: true, followRedirects: 0})
.then(name => {
t.equals(name, '222231b5589a5099aa3610a8ee550dcd454c3e33f4cac93b7d41b6b850cde222')
return datDnsHop3.resolveName('dns-test-setup-2.dat-ecosystem.org')
.then(() => {
t.fail('Dont expect to succeed')
t.end()
})
})
.catch(err => {
t.equals(err.message, 'Well known record lookup exceeded redirection limit: 0')
t.end()
})
})

tape('List cache', function (t) {
t.is(Object.keys(datDns.listCache()).length, 6)
t.end()
Expand Down

0 comments on commit 7a488de

Please sign in to comment.