Skip to content

Commit

Permalink
test(gw): add t0115-gateway-dir-listing.sh to sharness
Browse files Browse the repository at this point in the history
This adds proper end-to-end tests for directory listing on Gateway port
that protects us against regressions oni each gw type:
- path gateway
- subdomain gateway
- dnslink website gateway

Tests cover:
- etag/unicode support
- breadcrumbs
- file name column
- hash column


This commit was moved from ipfs/kubo@3ed46d9
  • Loading branch information
lidel committed Sep 29, 2020
1 parent 0872de9 commit 60703d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 0 additions & 4 deletions gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,6 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
Hash: hash,
}

// TODO: remove logging below
// tplDataJSON, _ := json.MarshalIndent(tplData, "", " ")
// fmt.Println(string(tplDataJSON))

err = listingTemplate.Execute(w, tplData)
if err != nil {
internalWebError(w, err)
Expand Down
4 changes: 2 additions & 2 deletions gateway/core/corehttp/gateway_indexPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func shortHash(hash string) string {
// (when hostname from gwURL is matching /ipns/<fqdn> in path)
func hasDNSLinkOrigin(gwURL string, path string) bool {
if gwURL != "" {
dnslinkRoot := strings.Replace(gwURL, "//", "/ipns/", 1)
return strings.HasPrefix(path, dnslinkRoot)
fqdn := stripPort(strings.TrimPrefix(gwURL, "//"))
return strings.HasPrefix(path, "/ipns/"+fqdn)
}
return false
}
Expand Down
12 changes: 11 additions & 1 deletion gateway/core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ func TestIPNSHostnameRedirect(t *testing.T) {

// Test directory listing on DNSLink website
// (scenario when Host header is the same as URL hostname)
// This is basic regression test: additional end-to-end tests
// can be found in test/sharness/t0115-gateway-dir-listing.sh
func TestIPNSHostnameBacklinks(t *testing.T) {
ns := mockNamesys{}
ts, api, ctx := newTestServerAndNode(t, ns)
Expand Down Expand Up @@ -439,7 +441,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
t.Fatal(err)
}

// expect correct backlinks
// expect correct links
body, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Fatalf("error reading response: %s", err)
Expand All @@ -456,6 +458,10 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, "<a class=\"ipfs-hash\" href=\"https://cid.ipfs.io/#") {
// https://github.com/ipfs/dir-index-html/issues/42
t.Fatalf("expected links to cid.ipfs.io in CID column when on DNSLink website")
}
if !strings.Contains(s, k2.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}
Expand Down Expand Up @@ -489,6 +495,10 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, "<a class=\"ipfs-hash\" href=\"https://cid.ipfs.io/#") {
// https://github.com/ipfs/dir-index-html/issues/42
t.Fatalf("expected links to cid.ipfs.io in CID column when on DNSLink website")
}
if !strings.Contains(s, k.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}
Expand Down

0 comments on commit 60703d4

Please sign in to comment.