-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: customize ipns dnsResolvers (#445)
* feat(verified-fetch): customize ipns dnsResolvers * chore: pr comment Co-authored-by: Alex Potsides <alex@achingbrain.net> * test: fix dns-resolvers test * chore: harden custom dns resolver test * test: actually fix the custom dns resolver test The test was passing when ran in isolation, but not in the group. dns caching was causing problems so i customized the url * chore: firefox promise.any aggregate name is different * fix: createVerifiedFetch passes through custom dnsResolvers * docs: jsdoc fix from pr comment Co-authored-by: Alex Potsides <alex@achingbrain.net> * test: move custom-dns-resolvers tests * test: move content-type-parser test * docs: typo Co-authored-by: Alex Potsides <alex@achingbrain.net> * fix: dnsResolvers is passed in first arg to createVerifiedFetch --------- Co-authored-by: Alex Potsides <alex@achingbrain.net>
- Loading branch information
1 parent
e92086a
commit 8f60822
Showing
4 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { stop } from '@libp2p/interface' | ||
import { expect } from 'aegir/chai' | ||
import Sinon from 'sinon' | ||
import { createVerifiedFetch } from '../src/index.js' | ||
import { VerifiedFetch } from '../src/verified-fetch.js' | ||
import { createHelia } from './fixtures/create-offline-helia.js' | ||
import type { Helia } from '@helia/interface' | ||
|
||
describe('custom dns-resolvers', () => { | ||
let helia: Helia | ||
|
||
beforeEach(async () => { | ||
helia = await createHelia() | ||
}) | ||
|
||
afterEach(async () => { | ||
await stop(helia) | ||
}) | ||
|
||
it('is used when passed to createVerifiedFetch', async () => { | ||
const customDnsResolver = Sinon.stub() | ||
|
||
customDnsResolver.returns(Promise.resolve('/ipfs/QmVP2ip92jQuMDezVSzQBWDqWFbp9nyCHNQSiciRauPLDg')) | ||
|
||
const fetch = await createVerifiedFetch({ | ||
gateways: ['http://127.0.0.1:8080'], | ||
dnsResolvers: [customDnsResolver] | ||
}) | ||
// error of walking the CID/dag because we haven't actually added the block to the blockstore | ||
await expect(fetch('ipns://some-non-cached-domain.com')).to.eventually.be.rejected.with.property('errors') | ||
|
||
expect(customDnsResolver.callCount).to.equal(1) | ||
expect(customDnsResolver.getCall(0).args).to.deep.equal(['some-non-cached-domain.com', { onProgress: undefined }]) | ||
}) | ||
|
||
it('is used when passed to VerifiedFetch', async () => { | ||
const customDnsResolver = Sinon.stub() | ||
|
||
customDnsResolver.returns(Promise.resolve('/ipfs/QmVP2ip92jQuMDezVSzQBWDqWFbp9nyCHNQSiciRauPLDg')) | ||
|
||
const verifiedFetch = new VerifiedFetch({ | ||
helia | ||
}, { | ||
dnsResolvers: [customDnsResolver] | ||
}) | ||
// error of walking the CID/dag because we haven't actually added the block to the blockstore | ||
await expect(verifiedFetch.fetch('ipns://some-non-cached-domain2.com')).to.eventually.be.rejected.with.property('errors').that.has.lengthOf(0) | ||
|
||
expect(customDnsResolver.callCount).to.equal(1) | ||
expect(customDnsResolver.getCall(0).args).to.deep.equal(['some-non-cached-domain2.com', { onProgress: undefined }]) | ||
}) | ||
}) |