-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dnslink-gw): breadcrumbs and CID column when dir listing #7699
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule dir-index-html
updated
6 files
+3 −4 | .github/workflows/build.yml | |
+54 −0 | CHANGELOG.md | |
+2 −2 | dir-index.html | |
+3 −2 | package.json | |
+1 −1 | src/dir-index.html | |
+12 −4 | test/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright (c) Protocol Labs | ||
|
||
test_description="Test directory listing (dir-index-html) on the HTTP gateway" | ||
|
||
|
||
. lib/test-lib.sh | ||
|
||
## ============================================================================ | ||
## Start IPFS Node and prepare test CIDs | ||
## ============================================================================ | ||
|
||
test_expect_success "ipfs init" ' | ||
export IPFS_PATH="$(pwd)/.ipfs" && | ||
ipfs init --profile=test > /dev/null | ||
' | ||
|
||
test_launch_ipfs_daemon --offline | ||
|
||
test_expect_success "Add the test directory" ' | ||
mkdir -p rootDir/ipfs && | ||
mkdir -p rootDir/ipns && | ||
mkdir -p rootDir/api && | ||
mkdir -p rootDir/ą/ę && | ||
echo "I am a txt file on path with utf8" > rootDir/ą/ę/file-źł.txt && | ||
echo "I am a txt file in confusing /api dir" > rootDir/api/file.txt && | ||
echo "I am a txt file in confusing /ipfs dir" > rootDir/ipfs/file.txt && | ||
echo "I am a txt file in confusing /ipns dir" > rootDir/ipns/file.txt && | ||
DIR_CID=$(ipfs add -Qr --cid-version 1 rootDir) && | ||
FILE_CID=$(ipfs files stat /ipfs/$DIR_CID/ą/ę/file-źł.txt | head -1) | ||
' | ||
|
||
## ============================================================================ | ||
## Test dir listing on path gateway (eg. 127.0.0.1:8080/ipfs/) | ||
## ============================================================================ | ||
|
||
test_expect_success "path gw: backlink on root CID should point at self" ' | ||
curl -sD - http://127.0.0.1:$GWAY_PORT/ipfs/${DIR_CID}/ > list_response && | ||
test_should_contain "Index of" list_response && | ||
test_should_contain "<a href=\"/ipfs/$DIR_CID/\">..</a>" list_response | ||
' | ||
|
||
test_expect_success "path gw: Etag should be present" ' | ||
curl -sD - http://127.0.0.1:$GWAY_PORT/ipfs/${DIR_CID}/ą/ę > list_response && | ||
test_should_contain "Index of" list_response && | ||
test_should_contain "Etag: \"DirIndex-" list_response | ||
' | ||
|
||
test_expect_success "path gw: breadcrumbs should point at /ipfs namespace mounted at Origin root" ' | ||
test_should_contain "/ipfs/<a href=\"/ipfs/$DIR_CID\">$DIR_CID</a>/<a href=\"/ipfs/$DIR_CID/%C4%85\">ą</a>/<a href=\"/ipfs/$DIR_CID/%C4%85/%C4%99\">ę</a>" list_response | ||
' | ||
|
||
test_expect_success "path gw: backlink should point at parent directory" ' | ||
test_should_contain "<a href=\"/ipfs/$DIR_CID/%C4%85/%C4%99/..\">..</a>" list_response | ||
' | ||
|
||
test_expect_success "path gw: name column should be a link to its content path" ' | ||
test_should_contain "<a href=\"/ipfs/$DIR_CID/%C4%85/%C4%99/file-%C5%BA%C5%82.txt\">file-źł.txt</a>" list_response | ||
' | ||
|
||
test_expect_success "path gw: hash column should be a CID link with filename param" ' | ||
test_should_contain "<a class=\"ipfs-hash\" href=\"/ipfs/$FILE_CID?filename=file-%25C5%25BA%25C5%2582.txt\">" list_response | ||
' | ||
|
||
## ============================================================================ | ||
## Test dir listing on subdomain gateway (eg. <cid>.ipfs.localhost:8080) | ||
## ============================================================================ | ||
|
||
DIR_HOSTNAME="${DIR_CID}.ipfs.localhost" | ||
# note: we skip DNS lookup by running curl with --resolve $DIR_HOSTNAME:127.0.0.1 | ||
|
||
test_expect_success "path gw: backlink on root CID should point origin root" ' | ||
curl -sD - --resolve $DIR_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DIR_HOSTNAME:$GWAY_PORT/ > list_response && | ||
test_should_contain "Index of" list_response && | ||
test_should_contain "<a href=\"/\">..</a>" list_response | ||
' | ||
|
||
test_expect_success "path gw: Etag should be present" ' | ||
curl -sD - --resolve $DIR_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DIR_HOSTNAME:$GWAY_PORT/ą/ę > list_response && | ||
test_should_contain "Index of" list_response && | ||
test_should_contain "Etag: \"DirIndex-" list_response | ||
' | ||
|
||
test_expect_success "subdomain gw: breadcrumbs should leverage path-based router mounted on the parent domain" ' | ||
test_should_contain "/ipfs/<a href=\"//localhost:$GWAY_PORT/ipfs/$DIR_CID\">$DIR_CID</a>/<a href=\"//localhost:$GWAY_PORT/ipfs/$DIR_CID/%C4%85\">ą</a>/<a href=\"//localhost:$GWAY_PORT/ipfs/$DIR_CID/%C4%85/%C4%99\">ę</a>" list_response | ||
' | ||
|
||
test_expect_success "path gw: name column should be a link to content root mounted at subdomain origin" ' | ||
test_should_contain "<a href=\"/%C4%85/%C4%99/file-%C5%BA%C5%82.txt\">file-źł.txt</a>" list_response | ||
' | ||
|
||
test_expect_success "path gw: hash column should be a CID link to path router with filename param" ' | ||
test_should_contain "<a class=\"ipfs-hash\" href=\"//localhost:$GWAY_PORT/ipfs/$FILE_CID?filename=file-%25C5%25BA%25C5%2582.txt\">" list_response | ||
' | ||
|
||
## ============================================================================ | ||
## Test dir listing on DNSLink gateway (eg. example.com) | ||
## ============================================================================ | ||
|
||
# DNSLink test requires a daemon in online mode with precached /ipns/ mapping | ||
test_kill_ipfs_daemon | ||
DNSLINK_HOSTNAME="website.example.com" | ||
export IPFS_NS_MAP="$DNSLINK_HOSTNAME:/ipfs/$DIR_CID" | ||
test_launch_ipfs_daemon | ||
|
||
# Note that: | ||
# - this type of gateway is also tested in gateway_test.go#TestIPNSHostnameBacklinks | ||
# (go tests and sharness tests should be kept in sync) | ||
# - we skip DNS lookup by running curl with --resolve $DNSLINK_HOSTNAME:127.0.0.1 | ||
|
||
test_expect_success "dnslink gw: backlink on root CID should point origin root" ' | ||
curl -v -sD - --resolve $DNSLINK_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DNSLINK_HOSTNAME:$GWAY_PORT/ > list_response && | ||
test_should_contain "Index of" list_response && | ||
test_should_contain "<a href=\"/\">..</a>" list_response | ||
' | ||
|
||
test_expect_success "dnslink gw: Etag should be present" ' | ||
curl -sD - --resolve $DNSLINK_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DNSLINK_HOSTNAME:$GWAY_PORT/ą/ę > list_response && | ||
test_should_contain "Index of" list_response && | ||
test_should_contain "Etag: \"DirIndex-" list_response | ||
' | ||
|
||
test_expect_success "dnslink gw: breadcrumbs should point at content root mounted at dnslink origin" ' | ||
test_should_contain "/ipns/<a href=\"//$DNSLINK_HOSTNAME:$GWAY_PORT/\">website.example.com</a>/<a href=\"//$DNSLINK_HOSTNAME:$GWAY_PORT/%C4%85\">ą</a>/<a href=\"//$DNSLINK_HOSTNAME:$GWAY_PORT/%C4%85/%C4%99\">ę</a>" list_response | ||
' | ||
|
||
test_expect_success "dnslink gw: name column should be a link to content root mounted at dnslink origin" ' | ||
test_should_contain "<a href=\"/%C4%85/%C4%99/file-%C5%BA%C5%82.txt\">file-źł.txt</a>" list_response | ||
' | ||
|
||
# DNSLink websites don't have public gateway mounted by default | ||
# See: https://github.com/ipfs/dir-index-html/issues/42 | ||
test_expect_success "dnslink gw: hash column should be a CID link to cid.ipfs.io" ' | ||
test_should_contain "<a class=\"ipfs-hash\" href=\"https://cid.ipfs.io/#$FILE_CID\" target=\"_blank\" rel=\"noreferrer noopener\">" list_response | ||
' | ||
|
||
## ============================================================================ | ||
## End of tests, cleanup | ||
## ============================================================================ | ||
|
||
test_kill_ipfs_daemon | ||
test_expect_success "clean up ipfs dir" ' | ||
rm -rf "$IPFS_PATH" | ||
' | ||
test_done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭
This file adds proper end-to-end tests for directory listing on Gateway port that protects us against regressions such as ipfs/dir-index-html#42 by testing each gateway type:
We check behavior of:
This level of testing is necessary, because URIs will be different on each gw type, and we literally had no tests for this apart from subdomain ones. Now we test all gw types and I can sleep better ;)