mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
test: update gateway tests for dir-index-html v1.1.0
This commit is contained in:
parent
9e95a82a05
commit
2feff33235
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@ -154,6 +155,11 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface
|
||||
return ts, api, n.Context()
|
||||
}
|
||||
|
||||
func matchPathOrBreadcrumbs(s string, expected string) bool {
|
||||
matched, _ := regexp.MatchString("Index of\n[\t ]*"+regexp.QuoteMeta(expected), s)
|
||||
return matched
|
||||
}
|
||||
|
||||
func TestGatewayGet(t *testing.T) {
|
||||
ns := mockNamesys{}
|
||||
ts, api, ctx := newTestServerAndNode(t, ns)
|
||||
@ -442,7 +448,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
||||
s := string(body)
|
||||
t.Logf("body: %s\n", string(body))
|
||||
|
||||
if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/") {
|
||||
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>") {
|
||||
t.Fatalf("expected a path in directory listing")
|
||||
}
|
||||
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/./..\">") {
|
||||
@ -475,7 +481,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
||||
s = string(body)
|
||||
t.Logf("body: %s\n", string(body))
|
||||
|
||||
if !strings.Contains(s, "Index of /") {
|
||||
if !matchPathOrBreadcrumbs(s, "/") {
|
||||
t.Fatalf("expected a path in directory listing")
|
||||
}
|
||||
if !strings.Contains(s, "<a href=\"/\">") {
|
||||
@ -508,7 +514,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
||||
s = string(body)
|
||||
t.Logf("body: %s\n", string(body))
|
||||
|
||||
if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/bar/") {
|
||||
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>") {
|
||||
t.Fatalf("expected a path in directory listing")
|
||||
}
|
||||
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/bar/./..\">") {
|
||||
@ -542,7 +548,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
||||
s = string(body)
|
||||
t.Logf("body: %s\n", string(body))
|
||||
|
||||
if !strings.Contains(s, "Index of /ipns/example.net") {
|
||||
if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>") {
|
||||
t.Fatalf("expected a path in directory listing")
|
||||
}
|
||||
if !strings.Contains(s, "<a href=\"/good-prefix/\">") {
|
||||
@ -584,7 +590,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
||||
s = string(body)
|
||||
t.Logf("body: %s\n", string(body))
|
||||
|
||||
if !strings.Contains(s, "Index of /") {
|
||||
if !matchPathOrBreadcrumbs(s, "/") {
|
||||
t.Fatalf("expected a path in directory listing")
|
||||
}
|
||||
if !strings.Contains(s, "<a href=\"/\">") {
|
||||
|
||||
@ -63,7 +63,7 @@ test_expect_success "HTTP GET empty directory" '
|
||||
URL="http://127.0.0.1:$port/ipfs/$HASH_EMPTY_DIR/" &&
|
||||
echo "GET $URL" &&
|
||||
curl -so outfile "$URL" 2>curl_getEmpty.out &&
|
||||
grep "Index of /ipfs/$HASH_EMPTY_DIR/" outfile
|
||||
cat outfile | tr -s "\n" " " | grep "Index of /ipfs/<a href=\"/ipfs/$HASH_EMPTY_DIR\">$HASH_EMPTY_DIR</a>"
|
||||
'
|
||||
|
||||
test_expect_success "HTTP PUT file to construct a hierarchy" '
|
||||
|
||||
Loading…
Reference in New Issue
Block a user