@@ -111,30 +111,30 @@ describe('modifyRequest.onBeforeRequest:', function () {
111
111
} )
112
112
} )
113
113
114
- describe ( 'XHR request for a path matching /ipfs/{CIDv0}' , function ( ) {
114
+ describe ( 'XHR request for a path matching /ipfs/{CIDv0} coming from 3rd party Origin ' , function ( ) {
115
115
describe ( 'with external node' , function ( ) {
116
116
beforeEach ( function ( ) {
117
117
state . ipfsNodeType = 'external'
118
118
} )
119
119
it ( 'should be served from custom gateway if fetched from the same origin and redirect is enabled in Firefox' , function ( ) {
120
120
runtime . isFirefox = true
121
121
const xhrRequest = { url : 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' , type : 'xmlhttprequest' , originUrl : 'https://google.com/' }
122
- expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
122
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
123
123
} )
124
124
it ( 'should be served from custom gateway if fetched from the same origin and redirect is enabled in Chromium' , function ( ) {
125
125
runtime . isFirefox = false
126
126
const xhrRequest = { url : 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' , type : 'xmlhttprequest' , initiator : 'https://google.com/' }
127
- expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
127
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
128
128
} )
129
129
it ( 'should be served from custom gateway if XHR is cross-origin and redirect is enabled in Chromium' , function ( ) {
130
130
runtime . isFirefox = false
131
131
const xhrRequest = { url : 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' , type : 'xmlhttprequest' , initiator : 'https://www.nasa.gov/foo.html' , requestId : fakeRequestId ( ) }
132
- expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
132
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
133
133
} )
134
134
it ( 'should be served from custom gateway if XHR is cross-origin and redirect is enabled in Firefox' , function ( ) {
135
135
runtime . isFirefox = true
136
136
const xhrRequest = { url : 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' , type : 'xmlhttprequest' , originUrl : 'https://www.nasa.gov/foo.html' , requestId : fakeRequestId ( ) }
137
- expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
137
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
138
138
} )
139
139
} )
140
140
describe ( 'with embedded node' , function ( ) {
@@ -170,17 +170,17 @@ describe('modifyRequest.onBeforeRequest:', function () {
170
170
it ( 'should be served from custom gateway if fetched from the same origin and redirect is enabled in Firefox' , function ( ) {
171
171
runtime . isFirefox = true
172
172
const xhrRequest = { url : 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' , type : 'xmlhttprequest' , originUrl : 'https://google.com/' }
173
- expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
173
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
174
174
} )
175
175
it ( 'should be served from custom gateway if fetched from the same origin and redirect is enabled in non-Firefox' , function ( ) {
176
176
runtime . isFirefox = false
177
177
const xhrRequest = { url : 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' , type : 'xmlhttprequest' , initiator : 'https://google.com/' }
178
- expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
178
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
179
179
} )
180
180
it ( 'should be served from custom gateway if XHR is cross-origin and redirect is enabled in non-Firefox' , function ( ) {
181
181
runtime . isFirefox = false
182
182
const xhrRequest = { url : 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' , type : 'xmlhttprequest' , initiator : 'https://www.nasa.gov/foo.html' , requestId : fakeRequestId ( ) }
183
- expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
183
+ expect ( modifyRequest . onBeforeRequest ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
184
184
} )
185
185
it ( 'should be served from custom gateway via late redirect in onHeadersReceived if XHR is cross-origin and redirect is enabled in Firefox' , function ( ) {
186
186
// Context for CORS XHR problems in Firefox: https://github.com/ipfs-shipyard/ipfs-companion/issues/436
@@ -189,7 +189,7 @@ describe('modifyRequest.onBeforeRequest:', function () {
189
189
// onBeforeRequest should not change anything, as it will trigger false-positive CORS error
190
190
expect ( modifyRequest . onBeforeRequest ( xhrRequest ) ) . to . equal ( undefined )
191
191
// onHeadersReceived is after CORS validation happens, so its ok to cancel and redirect late
192
- expect ( modifyRequest . onHeadersReceived ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://localhost :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
192
+ expect ( modifyRequest . onHeadersReceived ( xhrRequest ) . redirectUrl ) . to . equal ( 'http://127.0.0.1 :8080/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest' )
193
193
} )
194
194
} )
195
195
} )
@@ -255,7 +255,7 @@ describe('modifyRequest.onBeforeRequest:', function () {
255
255
} )
256
256
} )
257
257
258
- describe ( 'request to a public subdomain gateway (CID in subdomain) ' , function ( ) {
258
+ describe ( 'request to a subdomain gateway' , function ( ) {
259
259
const cid = 'bafybeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge'
260
260
const peerid = 'bafzbeigxjv2o4jse2lajbd5c7xxl5rluhyqg5yupln42252e5tcao7hbge'
261
261
@@ -339,7 +339,7 @@ describe('modifyRequest.onBeforeRequest:', function () {
339
339
state . redirect = true
340
340
} )
341
341
describe ( `with ${ nodeType } node:` , function ( ) {
342
- describe ( 'request for IPFS path at a localhost' , function ( ) {
342
+ describe ( 'request for IPFS path at the localhost' , function ( ) {
343
343
// we do not touch local requests, as it may interfere with other nodes running at the same machine
344
344
// or could produce false-positives such as redirection from localhost:5001/ipfs/path to localhost:8080/ipfs/path
345
345
it ( 'should be left untouched if localhost is used' , function ( ) {
@@ -362,6 +362,16 @@ describe('modifyRequest.onBeforeRequest:', function () {
362
362
const request = url2request ( 'http://[::1]:5001/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/' )
363
363
expectNoRedirect ( modifyRequest , request )
364
364
} )
365
+ it ( 'should be redirected to localhost (subdomain in go-ipfs >0.5) if type=main_frame and 127.0.0.1 (path gw) is used un URL' , function ( ) {
366
+ state . redirect = true
367
+ state . useSubdomainProxy = true
368
+ expect ( state . gwURL . hostname ) . to . equal ( 'localhost' )
369
+ const cid = 'QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'
370
+ const request = url2request ( `http://127.0.0.1:8080/ipfs/${ cid } ?arg=val#hash` )
371
+ request . type = 'main_frame' // explicit
372
+ expect ( modifyRequest . onBeforeRequest ( request ) . redirectUrl )
373
+ . to . equal ( `http://localhost:8080/ipfs/${ cid } ?arg=val#hash` )
374
+ } )
365
375
} )
366
376
} )
367
377
} )
0 commit comments