@@ -183,6 +183,20 @@ describe('modifyRequest processing', function () {
183
183
const xhrRequest = { url : 'http://explore.ipld.io/index.html?argTest#hashTest' , type : 'xmlhttprequest' , originUrl : 'https://www.nasa.gov/foo.html' , requestId : fakeRequestId ( ) }
184
184
expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest' )
185
185
} )
186
+ it ( 'should redirect later in onHeadersReceived if dnslink exists, XHR is cross-origin and runtime is Firefox <69' , function ( ) {
187
+ // stub existence of a valid DNS record
188
+ const fqdn = 'explore.ipld.io'
189
+ dnslinkResolver . readDnslinkFromTxtRecord = sinon . stub ( ) . withArgs ( fqdn ) . returns ( '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' )
190
+ //
191
+ // Context for CORS XHR problems in Firefox <69: https://github.com/ipfs-shipyard/ipfs-companion/issues/436
192
+ runtime . requiresXHRCORSfix = true
193
+ // Firefox uses 'originUrl' for origin
194
+ const xhrRequest = { url : 'http://explore.ipld.io/index.html?argTest#hashTest' , type : 'xmlhttprequest' , originUrl : 'https://www.nasa.gov/foo.html' , requestId : fakeRequestId ( ) }
195
+ // onBeforeRequest should not change anything, as it will trigger false-positive CORS error
196
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) ) . to . equal ( undefined )
197
+ // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late
198
+ expect ( modifyRequest . onHeadersReceived ( xhrRequest ) . redirectUrl ) . to . equal ( activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest' )
199
+ } )
186
200
it ( 'should do nothing if dnslink does not exist and XHR is cross-origin in Firefox' , function ( ) {
187
201
// stub no dnslink
188
202
const fqdn = 'youtube.com'
@@ -286,6 +300,19 @@ describe('modifyRequest processing', function () {
286
300
xhrRequest . responseHeaders = [ { name : 'X-Ipfs-Path' , value : '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' } ]
287
301
expect ( modifyRequest . onHeadersReceived ( xhrRequest ) . redirectUrl ) . to . equal ( activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest' )
288
302
} )
303
+ it ( 'should redirect later in onHeadersReceived if XHR is cross-origin and runtime is Firefox <69' , function ( ) {
304
+ // stub existence of a valid DNS record
305
+ const fqdn = 'explore.ipld.io'
306
+ dnslinkResolver . setDnslink ( fqdn , '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' )
307
+ //
308
+ // Context for CORS XHR problems in Firefox <69: https://github.com/ipfs-shipyard/ipfs-companion/issues/436
309
+ runtime . requiresXHRCORSfix = true
310
+ const xhrRequest = { url : 'http://explore.ipld.io/index.html?argTest#hashTest' , type : 'xmlhttprequest' , originUrl : 'https://www.nasa.gov/foo.html' , requestId : fakeRequestId ( ) }
311
+ // onBeforeRequest should not change anything, as it will trigger false-positive CORS error
312
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) ) . to . equal ( undefined )
313
+ // onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late
314
+ expect ( modifyRequest . onHeadersReceived ( xhrRequest ) . redirectUrl ) . to . equal ( activeGateway + '/ipns/explore.ipld.io/index.html?argTest#hashTest' )
315
+ } )
289
316
// Test makes more sense for dnslinkPolicy=enabled, but we keep it here for completeness
290
317
it ( 'should do nothing if DNS TXT record is missing and XHR is cross-origin in Firefox' , function ( ) {
291
318
// stub no dnslink
0 commit comments