Skip to content

Commit

Permalink
chore: add test for never-ending recursion (#375)
Browse files Browse the repository at this point in the history
Ensure we don't loop forever resolving dns addrs that resolve to
themselves.
  • Loading branch information
achingbrain authored Mar 14, 2024
1 parent 194956f commit 59309b0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/resolvers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const stubs: Record<string, string[]> = {
],
'_dnsaddr.am6.bootstrap.libp2p.io': [
'dnsaddr=/ip4/147.75.83.83/tcp/4001/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb'
],
'_dnsaddr.self-referential.io': [
'dnsaddr=/dnsaddr/self-referential.io'
]
}

Expand Down Expand Up @@ -143,5 +146,17 @@ describe('multiaddr resolve', () => {

await expect(resolvePromise).to.eventually.be.rejected().with.property('code', 'ERR_MAX_RECURSIVE_DEPTH_REACHED')
})

it('should handle recursive loops', async () => {
const ma = multiaddr('/dnsaddr/self-referential.io')

// Resolve
const resolvePromise = ma.resolve({
dns,
maxRecursiveDepth: 1
})

await expect(resolvePromise).to.eventually.be.rejected().with.property('code', 'ERR_MAX_RECURSIVE_DEPTH_REACHED')
})
})
})

0 comments on commit 59309b0

Please sign in to comment.