98
ts.Listener,
99
VersionOption(),
100
IPNSHostnameOption(),
101
- GatewayOption(false),
101
+ GatewayOption(false, []string{"/good-prefix"}),
102
)
103
if err != nil {
104
t.Fatal(err)
227
t.Fatal(err)
228
}
229
req.Host = "example.net"
230
- req.Header.Set("X-Ipfs-Gateway-Prefix", "/prefix")
230
+ req.Header.Set("X-Ipfs-Gateway-Prefix", "/good-prefix")
231
232
res, err = doWithoutRedirect(req)
233
if err != nil {
241
hdr = res.Header["Location"]
242
if len(hdr) < 1 {
243
t.Errorf("location header not present")
244
- } else if hdr[0] != "/prefix/foo/" {
245
- t.Errorf("location header is %v, expected /prefix/foo/", hdr[0])
244
+ } else if hdr[0] != "/good-prefix/foo/" {
245
+ t.Errorf("location header is %v, expected /good-prefix/foo/", hdr[0])
246
}
247
}
248
387
t.Fatal(err)
388
}
389
req.Host = "example.net"
390
- req.Header.Set("X-Ipfs-Gateway-Prefix", "/prefix")
390
+ req.Header.Set("X-Ipfs-Gateway-Prefix", "/good-prefix")
391
392
res, err = doWithoutRedirect(req)
393
if err != nil {
402
s = string(body)
403
t.Logf("body: %s\n", string(body))
404
405
- if !strings.Contains(s, "Index of /prefix") {
405
+ if !strings.Contains(s, "Index of /good-prefix") {
406
t.Fatalf("expected a path in directory listing")
407
}
408
- if !strings.Contains(s, "<a href=\"/prefix/\">") {
408
+ if !strings.Contains(s, "<a href=\"/good-prefix/\">") {
409
t.Fatalf("expected backlink in directory listing")
410
}
411
- if !strings.Contains(s, "<a href=\"/prefix/file.txt\">") {
411
+ if !strings.Contains(s, "<a href=\"/good-prefix/file.txt\">") {
412
+ t.Fatalf("expected file in directory listing")
413
+ }
414
+
415
+ // make request to directory listing with illegal prefix
416
+ req, err = http.NewRequest("GET", ts.URL, nil)
417
+ if err != nil {
418
+ t.Fatal(err)
419
+ }
420
+ req.Host = "example.net"
421
+ req.Header.Set("X-Ipfs-Gateway-Prefix", "/bad-prefix")
422
+
423
+ res, err = doWithoutRedirect(req)
424
+ if err != nil {
425
+ t.Fatal(err)
426
+ }
427
+
428
+ // make request to directory listing with evil prefix
429
+ req, err = http.NewRequest("GET", ts.URL, nil)
430
+ if err != nil {
431
+ t.Fatal(err)
432
+ }
433
+ req.Host = "example.net"
434
+ req.Header.Set("X-Ipfs-Gateway-Prefix", "//good-prefix/foo")
435
+
436
+ res, err = doWithoutRedirect(req)
437
+ if err != nil {
438
+ t.Fatal(err)
439
+ }
440
+
441
+ // expect correct backlinks without illegal prefix
442
+ body, err = ioutil.ReadAll(res.Body)
443
+ if err != nil {
444
+ t.Fatalf("error reading response: %s", err)
445
+ }
446
+ s = string(body)
447
+ t.Logf("body: %s\n", string(body))
448
+
449
+ if !strings.Contains(s, "Index of /") {
450
+ t.Fatalf("expected a path in directory listing")
451
+ }
452
+ if !strings.Contains(s, "<a href=\"/\">") {
453
+ t.Fatalf("expected backlink in directory listing")
454
+ }
455
+ if !strings.Contains(s, "<a href=\"/file.txt\">") {
456
t.Fatalf("expected file in directory listing")
457
}
458
}