-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Etag, X-Ipfs-Path and X-Ipfs-Roots
This documents the current behavior of mentioned headers. It helped to identify a a bug around index.html responses having etag of a dir-index-html (to be fixed in a separate change)
- Loading branch information
Showing
3 changed files
with
137 additions
and
21 deletions.
There are no files selected for viewing
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,88 @@ | ||
#!/usr/bin/env bash | ||
|
||
test_description="Test HTTP Gateway Cache Control Support" | ||
|
||
. lib/test-lib.sh | ||
|
||
test_init_ipfs | ||
test_launch_ipfs_daemon_without_network | ||
|
||
# Cache control support is based on logical roots (each path segment == one logical root). | ||
# To maximize the test surface, we want to test: | ||
# - /ipfs/ content path | ||
# - /ipns/ content path | ||
# - at least 3 levels | ||
# - separate tests for a directory listing and a file | ||
# - have implicit index.html for a good measure | ||
# /ipns/root1/root2/root3/ (/ipns/root1/root2/root3/index.html) | ||
|
||
test_expect_success "Add the test directory" ' | ||
mkdir -p root2/root3 && | ||
echo "hello" > root2/root3/index.html && | ||
ROOT1_CID=$(ipfs add -Qrw --cid-version 1 root2) | ||
ROOT2_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2 | cut -d "/" -f3) | ||
ROOT3_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3 | cut -d "/" -f3) | ||
FILE_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3/index.html | cut -d "/" -f3) | ||
' | ||
|
||
test_expect_success "Prepare IPNS unixfs content path for testing" ' | ||
TEST_IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 cache_test_key | head -n1 | tr -d "\n") | ||
ipfs name publish --key cache_test_key --allow-offline -Q "/ipfs/$ROOT1_CID" > name_publish_out && | ||
test_check_peerid "${TEST_IPNS_ID}" && | ||
ipfs name resolve "${TEST_IPNS_ID}" > output && | ||
printf "/ipfs/%s\n" "$ROOT1_CID" > expected && | ||
test_cmp expected output | ||
' | ||
|
||
test_expect_success "GET for /ipfs/ unixfs dir index succeeds" ' | ||
curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/" >/dev/null 2>curl_ipfs_dir_output && | ||
cat curl_ipfs_dir_output | ||
' | ||
test_expect_success "GET for /ipfs/ unixfs file succeeds" ' | ||
curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/index.html" >/dev/null 2>curl_ipfs_file_output && | ||
cat curl_ipfs_file_output | ||
' | ||
test_expect_success "GET for /ipns/ unixfs dir index succeeds" ' | ||
curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/" >/dev/null 2>curl_ipns_dir_output && | ||
cat curl_ipns_dir_output | ||
' | ||
test_expect_success "GET for /ipns/ unixfs file succeeds" ' | ||
curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/index.html" >/dev/null 2>curl_ipns_file_output && | ||
cat curl_ipns_file_output | ||
' | ||
|
||
# X-Ipfs-Path | ||
test_expect_success "GET /ipfs/ response has original content path in X-Ipfs-Path" ' | ||
grep "< X-Ipfs-Path: /ipfs/$ROOT1_CID/root2/root3" curl_ipfs_dir_output | ||
' | ||
test_expect_success "GET /ipns/ response has original content path in X-Ipfs-Path" ' | ||
grep "< X-Ipfs-Path: /ipns/$TEST_IPNS_ID/root2/root3" curl_ipns_dir_output | ||
' | ||
|
||
# X-Ipfs-Roots | ||
test_expect_success "GET /ipfs/ response has logical CID roots in X-Ipfs-Roots" ' | ||
grep "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID}" curl_ipfs_dir_output | ||
' | ||
test_expect_success "GET /ipns/ response has logical CID roots in X-Ipfs-Roots" ' | ||
grep "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID}" curl_ipns_dir_output | ||
' | ||
|
||
# Etag for DirIndex | ||
test_expect_success "GET /ipfs/ response has special Etag for unixfs dir listing" ' | ||
grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipfs_dir_output | ||
' | ||
test_expect_success "GET /ipns/ response has special Etag for unixfs dir listing" ' | ||
grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipns_dir_output | ||
' | ||
|
||
# Etag for a file | ||
test_expect_success "GET /ipfs/ response has CID as Etag for a file" ' | ||
grep -E "< Etag: \"${FILE_CID}\"" curl_ipfs_file_output | ||
' | ||
test_expect_success "GET /ipns/ response has CID as Etag for a file" ' | ||
grep -E "< Etag: \"${FILE_CID}\"" curl_ipns_file_output | ||
' | ||
|
||
test_kill_ipfs_daemon | ||
|
||
test_done |
File renamed without changes.