@@ -811,15 +811,14 @@ describe('@helia/verified-fetch', () => {
811811 blockBrokerRetrieveCalledWithProviders = pDefer ( )
812812 blockRetriever = stubInterface < Required < Pick < BlockBroker , 'retrieve' | 'createSession' > > > ( {
813813 retrieve : sandbox . stub ( ) . callsFake ( async ( cid , options ) => {
814- blockBrokerRetrieveCalledWithProviders . resolve ( options . providers )
814+ blockBrokerRetrieveCalledWithProviders . resolve ( options . providers || [ ] )
815815
816816 // attempt to read from the provider
817817 // eslint-disable-next-line
818818 const stringProviders = options . providers . map ( ( p : import ( '@multiformats/multiaddr' ) . Multiaddr ) => p . toString ( ) )
819819 if ( stringProviders . includes ( provider ) ) {
820820 return helia . blockstore . get ( cid , options )
821821 }
822- throw new Error ( 'not found' )
823822 } ) ,
824823 createSession : ( ) => {
825824 return blockRetriever
@@ -848,7 +847,9 @@ describe('@helia/verified-fetch', () => {
848847 // broker retriever
849848 await helia . blockstore . put ( cid , rawData )
850849
851- const resp = await stubbedVerifiedFetch . fetch ( `ipfs://${ cid } ?provider=${ provider } ` )
850+ const resp = await stubbedVerifiedFetch . fetch ( `ipfs://${ cid } ?provider=${ provider } ` , {
851+ allowProviderParameter : true
852+ } )
852853 expect ( resp ) . to . be . ok ( )
853854 expect ( resp . status ) . to . equal ( 200 )
854855 expect ( resp . statusText ) . to . equal ( 'OK' )
@@ -880,7 +881,9 @@ describe('@helia/verified-fetch', () => {
880881 const url = `ipfs://${ cid } ?${ query } `
881882
882883 // Verify response expectations
883- const resp = await stubbedVerifiedFetch . fetch ( url )
884+ const resp = await stubbedVerifiedFetch . fetch ( url , {
885+ allowProviderParameter : true
886+ } )
884887
885888 expect ( resp ) . to . be . ok ( )
886889 expect ( resp . status ) . to . equal ( 200 )
@@ -896,6 +899,37 @@ describe('@helia/verified-fetch', () => {
896899 expect ( received ) . to . include ( p )
897900 }
898901 } )
902+
903+ it ( 'should not pass providers unless allowProviderParameter option is set' , async ( ) => {
904+ const rawData = new Uint8Array ( [ 0x01 , 0x02 , 0x03 ] )
905+ const cid = CID . createV1 ( raw . code , await sha256 . digest ( rawData ) )
906+ // Add raw data to helia (provider instance), which will be called by
907+ // broker retriever
908+ await helia . blockstore . put ( cid , rawData )
909+
910+ // prepare URL
911+ const providers = [
912+ provider ,
913+ '/dns4/provider2.io/tcp/8000/ws'
914+ ]
915+ const query = providers
916+ . map ( p => `provider=${ p } ` )
917+ . join ( '&' )
918+
919+ const url = `ipfs://${ cid } ?${ query } `
920+
921+ // Verify response expectations
922+ // Default behaviour with disabled passing providers from query parameter
923+ const resp = await stubbedVerifiedFetch . fetch ( url )
924+
925+ expect ( resp ) . to . be . ok ( )
926+ expect ( resp . status ) . to . not . equal ( 200 )
927+ expect ( resp . statusText ) . to . not . equal ( 'OK' )
928+
929+ // Verify block broker is called without providers
930+ const providerParams = await blockBrokerRetrieveCalledWithProviders . promise
931+ expect ( providerParams . length ) . to . equal ( 0 )
932+ } )
899933 } )
900934
901935 describe ( '?format' , ( ) => {
0 commit comments