| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | test_description="Test HTTP Gateway Cache Control Support" |
| 4 | |
| 5 | . lib/test-lib.sh |
| 6 | |
| 7 | test_init_ipfs |
| 8 | test_launch_ipfs_daemon_without_network |
| 9 | |
| 10 | # Cache control support is based on logical roots (each path segment == one logical root). |
| 11 | # To maximize the test surface, we want to test: |
| 12 | # - /ipfs/ content path |
| 13 | # - /ipns/ content path |
| 14 | # - at least 3 levels |
| 15 | # - separate tests for a directory listing and a file |
| 16 | # - have implicit index.html for a good measure |
| 17 | # /ipns/root1/root2/root3/ (/ipns/root1/root2/root3/index.html) |
| 18 | |
| 19 | # Note: we cover important UnixFS-focused edge case here: |
| 20 | # |
| 21 | # ROOT3_CID - dir listing (dir-index-html response) |
| 22 | # ROOT4_CID - index.html returned as a root response (dir/), instead of generated dir-index-html |
| 23 | # FILE_CID - index.html returned directly, as a file |
| 24 | # |
| 25 | # Caching of things like raw blocks, CARs, dag-json and dag-cbor |
| 26 | # is tested in their respective suites. |
| 27 | |
| 28 | ROOT1_CID=bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui # ./ |
| 29 | ROOT2_CID=bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii # ./root2 |
| 30 | ROOT3_CID=bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja # ./root2/root3 |
| 31 | ROOT4_CID=bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q # ./root2/root3/root4 |
| 32 | FILE_CID=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am # ./root2/root3/root4/index.html |
| 33 | TEST_IPNS_ID=k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe |
| 34 | |
| 35 | # Import test case |
| 36 | # See the static fixtures in ./t0116-gateway-cache/ |
| 37 | test_expect_success "Add the test directory" ' |
| 38 | ipfs dag import --pin-roots ../t0116-gateway-cache/fixtures.car |
| 39 | ipfs routing put --allow-offline /ipns/${TEST_IPNS_ID} ../t0116-gateway-cache/${TEST_IPNS_ID}.ipns-record |
| 40 | ' |
| 41 | |
| 42 | # Etag |
| 43 | test_expect_success "GET for /ipfs/ unixfs dir listing succeeds" ' |
| 44 | curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/" >/dev/null 2>curl_ipfs_dir_listing_output |
| 45 | ' |
| 46 | |
| 47 | test_expect_success "GET for /ipns/ unixfs dir listing succeeds" ' |
| 48 | curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/" >/dev/null 2>curl_ipns_dir_listing_output |
| 49 | ' |
| 50 | |
| 51 | ## dir generated listing |
| 52 | test_expect_success "GET /ipfs/ dir response has special Etag for generated dir listing" ' |
| 53 | test_should_contain "< Etag: \"DirIndex" curl_ipfs_dir_listing_output && |
| 54 | grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipfs_dir_listing_output |
| 55 | ' |
| 56 | test_expect_success "GET /ipns/ dir response has special Etag for generated dir listing" ' |
| 57 | test_should_contain "< Etag: \"DirIndex" curl_ipns_dir_listing_output && |
| 58 | grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipns_dir_listing_output |
| 59 | ' |
| 60 | |
| 61 | |
| 62 | test_kill_ipfs_daemon |
| 63 | |
| 64 | test_done |