@cryptotaxi247 / kubo / commits / 2feff3323

test: update gateway tests for dir-index-html v1.1.0

Kevin Neaton committed Jul 25, 2020 at 23:13 UTC 2feff332354b376a211c956902e0ad64de61fa0c
2 files changed +12 -6
core/corehttp/gateway_test.go
+11 -5
@@ -6,6 +6,7 @@ import (
6 "io/ioutil"
7 "net/http"
8 "net/http/httptest"
9 + "regexp"
10 "strings"
11 "testing"
12 "time"
@@ -154,6 +155,11 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface
155 return ts, api, n.Context()
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 +
163 func TestGatewayGet(t *testing.T) {
164 ns := mockNamesys{}
165 ts, api, ctx := newTestServerAndNode(t, ns)
@@ -442,7 +448,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
448 s := string(body)
449 t.Logf("body: %s\n", string(body))
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? #&lt;&#39;</a>") {
452 t.Fatalf("expected a path in directory listing")
453 }
454 if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/./..\">") {
@@ -475,7 +481,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
481 s = string(body)
482 t.Logf("body: %s\n", string(body))
483
478 - if !strings.Contains(s, "Index of /") {
484 + if !matchPathOrBreadcrumbs(s, "/") {
485 t.Fatalf("expected a path in directory listing")
486 }
487 if !strings.Contains(s, "<a href=\"/\">") {
@@ -508,7 +514,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
514 s = string(body)
515 t.Logf("body: %s\n", string(body))
516
511 - if !strings.Contains(s, "Index of /ipns/example.net/foo? #&lt;&#39;/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? #&lt;&#39;</a>/<a href=\"/ipns/example.net/foo%3F%20%23%3C%27/bar\">bar</a>") {
518 t.Fatalf("expected a path in directory listing")
519 }
520 if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/bar/./..\">") {
@@ -542,7 +548,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
548 s = string(body)
549 t.Logf("body: %s\n", string(body))
550
545 - if !strings.Contains(s, "Index of /ipns/example.net") {
551 + if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>") {
552 t.Fatalf("expected a path in directory listing")
553 }
554 if !strings.Contains(s, "<a href=\"/good-prefix/\">") {
@@ -584,7 +590,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
590 s = string(body)
591 t.Logf("body: %s\n", string(body))
592
587 - if !strings.Contains(s, "Index of /") {
593 + if !matchPathOrBreadcrumbs(s, "/") {
594 t.Fatalf("expected a path in directory listing")
595 }
596 if !strings.Contains(s, "<a href=\"/\">") {
test/sharness/t0111-gateway-writeable.sh
+1 -1
@@ -63,7 +63,7 @@ test_expect_success "HTTP GET empty directory" '
63 URL="http://127.0.0.1:$port/ipfs/$HASH_EMPTY_DIR/" &&
64 echo "GET $URL" &&
65 curl -so outfile "$URL" 2>curl_getEmpty.out &&
66 - grep "Index of /ipfs/$HASH_EMPTY_DIR/" outfile
66 + cat outfile | tr -s "\n" " " | grep "Index of /ipfs/<a href=\"/ipfs/$HASH_EMPTY_DIR\">$HASH_EMPTY_DIR</a>"
67 '
68
69 test_expect_success "HTTP PUT file to construct a hierarchy" '