@@ -213,6 +213,30 @@ func TestIPNSHostnameRedirect(t *testing.T) {
213
213
} else if hdr [0 ] != "/foo/" {
214
214
t .Errorf ("location header is %v, expected /foo/" , hdr [0 ])
215
215
}
216
+
217
+ // make request with prefix to directory containing index.html
218
+ req , err = http .NewRequest ("GET" , ts .URL + "/foo" , nil )
219
+ if err != nil {
220
+ t .Fatal (err )
221
+ }
222
+ req .Host = "example.net"
223
+ req .Header .Set ("X-Ipfs-Gateway-Prefix" , "/prefix" )
224
+
225
+ res , err = doWithoutRedirect (req )
226
+ if err != nil {
227
+ t .Fatal (err )
228
+ }
229
+
230
+ // expect 302 redirect to same path, but with prefix and trailing slash
231
+ if res .StatusCode != 302 {
232
+ t .Errorf ("status is %d, expected 302" , res .StatusCode )
233
+ }
234
+ hdr = res .Header ["Location" ]
235
+ if len (hdr ) < 1 {
236
+ t .Errorf ("location header not present" )
237
+ } else if hdr [0 ] != "/prefix/foo/" {
238
+ t .Errorf ("location header is %v, expected /prefix/foo/" , hdr [0 ])
239
+ }
216
240
}
217
241
218
242
func TestIPNSHostnameBacklinks (t * testing.T ) {
@@ -282,7 +306,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
282
306
t .Fatalf ("expected file in directory listing" )
283
307
}
284
308
285
- // make request to directory listing
309
+ // make request to directory listing at root
286
310
req , err = http .NewRequest ("GET" , ts .URL , nil )
287
311
if err != nil {
288
312
t .Fatal (err )
@@ -294,7 +318,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
294
318
t .Fatal (err )
295
319
}
296
320
297
- // expect correct backlinks
321
+ // expect correct backlinks at root
298
322
body , err = ioutil .ReadAll (res .Body )
299
323
if err != nil {
300
324
t .Fatalf ("error reading response: %s" , err )
@@ -341,4 +365,35 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
341
365
if ! strings .Contains (s , "<a href=\" /foo/bar/file.txt\" >" ) {
342
366
t .Fatalf ("expected file in directory listing" )
343
367
}
368
+
369
+ // make request to directory listing with prefix
370
+ req , err = http .NewRequest ("GET" , ts .URL , nil )
371
+ if err != nil {
372
+ t .Fatal (err )
373
+ }
374
+ req .Host = "example.net"
375
+ req .Header .Set ("X-Ipfs-Gateway-Prefix" , "/prefix" )
376
+
377
+ res , err = doWithoutRedirect (req )
378
+ if err != nil {
379
+ t .Fatal (err )
380
+ }
381
+
382
+ // expect correct backlinks with prefix
383
+ body , err = ioutil .ReadAll (res .Body )
384
+ if err != nil {
385
+ t .Fatalf ("error reading response: %s" , err )
386
+ }
387
+ s = string (body )
388
+ t .Logf ("body: %s\n " , string (body ))
389
+
390
+ if ! strings .Contains (s , "Index of /prefix" ) {
391
+ t .Fatalf ("expected a path in directory listing" )
392
+ }
393
+ if ! strings .Contains (s , "<a href=\" /prefix/\" >" ) {
394
+ t .Fatalf ("expected backlink in directory listing" )
395
+ }
396
+ if ! strings .Contains (s , "<a href=\" /prefix/file.txt\" >" ) {
397
+ t .Fatalf ("expected file in directory listing" )
398
+ }
344
399
}
0 commit comments