|
6 | 6 | "io/ioutil"
|
7 | 7 | "net/http"
|
8 | 8 | "net/http/httptest"
|
| 9 | + "regexp" |
9 | 10 | "strings"
|
10 | 11 | "testing"
|
11 | 12 | "time"
|
@@ -154,6 +155,11 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface
|
154 | 155 | return ts, api, n.Context()
|
155 | 156 | }
|
156 | 157 |
|
| 158 | +func matchPathOrBreadcrumbs(s string, expected string) bool { |
| 159 | + matched, _ := regexp.MatchString("Index of\n[\t ]*"+regexp.QuoteMeta(expected), s) |
| 160 | + return matched |
| 161 | +} |
| 162 | + |
157 | 163 | func TestGatewayGet(t *testing.T) {
|
158 | 164 | ns := mockNamesys{}
|
159 | 165 | ts, api, ctx := newTestServerAndNode(t, ns)
|
@@ -442,7 +448,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
442 | 448 | s := string(body)
|
443 | 449 | t.Logf("body: %s\n", string(body))
|
444 | 450 |
|
445 |
| - if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/") { |
| 451 | + if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>/<a href=\"/ipns/example.net/foo%3F%20%23%3C%27\">foo? #<'</a>") { |
446 | 452 | t.Fatalf("expected a path in directory listing")
|
447 | 453 | }
|
448 | 454 | if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/./..\">") {
|
@@ -475,7 +481,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
475 | 481 | s = string(body)
|
476 | 482 | t.Logf("body: %s\n", string(body))
|
477 | 483 |
|
478 |
| - if !strings.Contains(s, "Index of /") { |
| 484 | + if !matchPathOrBreadcrumbs(s, "/") { |
479 | 485 | t.Fatalf("expected a path in directory listing")
|
480 | 486 | }
|
481 | 487 | if !strings.Contains(s, "<a href=\"/\">") {
|
@@ -508,7 +514,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
508 | 514 | s = string(body)
|
509 | 515 | t.Logf("body: %s\n", string(body))
|
510 | 516 |
|
511 |
| - if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/bar/") { |
| 517 | + if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>/<a href=\"/ipns/example.net/foo%3F%20%23%3C%27\">foo? #<'</a>/<a href=\"/ipns/example.net/foo%3F%20%23%3C%27/bar\">bar</a>") { |
512 | 518 | t.Fatalf("expected a path in directory listing")
|
513 | 519 | }
|
514 | 520 | if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/bar/./..\">") {
|
@@ -542,7 +548,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
542 | 548 | s = string(body)
|
543 | 549 | t.Logf("body: %s\n", string(body))
|
544 | 550 |
|
545 |
| - if !strings.Contains(s, "Index of /ipns/example.net") { |
| 551 | + if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>") { |
546 | 552 | t.Fatalf("expected a path in directory listing")
|
547 | 553 | }
|
548 | 554 | if !strings.Contains(s, "<a href=\"/good-prefix/\">") {
|
@@ -584,7 +590,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
584 | 590 | s = string(body)
|
585 | 591 | t.Logf("body: %s\n", string(body))
|
586 | 592 |
|
587 |
| - if !strings.Contains(s, "Index of /") { |
| 593 | + if !matchPathOrBreadcrumbs(s, "/") { |
588 | 594 | t.Fatalf("expected a path in directory listing")
|
589 | 595 | }
|
590 | 596 | if !strings.Contains(s, "<a href=\"/\">") {
|
|
0 commit comments