diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ce9c799f..18df60519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `--verbose` flag displays all the output to the console +### Changed +- finalized port of Kubo's sharness tests. [PR](https://github.com/ipfs/gateway-conformance/pull/92) + ## [0.2.0] - 2023-06-26 ### Added - `carFixture.MustGetChildren` diff --git a/fixtures/README.md b/fixtures/README.md index f9df5d6b7..beff1066d 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -1,33 +1,22 @@ -# ipfs add --recursive --raw-leaves --cid-version=1 --wrap-with-directory fixtures/dir +# Fixtures -added bafkreibyniihaqnhs536mbvc3wx66vbfttisc6zrvea6kzeku3w4as6lum dir/ascii.txt -added bafybeiaxmpwa4nz2mekiiosayvkfgfpbubm7pch7tspx5syhzzsvkoewc4 dir -added bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy +This folder contains all the fixtures using during the tests, with +the recipes to re-create them. -# ipfs dag export bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy > fixtures/dir.car +## Recipes -# go install github.com/ipld/go-car/cmd/car@latest +### [gateway-raw-block.car](./gateway-raw-block.car) -# car list fixtures/dir.car +Generated with: -bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy -bafybeiaxmpwa4nz2mekiiosayvkfgfpbubm7pch7tspx5syhzzsvkoewc4 -bafkreibyniihaqnhs536mbvc3wx66vbfttisc6zrvea6kzeku3w4as6lum +```sh +# using Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/) +mkdir -p dir && +echo "hello application/vnd.ipld.raw" > dir/ascii.txt && +ROOT_DIR_CID=$(ipfs add -Qrw --cid-version 1 dir) && +FILE_CID=$(ipfs resolve -r /ipfs/$ROOT_DIR_CID/dir/ascii.txt | cut -d "/" -f3) && +ipfs dag export $ROOT_DIR_CID > gateway-raw-block.car -# car extract --file fixtures/dir.car --verbose - -.../gateway-conformance/dir -.../gateway-conformance/dir/ascii.txt - -# go run extract.go fixtures/dir.car - -path: / - cid: bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy - raw: [18 45 10 36 1 112 18 32 23 99 236 14 55 58 97 20 132 58 64 197 84 83 21 225 160 89 247 136 255 156 159 126 203 7 206 101 85 56 150 23 18 3 100 105 114 24 90 10 2 8 1] -path: /dir - cid: bafybeiaxmpwa4nz2mekiiosayvkfgfpbubm7pch7tspx5syhzzsvkoewc4 - raw: [18 51 10 36 1 85 18 32 56 106 16 112 65 167 151 119 230 6 162 221 175 239 84 37 156 209 33 123 49 169 1 229 100 138 166 237 192 75 203 163 18 9 97 115 99 105 105 46 116 120 116 24 33 10 2 8 1] -path: /dir/ascii.txt - cid: bafkreibyniihaqnhs536mbvc3wx66vbfttisc6zrvea6kzeku3w4as6lum - raw: [103 111 111 100 98 121 101 32 97 112 112 108 105 99 97 116 105 111 110 47 118 110 100 46 105 112 108 100 46 114 97 119 10] - str: goodbye application/vnd.ipld.raw +echo ROOT_DIR_CID=${ROOT_DIR_CID} # ./ +echo FILE_CID=${FILE_CID} # ./dir/ascii.txt +``` \ No newline at end of file diff --git a/fixtures/t0115/README.md b/fixtures/dir_listing/README.md similarity index 85% rename from fixtures/t0115/README.md rename to fixtures/dir_listing/README.md index 937438bcd..8b74a7327 100644 --- a/fixtures/t0115/README.md +++ b/fixtures/dir_listing/README.md @@ -1,12 +1,13 @@ -# Dataset description/sources +# Directory Listing Fixtures -- fixtures.car - - raw CARv1 +## Recipes -generated with: +### [fixtures.car](./fixtures.car) + +Raw CARv1, generated with: ```sh -# using ipfs version 0.18.1 +# using Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/) mkdir -p rootDir/ipfs && mkdir -p rootDir/ipns && mkdir -p rootDir/api && diff --git a/fixtures/t0115/dnslink.yml b/fixtures/dir_listing/dnslink.yml similarity index 100% rename from fixtures/t0115/dnslink.yml rename to fixtures/dir_listing/dnslink.yml diff --git a/fixtures/t0115/fixtures.car b/fixtures/dir_listing/fixtures.car similarity index 100% rename from fixtures/t0115/fixtures.car rename to fixtures/dir_listing/fixtures.car diff --git a/fixtures/gateway-cache/README.md b/fixtures/gateway-cache/README.md index 56f244caa..41ad5f4e4 100644 --- a/fixtures/gateway-cache/README.md +++ b/fixtures/gateway-cache/README.md @@ -10,7 +10,7 @@ generated with: ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) mkdir -p root2/root3/root4 && echo "hello" > root2/root3/root4/index.html && diff --git a/fixtures/t0117-gateway-block.car b/fixtures/gateway-raw-block.car similarity index 100% rename from fixtures/t0117-gateway-block.car rename to fixtures/gateway-raw-block.car diff --git a/fixtures/ipns_records/README.md b/fixtures/ipns_records/README.md new file mode 100644 index 000000000..772712820 --- /dev/null +++ b/fixtures/ipns_records/README.md @@ -0,0 +1,23 @@ +# IPNS Records Fixtures + +## Recipes + +### Fixtures and ipns-record + +```sh +# using Kubo CLI version 0.21.0-rc3 (https://dist.ipfs.tech/kubo/v0.21.0-rc3/) +FILE_CID=$(echo "Hello IPFS" | ipfs add --cid-version 1 -q) +IPNS_KEY=$(ipfs key gen ipns-record) + +ipfs dag export ${FILE_CID} > fixtures.car + +# publish a record valid for a 100 years +ipfs name publish --key=ipns-record --quieter --ttl=876600h --lifetime=876600h /ipfs/${FILE_CID} +ipfs routing get /ipns/${IPNS_KEY} > ${IPNS_KEY}.ipns-record + +echo IPNS_KEY=${IPNS_KEY} +echo FILE_CID=${FILE_CID} # A file containing "Hello IPFS" + +# IPNS_KEY=k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab +# FILE_CID=bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244 # A file containing Hello IPFS +``` diff --git a/fixtures/t0124/fixtures.car b/fixtures/ipns_records/fixtures.car similarity index 100% rename from fixtures/t0124/fixtures.car rename to fixtures/ipns_records/fixtures.car diff --git a/fixtures/t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record b/fixtures/ipns_records/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record similarity index 100% rename from fixtures/t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record rename to fixtures/ipns_records/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record diff --git a/fixtures/path_gateway_dag/README.md b/fixtures/path_gateway_dag/README.md new file mode 100644 index 000000000..3caeaa2b3 --- /dev/null +++ b/fixtures/path_gateway_dag/README.md @@ -0,0 +1,66 @@ +# Path Gateway Dag Fixtures + +## Recipes + +### Legacy fixtures from Kubo + +- dag-cbor-traversal.car +- dag-json-traversal.car +- dag-pb.car +- dag-pb.json + +### [gateway-json-cbor.car](./gateway-json-cbor.car) and ipns-records + +Generated with: + +```sh +# using Kubo CLI version 0.21.0-rc3 (https://dist.ipfs.tech/kubo/v0.21.0-rc3/) + +mkdir -p rootDir/ipfs && +mkdir -p rootDir/ipns && +mkdir -p rootDir/api && +mkdir -p rootDir/ą/ę && +echo "{ \"test\": \"i am a plain json file\" }" > rootDir/ą/ę/t.json && +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_JSON_CID=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/t.json | jq -r .Hash) && +FILE_CID=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Hash) && +FILE_SIZE=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Size) +echo "$FILE_CID / $FILE_SIZE" + +echo DIR_CID=${DIR_CID} # ./rootDir +echo FILE_JSON_CID=${FILE_JSON_CID} # ./rootDir/ą/ę/t.json +echo FILE_CID=${FILE_CID} # ./rootDir/ą/ę/file-źł.txt +echo FILE_SIZE=${FILE_SIZE} + +ipfs dag export ${DIR_CID} > gateway-json-cbor.car + +DAG_CBOR_TRAVERSAL_CID="bafyreibs4utpgbn7uqegmd2goqz4bkyflre2ek2iwv743fhvylwi4zeeim" +DAG_JSON_TRAVERSAL_CID="baguqeeram5ujjqrwheyaty3w5gdsmoz6vittchvhk723jjqxk7hakxkd47xq" +DAG_PB_CID="bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke" + +test_native_dag() { + NAME=$1 + CID=$2 + + IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 ${NAME}_test_key | head -n1 | tr -d "\n") + ipfs name publish --key ${NAME}_test_key --allow-offline --ttl=876600h --lifetime=876600h -Q "/ipfs/${CID}" > name_publish_out + + ipfs routing get /ipns/${IPNS_ID} > ${IPNS_ID}.ipns-record + + echo "IPNS_ID_${NAME}=${IPNS_ID}" +} + +test_native_dag "DAG_JSON" "$DAG_JSON_TRAVERSAL_CID" +test_native_dag "DAG_CBOR" "$DAG_CBOR_TRAVERSAL_CID" + +# DIR_CID=bafybeiafyvqlazbbbtjnn6how5d6h6l6rxbqc4qgpbmteaiskjrffmyy4a # ./rootDir +# FILE_JSON_CID=bafkreibrppizs3g7axs2jdlnjua6vgpmltv7k72l7v7sa6mmht6mne3qqe # ./rootDir/ą/ę/t.json +# FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt +# FILE_SIZE=34 +# IPNS_ID_DAG_JSON=k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2 +# IPNS_ID_DAG_CBOR=k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l +``` diff --git a/fixtures/t0123/dag-cbor-traversal.car b/fixtures/path_gateway_dag/dag-cbor-traversal.car similarity index 100% rename from fixtures/t0123/dag-cbor-traversal.car rename to fixtures/path_gateway_dag/dag-cbor-traversal.car diff --git a/fixtures/t0123/dag-json-traversal.car b/fixtures/path_gateway_dag/dag-json-traversal.car similarity index 100% rename from fixtures/t0123/dag-json-traversal.car rename to fixtures/path_gateway_dag/dag-json-traversal.car diff --git a/fixtures/t0123/dag-pb.car b/fixtures/path_gateway_dag/dag-pb.car similarity index 100% rename from fixtures/t0123/dag-pb.car rename to fixtures/path_gateway_dag/dag-pb.car diff --git a/fixtures/t0123/dag-pb.json b/fixtures/path_gateway_dag/dag-pb.json similarity index 100% rename from fixtures/t0123/dag-pb.json rename to fixtures/path_gateway_dag/dag-pb.json diff --git a/fixtures/t0123-gateway-json-cbor.car b/fixtures/path_gateway_dag/gateway-json-cbor.car similarity index 100% rename from fixtures/t0123-gateway-json-cbor.car rename to fixtures/path_gateway_dag/gateway-json-cbor.car diff --git a/fixtures/t0123/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record b/fixtures/path_gateway_dag/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record similarity index 100% rename from fixtures/t0123/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record rename to fixtures/path_gateway_dag/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record diff --git a/fixtures/t0123/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record b/fixtures/path_gateway_dag/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record similarity index 100% rename from fixtures/t0123/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record rename to fixtures/path_gateway_dag/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record diff --git a/fixtures/t0123/plain-that-can-be-dag.cbor.car b/fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-cbor.car similarity index 100% rename from fixtures/t0123/plain-that-can-be-dag.cbor.car rename to fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-cbor.car diff --git a/fixtures/t0123/plain-that-can-be-dag.json.car b/fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-json.car similarity index 100% rename from fixtures/t0123/plain-that-can-be-dag.json.car rename to fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-json.car diff --git a/fixtures/t0123/plain.cbor.car b/fixtures/path_gateway_dag/plain-cbor.car similarity index 100% rename from fixtures/t0123/plain.cbor.car rename to fixtures/path_gateway_dag/plain-cbor.car diff --git a/fixtures/t0123/plain.json.car b/fixtures/path_gateway_dag/plain-json.car similarity index 100% rename from fixtures/t0123/plain.json.car rename to fixtures/path_gateway_dag/plain-json.car diff --git a/fixtures/path_gateway_tar/README.md b/fixtures/path_gateway_tar/README.md new file mode 100644 index 000000000..ff8790088 --- /dev/null +++ b/fixtures/path_gateway_tar/README.md @@ -0,0 +1,40 @@ +# Path Gateway Tar Fixtures + +## Recipes + +### [inside-roots.car](./inside-root.car) and [outside-roots.car](./outside-root.car) + +Legacy fixtures from Kubo Sharness. + +See the [PR](https://github.com/ipfs/kubo/pull/9029) that introduced them for more details + +### [fixtures.car](./fixtures.car) + +Generated with: + +```sh +# Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/) + +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 --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Hash) && +FILE_SIZE=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Size) +echo "$FILE_CID / $FILE_SIZE" + +echo DIR_CID=${DIR_CID} # ./rootDir +echo FILE_CID=${FILE_CID} # ./rootDir/ą/ę/file-źł.txt +echo FILE_SIZE=${FILE_SIZE} + +ipfs dag export ${DIR_CID} > ./fixtures.car + +# DIR_CID=bafybeig6ka5mlwkl4subqhaiatalkcleo4jgnr3hqwvpmsqfca27cijp3i # ./rootDir +# FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt +# FILE_SIZE=34 +``` diff --git a/fixtures/t0122/fixtures.car b/fixtures/path_gateway_tar/fixtures.car similarity index 100% rename from fixtures/t0122/fixtures.car rename to fixtures/path_gateway_tar/fixtures.car diff --git a/fixtures/t0122/inside-root.car b/fixtures/path_gateway_tar/inside-root.car similarity index 100% rename from fixtures/t0122/inside-root.car rename to fixtures/path_gateway_tar/inside-root.car diff --git a/fixtures/t0122/outside-root.car b/fixtures/path_gateway_tar/outside-root.car similarity index 100% rename from fixtures/t0122/outside-root.car rename to fixtures/path_gateway_tar/outside-root.car diff --git a/fixtures/path_gateway_unixfs/README.md b/fixtures/path_gateway_unixfs/README.md new file mode 100644 index 000000000..1c5186623 --- /dev/null +++ b/fixtures/path_gateway_unixfs/README.md @@ -0,0 +1,14 @@ +# Path Gateway Fixtures + +## Recipes + +### [symlink.car](./symlink.car) + +```sh +# using Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/ +mkdir testfiles && +echo "content" > testfiles/foo && +ln -s foo testfiles/bar && +ROOT_DIR_CID=$(ipfs add -Qr testfiles) && +ipfs dag export $ROOT_DIR_CID > symlink.car +``` diff --git a/fixtures/t0113-gateway-symlink.car b/fixtures/path_gateway_unixfs/symlink.car similarity index 100% rename from fixtures/t0113-gateway-symlink.car rename to fixtures/path_gateway_unixfs/symlink.car diff --git a/fixtures/redirects_file/README.md b/fixtures/redirects_file/README.md new file mode 100644 index 000000000..9d56fb5cf --- /dev/null +++ b/fixtures/redirects_file/README.md @@ -0,0 +1,12 @@ +# Fixture for Redirects File Testing + +## Recipes + +### [dnslink.yml](./dnslink.yml) + +See comments in the yml file. + + +### [redirects.car](./redirects.car) + +Fixtures based on [specs.ipfs.tech/http-gateways/web-redirects-file/#test-fixtures](https://specs.ipfs.tech/http-gateways/web-redirects-file/#test-fixtures) and [IPIP-0002](https://specs.ipfs.tech/ipips/ipip-0002/) \ No newline at end of file diff --git a/fixtures/t0109-dnslink.yml b/fixtures/redirects_file/dnslink.yml similarity index 85% rename from fixtures/t0109-dnslink.yml rename to fixtures/redirects_file/dnslink.yml index d65b5f638..15be77219 100644 --- a/fixtures/t0109-dnslink.yml +++ b/fixtures/redirects_file/dnslink.yml @@ -3,5 +3,5 @@ dnslinks: custom-dnslink: subdomain: dnslink-enabled-on-fqdn # this is the cid of the folder - # t0109-redirects.car:/examples/ + # ./redirects.car:/examples/ path: /ipfs/QmYBhLYDwVFvxos9h8CGU2ibaY66QNgv8hpfewxaQrPiZj \ No newline at end of file diff --git a/fixtures/t0109-redirects.car b/fixtures/redirects_file/redirects.car similarity index 100% rename from fixtures/t0109-redirects.car rename to fixtures/redirects_file/redirects.car diff --git a/fixtures/t0114/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record b/fixtures/subdomain_gateway/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record similarity index 100% rename from fixtures/t0114/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record rename to fixtures/subdomain_gateway/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record diff --git a/fixtures/t0114/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record b/fixtures/subdomain_gateway/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record similarity index 100% rename from fixtures/t0114/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record rename to fixtures/subdomain_gateway/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record diff --git a/fixtures/t0114/README.md b/fixtures/subdomain_gateway/README.md similarity index 64% rename from fixtures/t0114/README.md rename to fixtures/subdomain_gateway/README.md index 005a7f0c5..ea300eb34 100644 --- a/fixtures/t0114/README.md +++ b/fixtures/subdomain_gateway/README.md @@ -1,18 +1,15 @@ -# Dataset description/sources +# Subdomain Gateway Fixtures -- fixtures.car - - raw CARv1 +## Recipes -- QmUKd....ipns-record - - ipns record, encoded with protocol buffer +### [dnslink.yml](./dnslink.yml) -- 12D3K....ipns-record - - ipns record, encoded with protocol buffer +See comments in the yml file. -Generated with: +### [fixtures.car](./fixtures.car) ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-rc3 (https://dist.ipfs.tech/kubo/v0.21.0-rc3/) # CIDv0to1 is necessary because raw-leaves are enabled by default during # "ipfs add" with CIDv1 and disabled with CIDv0 @@ -42,18 +39,22 @@ DIR_CID=$(ipfs add -Qr --cid-version 1 testdirlisting) echo DIR_CID=${DIR_CID} # ./testdirlisting ipfs files mkdir /t0114/ -ipfs files cp /ipfs/${CIDv1} /t0114/ -ipfs files cp /ipfs/${CIDv0} /t0114/ -ipfs files cp /ipfs/${CIDv0to1} /t0114/ -ipfs files cp /ipfs/${DIR_CID} /t0114/ -ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/ +ipfs files cp /ipfs/${CIDv1} /t0114/hello-CIDv1 +ipfs files cp /ipfs/${CIDv0} /t0114/hello-CIDv0 +ipfs files cp /ipfs/${CIDv0to1} /t0114/hello-CIDv0to1 +ipfs files cp /ipfs/${DIR_CID} /t0114/testdirlisting +ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/hello-CIDv1_TOO_LONG ROOT=`ipfs files stat /t0114/ --hash` ipfs dag export ${ROOT} > ./fixtures.car +``` + +### [ipns-records](./) -# Then the keys +We create ipns-records pointing to the CIDv1 generated above: +```sh KEY_NAME=test_key_rsa_$RANDOM RSA_KEY=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 ${KEY_NAME} | head -n1 | tr -d "\n") RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0) @@ -89,23 +90,4 @@ echo ED25519_IPNS_IDv1=${ED25519_IPNS_IDv1} echo ED25519_IPNS_IDv1_DAGPB=${ED25519_IPNS_IDv1_DAGPB} echo IPNS_ED25519_B58MH=${IPNS_ED25519_B58MH} echo IPNS_ED25519_B36CID=${IPNS_ED25519_B36CID} - -# CID_VAL=hello -# CIDv1=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am -# CIDv0=QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN -# CIDv0to1=bafybeiffndsajwhk3lwjewwdxqntmjm4b5wxaaanokonsggenkbw6slwk4 -# CIDv1_TOO_LONG=bafkrgqhhyivzstcz3hhswshfjgy6ertgmnqeleynhwt4dlfsthi4hn7zgh4uvlsb5xncykzapi3ocd4lzogukir6ksdy6wzrnz6ohnv4aglcs -# DIR_CID=bafybeiht6dtwk3les7vqm6ibpvz6qpohidvlshsfyr7l5mpysdw2vmbbhe # ./testdirlisting - -# RSA_KEY=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3 -# RSA_IPNS_IDv0=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3 -# RSA_IPNS_IDv1=k2k4r8m7xvggw5pxxk3abrkwyer625hg01hfyggrai7lk1m63fuihi7w -# RSA_IPNS_IDv1_DAGPB=k2jmtxu61bnhrtj301lw7zizknztocdbeqhxgv76l2q9t36fn9jbzipo - -# ED25519_KEY=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d -# ED25519_IPNS_IDv0=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d -# ED25519_IPNS_IDv1=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam -# ED25519_IPNS_IDv1_DAGPB=k50rm9yjlt0jey4fqg6wafvqprktgbkpgkqdg27tpqje6iimzxewnhvtin9hhq -# IPNS_ED25519_B58MH=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d -# IPNS_ED25519_B36CID=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam ``` diff --git a/fixtures/t0114/dnslink.yml b/fixtures/subdomain_gateway/dnslink.yml similarity index 100% rename from fixtures/t0114/dnslink.yml rename to fixtures/subdomain_gateway/dnslink.yml diff --git a/fixtures/t0114-gateway_subdomains.car b/fixtures/subdomain_gateway/fixtures.car similarity index 100% rename from fixtures/t0114-gateway_subdomains.car rename to fixtures/subdomain_gateway/fixtures.car diff --git a/fixtures/t0114/fixtures.car b/fixtures/t0114/fixtures.car deleted file mode 100644 index bc7b913df..000000000 Binary files a/fixtures/t0114/fixtures.car and /dev/null differ diff --git a/fixtures/t0123/README.md b/fixtures/t0123/README.md index 5a63b192a..de670caa5 100644 --- a/fixtures/t0123/README.md +++ b/fixtures/t0123/README.md @@ -14,7 +14,7 @@ generated with: ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) mkdir -p rootDir/ipfs && mkdir -p rootDir/ipns && diff --git a/tests/dnslink_gateway_test.go b/tests/dnslink_gateway_test.go index 4cd0e26e7..0a18a23b2 100644 --- a/tests/dnslink_gateway_test.go +++ b/tests/dnslink_gateway_test.go @@ -13,134 +13,11 @@ import ( "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - -func TestDNSLinkGateway(t *testing.T) { - tests := SugarTests{ - // ## ============================================================================ - // ## Test DNSLink requests with a custom PublicGateway (hostname config) - // ## (DNSLink site at http://dnslink-test.example.com) - // ## ============================================================================ - // # disable wildcard DNSLink gateway - // # and enable it on specific NSLink hostname - // ipfs config --json Gateway.NoDNSLink true && \ - // ipfs config --json Gateway.PublicGateways '{ - // "dnslink-enabled-on-fqdn.example.org": { - // "NoDNSLink": false, - // "UseSubdomains": false, - // "Paths": ["/ipfs"] - // }, - // "only-dnslink-enabled-on-fqdn.example.org": { - // "NoDNSLink": false, - // "UseSubdomains": false, - // "Paths": [] - // }, - // "dnslink-disabled-on-fqdn.example.com": { - // "NoDNSLink": true, - // "UseSubdomains": false, - // "Paths": [] - // } - // }' || exit 1 - - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // DNSLINK_FQDN="dnslink-enabled-on-fqdn.example.org" - // ONLY_DNSLINK_FQDN="only-dnslink-enabled-on-fqdn.example.org" - // NO_DNSLINK_FQDN="dnslink-disabled-on-fqdn.example.com" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1,$ONLY_DNSLINK_FQDN:/ipfs/$DIR_CID" - - // # DNSLink enabled - - // test_hostname_gateway_response_should_contain \ - // "request for http://{dnslink-fqdn}/ PublicGateway returns expected payload" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/" \ - // "$CID_VAL" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipfs/{cid} returns expected payload when /ipfs is on Paths whitelist" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ - // "$CID_VAL" - - // # Test for a fun edge case: DNSLink-only gateway without /ipfs/ namespace - // # mounted, and with subdirectory named "ipfs" ¯\_(ツ)_/¯ - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipfs/file.txt returns data from content root when /ipfs in not on Paths whitelist" \ - // "$ONLY_DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipfs/file.txt" \ - // "I am a txt file" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipns/{peerid} returns 404 when path is not whitelisted" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \ - // "404 Not Found" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipns/{peerid} returns 404 when path is not whitelisted" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \ - // "404 Not Found" - - // # DNSLink disabled - - // test_hostname_gateway_response_should_contain \ - // "request for http://{dnslink-fqdn}/ returns 404 when NoDNSLink=true" \ - // "$NO_DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/" \ - // "404 Not Found" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipfs/{cid} returns 404 when path is not whitelisted" \ - // "$NO_DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv0" \ - // "404 Not Found" - - // ## ============================================================================ - // ## Test wildcard DNSLink (any hostname, with default config) - // ## ============================================================================ - - // test_kill_ipfs_daemon - - // # enable wildcard DNSLink gateway (any value in Host header) - // # and remove custom PublicGateways - // ipfs config --json Gateway.NoDNSLink false && \ - // ipfs config --json Gateway.PublicGateways '{}' || exit 1 - - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // DNSLINK_FQDN="wildcard-dnslink-not-in-config.example.com" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1" - - // # restart daemon to apply config changes - // test_launch_ipfs_daemon - - // # make sure test setup is valid (fail if CoreAPI is unable to resolve) - // test_expect_success "spoofed DNSLink record resolves in cli" " - // ipfs resolve /ipns/$DNSLINK_FQDN > result && - // test_should_contain \"$CIDv1\" result && - // ipfs cat /ipns/$DNSLINK_FQDN > result && - // test_should_contain \"$CID_VAL\" result - // " - - // # gateway test - // - // test_hostname_gateway_response_should_contain \ - // "request for http://{dnslink-fqdn}/ (wildcard) returns expected payload" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/" \ - // "$CID_VAL" - } - - RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.DNSLinkGateway) -} - -// TODO(laurent): this was in t0115_gateway_dir_listing_test.go - func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0115/fixtures.car") + fixture := car.MustOpenUnixfsCar("dir_listing/fixtures.car") file := fixture.MustGetNode("ą", "ę", "file-źł.txt") - dnsLinks := dnslink.MustOpenDNSLink("t0115/dnslink.yml") + dnsLinks := dnslink.MustOpenDNSLink("dir_listing/dnslink.yml") dnsLink := dnsLinks.MustGet("website") gatewayURL := SubdomainGatewayURL @@ -154,26 +31,7 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { dnsLinkHostname := tmpl.Fmt("{{dnslink}}.{{host}}", dnsLink, u.Host) - // ## ============================================================================ - // ## Test dir listing on DNSLink gateway (eg. example.com) - // ## ============================================================================ tests = append(tests, SugarTests{ - // # 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 be hidden" ' - // 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_not_contain ".." list_response - // ' { Name: "Backlink on root CID should be hidden (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -186,11 +44,6 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { ), ), }, - // test_expect_success "dnslink gw: redirect dir listing to URL with trailing slash" ' - // curl -sD - --resolve $DNSLINK_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DNSLINK_HOSTNAME:$GWAY_PORT/ą/ę > list_response && - // test_should_contain "HTTP/1.1 301 Moved Permanently" list_response && - // test_should_contain "Location: /%c4%85/%c4%99/" list_response - // ' { Name: "Redirect dir listing to URL with trailing slash", Request: Request(). @@ -201,25 +54,6 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { Header("Location").Equals(`/%c4%85/%c4%99/`), ), }, - // 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: backlink on subdirectory should point at parent directory" ' - // test_should_contain ".." list_response - // ' - // test_expect_success "dnslink gw: breadcrumbs should point at content root mounted at dnslink origin" ' - // test_should_contain "/ipns/website.example.com/ą/ę" list_response - // ' - // test_expect_success "dnslink gw: name column should be a link to content root mounted at dnslink origin" ' - // test_should_contain "file-źł.txt" 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.tech" ' - // test_should_contain "" list_response - // ' { Name: "Regular dir listing (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -234,7 +68,7 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { - name column should be a link to content root mounted at dnslink origin - hash column should be a CID link to cid.ipfs.tech DNSLink websites don't have public gateway mounted by default - See: https://github.com/ipfs/dir-index-html/issues/42 (TODO: class and other attrs are kubo-specific) + See: https://github.com/ipfs/dir-index-html/issues/42 (TODO: class and other attrs are kubo-specific) `, And( Contains("Index of"), diff --git a/tests/path_gateway_cors_test.go b/tests/path_gateway_cors_test.go new file mode 100644 index 000000000..563a2a71a --- /dev/null +++ b/tests/path_gateway_cors_test.go @@ -0,0 +1,56 @@ +package tests + +import ( + "testing" + + "github.com/ipfs/gateway-conformance/tooling/specs" + . "github.com/ipfs/gateway-conformance/tooling/test" +) + +func TestCors(t *testing.T) { + cidHello := "bafkqabtimvwgy3yk" // hello + + tests := SugarTests{ + { + Name: "GET Responses from Gateway should include CORS headers allowing JS from other origins to read the data cross-origin.", + Request: Request(). + Path("/ipfs/{{CID}}/", cidHello), + Response: Expect(). + Headers( + Header("Access-Control-Allow-Origin").Equals("*"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), + Header("Access-Control-Expose-Headers").Has( + "Content-Range", + "Content-Length", + "X-Ipfs-Path", + "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", + ), + ), + }, + { + Name: "OPTIONS to Gateway succeeds", + Request: Request(). + Method("OPTIONS"). + Path("/ipfs/{{CID}}/", cidHello), + Response: Expect(). + Headers( + Header("Access-Control-Allow-Origin").Equals("*"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), + Header("Access-Control-Expose-Headers").Has( + "Content-Range", + "Content-Length", + "X-Ipfs-Path", + "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", + ), + ), + }, + } + + RunWithSpecs(t, tests, specs.PathGatewayUnixFS) +} diff --git a/tests/path_gateway_dag_test.go b/tests/path_gateway_dag_test.go index 8bccaf180..d0b0aec1b 100644 --- a/tests/path_gateway_dag_test.go +++ b/tests/path_gateway_dag_test.go @@ -14,7 +14,7 @@ import ( // TODO(laurent): this was t0123_gateway_json_cbor_test func TestGatewayJsonCbor(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0123-gateway-json-cbor.car") + fixture := car.MustOpenUnixfsCar("path_gateway_dag/gateway-json-cbor.car") fileJSON := fixture.MustGetNode("ą", "ę", "t.json") fileJSONCID := fileJSON.Cid() @@ -22,7 +22,7 @@ func TestGatewayJsonCbor(t *testing.T) { tests := SugarTests{ { - Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type (1)", + Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type - without headers", Hint: ` ## Quick regression check for JSON stored on UnixFS: ## it has nothing to do with DAG-JSON and JSON codecs, @@ -30,10 +30,7 @@ func TestGatewayJsonCbor(t *testing.T) { ## and we want to avoid surprises like https://github.com/protocol/bifrost-infra/issues/2290 `, Request: Request(). - Path("/ipfs/{{cid}}", fileJSONCID). - Headers( - Header("Accept", "application/json"), - ), + Path("/ipfs/{{cid}}", fileJSONCID), Response: Expect(). Status(200). Headers( @@ -43,7 +40,7 @@ func TestGatewayJsonCbor(t *testing.T) { Body(fileJSONData), }, { - Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type (2)", + Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type - with headers", Hint: ` ## Quick regression check for JSON stored on UnixFS: ## it has nothing to do with DAG-JSON and JSON codecs, @@ -71,7 +68,7 @@ func TestGatewayJsonCbor(t *testing.T) { // ## Reading UnixFS (data encoded with dag-pb codec) as DAG-CBOR and DAG-JSON // ## (returns representation defined in https://ipld.io/specs/codecs/dag-pb/spec/#logical-format) func TestDAgPbConversion(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0123-gateway-json-cbor.car") + fixture := car.MustOpenUnixfsCar("path_gateway_dag/gateway-json-cbor.car") dir := fixture.MustGetRoot() file := fixture.MustGetNode("ą", "ę", "file-źł.txt") @@ -95,16 +92,6 @@ func TestDAgPbConversion(t *testing.T) { formatedDir := dir.Formatted("dag-" + row.Format) tests := SugarTests{ - /** - test_expect_success "GET UnixFS file as $name with format=dag-$format converts to the expected Content-Type" ' - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 && - ipfs dag get --output-codec dag-$format $FILE_CID > ipfs_dag_get_output 2>&1 && - test_cmp ipfs_dag_get_output curl_output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" headers && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${FILE_CID}.${format}\"" headers && - test_should_not_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET UnixFS file as {{name}} with format=dag-{{format}} converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -123,16 +110,6 @@ func TestDAgPbConversion(t *testing.T) { formatedFile, ), }, - /** - test_expect_success "GET UnixFS directory as $name with format=dag-$format converts to the expected Content-Type" ' - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output 2>&1 && - ipfs dag get --output-codec dag-$format $DIR_CID > ipfs_dag_get_output 2>&1 && - test_cmp ipfs_dag_get_output curl_output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" headers && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${DIR_CID}.${format}\"" headers && - test_should_not_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET UnixFS directory as {{name}} with format=dag-{{format}} converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -150,14 +127,6 @@ func TestDAgPbConversion(t *testing.T) { formatedDir, ), }, - /** - test_expect_success "GET UnixFS as $name with 'Accept: application/vnd.ipld.dag-$format' converts to the expected Content-Type" ' - curl -sD - -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${FILE_CID}.${format}\"" curl_output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output && - test_should_not_contain "Content-Type: application/$format" curl_output - ' - */ { Name: Fmt("GET UnixFS as {{name}} with 'Accept: application/vnd.ipld.dag-{{format}}' converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -176,12 +145,6 @@ func TestDAgPbConversion(t *testing.T) { Not().Contains("application/{{format}}", row.Format), ), }, - /** - test_expect_success "GET UnixFS as $name with 'Accept: foo, application/vnd.ipld.dag-$format,bar' converts to the expected Content-Type" ' - curl -sD - -H "Accept: foo, application/vnd.ipld.dag-$format,text/plain" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output - ' - */ { Name: Fmt("GET UnixFS as {{name}} with 'Accept: foo, application/vnd.ipld.dag-{{format}},bar' converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -196,16 +159,6 @@ func TestDAgPbConversion(t *testing.T) { Equals("application/vnd.ipld.dag-{{format}}", row.Format), ), }, - /** - test_expect_success "GET UnixFS with format=$format (not dag-$format) is no-op (no conversion)" ' - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=$format" > curl_output 2>&1 && - ipfs cat $FILE_CID > cat_output && - test_cmp cat_output curl_output && - test_should_contain "Content-Type: text/plain" headers && - test_should_not_contain "Content-Type: application/$format" headers && - test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" headers - ' - */ { Name: Fmt("GET UnixFS with format={{format}} (not dag-{{format}}) is no-op (no conversion)", row.Format), Request: Request(). @@ -224,16 +177,6 @@ func TestDAgPbConversion(t *testing.T) { fileData, ), }, - /** - test_expect_success "GET UnixFS with 'Accept: application/$format' (not dag-$format) is no-op (no conversion)" ' - curl -sD headers -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && - ipfs cat $FILE_CID > cat_output && - test_cmp cat_output curl_output && - test_should_contain "Content-Type: text/plain" headers && - test_should_not_contain "Content-Type: application/$format" headers && - test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" headers - ' - */ { Name: Fmt("GET UnixFS with 'Accept: application/{{format}}' (not dag-{{format}}) is no-op (no conversion)", row.Format), Request: Request(). @@ -275,25 +218,14 @@ func TestPlainCodec(t *testing.T) { } for _, row := range table { - plain := car.MustOpenUnixfsCar(Fmt("t0123/plain.{{format}}.car", row.Format)).MustGetRoot() - plainOrDag := car.MustOpenUnixfsCar(Fmt("t0123/plain-that-can-be-dag.{{format}}.car", row.Format)).MustGetRoot() + plain := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain-{{format}}.car", row.Format)).MustGetRoot() + plainOrDag := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain-cbor-that-can-be-dag-{{format}}.car", row.Format)).MustGetRoot() formatted := plainOrDag.Formatted("dag-" + row.Format) plainCID := plain.Cid() plainOrDagCID := plainOrDag.Cid() tests := SugarTests{ - /** - # no explicit format, just codec in CID - test_expect_success "GET $name without Accept or format= has expected $format Content-Type and body as-is" ' - CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output 2>&1 && - ipfs block get $CID > ipfs_block_output 2>&1 && - test_cmp ipfs_block_output curl_output && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt(`GET {{name}} without Accept or format= has expected "{{format}}" Content-Type and body as-is`, row.Name, row.Format), Hint: ` @@ -312,17 +244,6 @@ func TestPlainCodec(t *testing.T) { plain.RawData(), ), }, - /** - # explicit format still gives correct output, just codec in CID - test_expect_success "GET $name with ?format= has expected $format Content-Type and body as-is" ' - CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=$format" > curl_output 2>&1 && - ipfs block get $CID > ipfs_block_output 2>&1 && - test_cmp ipfs_block_output curl_output && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET {{name}} with ?format= has expected {{format}} Content-Type and body as-is", row.Name, row.Format), Hint: ` @@ -342,17 +263,6 @@ func TestPlainCodec(t *testing.T) { plain.RawData(), ), }, - /** - # explicit format still gives correct output, just codec in CID - test_expect_success "GET $name with Accept has expected $format Content-Type and body as-is" ' - CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output 2>&1 && - ipfs block get $CID > ipfs_block_output 2>&1 && - test_cmp ipfs_block_output curl_output && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET {{name}} with Accept has expected {{format}} Content-Type and body as-is", row.Name, row.Format), Hint: ` @@ -372,20 +282,6 @@ func TestPlainCodec(t *testing.T) { plain.RawData(), ), }, - /** - # explicit dag-* format passed, attempt to parse as dag* variant - ## Note: this works only for simple JSON that can be upgraded to DAG-JSON. - test_expect_success "GET $name with format=dag-$format interprets $format as dag-* variant and produces expected Content-Type and body" ' - CID=$(echo "{ \"test\": \"plain-json-that-can-also-be-dag-json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" > curl_output_param 2>&1 && - ipfs dag get --output-codec dag-$format $CID > ipfs_dag_get_output 2>&1 && - test_cmp ipfs_dag_get_output curl_output_param && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" headers && - curl -s -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output_accept 2>&1 && - test_cmp curl_output_param curl_output_accept - ' - */ { Name: Fmt("GET {{name}} with format=dag-{{format}} interprets {{format}} as dag-* variant and produces expected Content-Type and body", row.Name, row.Format), Hint: ` @@ -414,20 +310,13 @@ func TestPlainCodec(t *testing.T) { // ## Pathing, traversal over DAG-JSON and DAG-CBOR func TestPathing(t *testing.T) { - dagJSONTraversal := car.MustOpenUnixfsCar("t0123/dag-json-traversal.car").MustGetRoot() - dagCBORTraversal := car.MustOpenUnixfsCar("t0123/dag-cbor-traversal.car").MustGetRoot() + dagJSONTraversal := car.MustOpenUnixfsCar("path_gateway_dag/dag-json-traversal.car").MustGetRoot() + dagCBORTraversal := car.MustOpenUnixfsCar("path_gateway_dag/dag-cbor-traversal.car").MustGetRoot() dagJSONTraversalCID := dagJSONTraversal.Cid() dagCBORTraversalCID := dagCBORTraversal.Cid() tests := SugarTests{ - /** - test_expect_success "GET DAG-JSON traversal returns 501 if there is path remainder" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID/foo?format=dag-json" > curl_output 2>&1 && - test_should_contain "501 Not Implemented" curl_output && - test_should_contain "reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented" curl_output - ' - */ { Name: "GET DAG-JSON traversal returns 501 if there is path remainder", Request: Request(). @@ -437,14 +326,6 @@ func TestPathing(t *testing.T) { Status(501). Body(Contains("reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented")), }, - /** - test_expect_success "GET DAG-JSON traverses multiple links" ' - curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID/foo/link/bar?format=dag-json" > curl_output 2>&1 && - jq --sort-keys . curl_output > actual && - echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected && - test_cmp expected actual - ' - */ { Name: "GET DAG-JSON traverses multiple links", Request: Request(). @@ -458,13 +339,6 @@ func TestPathing(t *testing.T) { IsJSONEqual([]byte(`{"hello": "this is not a link"}`)), ), }, - /** - test_expect_success "GET DAG-CBOR traversal returns 501 if there is path remainder" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo?format=dag-cbor" > curl_output 2>&1 && - test_should_contain "501 Not Implemented" curl_output && - test_should_contain "reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented" curl_output - ' - */ { Name: "GET DAG-CBOR traversal returns 501 if there is path remainder", Request: Request(). @@ -474,14 +348,6 @@ func TestPathing(t *testing.T) { Status(501). Body(Contains("reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented")), }, - /** - test_expect_success "GET DAG-CBOR traverses multiple links" ' - curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/link/bar?format=dag-json" > curl_output 2>&1 && - jq --sort-keys . curl_output > actual && - echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected && - test_cmp expected actual - ' - */ { Name: "GET DAG-CBOR traverses multiple links", Request: Request(). @@ -516,20 +382,11 @@ func TestNativeDag(t *testing.T) { } for _, row := range table { - dagTraversal := car.MustOpenUnixfsCar(Fmt("t0123/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() + dagTraversal := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() dagTraversalCID := dagTraversal.Cid() formatted := dagTraversal.Formatted("dag-" + row.Format) tests := SugarTests{ - /** - # GET without explicit format and Accept: text/html returns raw block - - test_expect_success "GET $name from /ipfs without explicit format returns the same payload as the raw block" ' - ipfs block get "/ipfs/$CID" > expected && - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o curl_output && - test_cmp expected curl_output - ' - */ { Name: Fmt("GET {{name}} from /ipfs without explicit format returns the same payload as the raw block", row.Name), Hint: `GET without explicit format and Accept: text/html returns raw block`, @@ -541,15 +398,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - # GET dag-cbor block via Accept and ?format and ensure both are the same as `ipfs block get` output - - test_expect_success "GET $name from /ipfs with format=dag-$format returns the same payload as the raw block" ' - ipfs block get "/ipfs/$CID" > expected && - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o curl_ipfs_dag_param_output && - test_cmp expected curl_ipfs_dag_param_output - ' - */ { Name: Fmt("GET {{name}} from /ipfs with format=dag-{{format}} returns the same payload as the raw block", row.Name, row.Format), Hint: `GET dag-cbor block via Accept and ?format and ensure both are the same as ipfs block get output`, @@ -562,21 +410,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - test_expect_success "GET $name from /ipfs for application/$format returns the same payload as format=dag-$format" ' - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o expected && - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=$format" -o plain_output && - test_cmp expected plain_output - ' - Note: we skip this test since we compare responses bytes to bytes above. - */ - /** - test_expect_success "GET $name from /ipfs with application/vnd.ipld.dag-$format returns the same payload as the raw block" ' - ipfs block get "/ipfs/$CID" > expected_block && - curl -sX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o curl_ipfs_dag_block_accept_output && - test_cmp expected_block curl_ipfs_dag_block_accept_output - ' - */ { Name: Fmt("GET {{name}} from /ipfs with application/vnd.ipld.dag-{{format}} returns the same payload as the raw block", row.Name, row.Format), Request: Request(). @@ -588,16 +421,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - # Make sure DAG-* can be requested as plain JSON or CBOR and response has plain Content-Type for interop purposes - - test_expect_success "GET $name with format=$format returns same payload as format=dag-$format but with plain Content-Type" ' - curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o expected && - curl -sD plain_headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=$format" -o plain_output && - test_should_contain "Content-Type: application/$format" plain_headers && - test_cmp expected plain_output - ' - */ { Name: Fmt("GET {{name}} with format={{format}} returns same payload as format=dag-{{format}} but with plain Content-Type", row.Name, row.Format), Hint: `Make sure DAG-* can be requested as plain JSON or CBOR and response has plain Content-Type for interop purposes`, @@ -611,14 +434,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - test_expect_success "GET $name with Accept: application/$format returns same payload as application/vnd.ipld.dag-$format but with plain Content-Type" ' - curl -s -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > expected && - curl -sD plain_headers -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > plain_output && - test_should_contain "Content-Type: application/$format" plain_headers && - test_cmp expected plain_output - ' - */ { Name: Fmt("GET {{name}} with Accept: application/{{format}} returns same payload as application/vnd.ipld.dag-{{format}} but with plain Content-Type", row.Name, row.Format), Request: Request(). @@ -631,24 +446,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - # Make sure expected HTTP headers are returned with the dag- block - - test_expect_success "GET response for application/vnd.ipld.dag-$format has expected Content-Type" ' - curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" >/dev/null 2>curl_output && - test_should_contain "< Content-Type: application/vnd.ipld.dag-$format" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Content-Length" ' - BYTES=$(ipfs block get $CID | wc --bytes) - test_should_contain "< Content-Length: $BYTES" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Content-Disposition" ' - test_should_contain "< Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes nosniff hint" ' - test_should_contain "< X-Content-Type-Options: nosniff" curl_output - ' - */ { Name: Fmt("GET response for application/vnd.ipld.dag-{{format}} has expected Content-Type", row.Format), Hint: `Make sure expected HTTP headers are returned with the dag- block`, @@ -663,12 +460,6 @@ func TestNativeDag(t *testing.T) { Header("X-Content-Type-Options").Hint("includes nosniff hint").Contains("nosniff"), ), }, - /** - test_expect_success "GET for application/vnd.ipld.dag-$format with query filename includes Content-Disposition with custom filename" ' - curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?filename=foobar.$format" >/dev/null 2>curl_output_filename && - test_should_contain "< Content-Disposition: ${disposition}\; filename=\"foobar.$format\"" curl_output_filename - ' - */ { Name: Fmt("GET for application/vnd.ipld.dag-{{format}} with query filename includes Content-Disposition with custom filename", row.Format), Request: Request(). @@ -682,12 +473,6 @@ func TestNativeDag(t *testing.T) { Contains(`{{disposition}}; filename="foobar.{{format}}"`, row.Disposition, row.Format), ), }, - /** - test_expect_success "GET for application/vnd.ipld.dag-$format with ?download=true forces Content-Disposition: attachment" ' - curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?filename=foobar.$format&download=true" >/dev/null 2>curl_output_filename && - test_should_contain "< Content-Disposition: attachment" curl_output_filename - ' - */ { Name: Fmt("GET for application/vnd.ipld.dag-{{format}} with ?download=true forces Content-Disposition: attachment", row.Format), Request: Request(). @@ -702,21 +487,6 @@ func TestNativeDag(t *testing.T) { Contains(`attachment; filename="foobar.{{format}}"`, row.Format), ), }, - /** - # Cache control HTTP headers - # (basic checks, detailed behavior is tested in t0116-gateway-cache.sh) - - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Etag" ' - test_should_contain "< Etag: \"${CID}.dag-$format\"" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes X-Ipfs-Path and X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Path" curl_output && - test_should_contain "< X-Ipfs-Roots" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Cache-Control" ' - test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_output - ' - */ { Name: Fmt("Cache control HTTP headers ({{format}})", row.Format), Hint: `(basic checks, detailed behavior is tested in t0116-gateway-cache.sh)`, @@ -731,15 +501,6 @@ func TestNativeDag(t *testing.T) { Header("Cache-Control").Hint("includes Cache-Control").Contains("public, max-age=29030400, immutable"), ), }, - /** - # HTTP HEAD behavior - test_expect_success "HEAD $name with no explicit format returns HTTP 200" ' - curl -I "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o output && - test_should_contain "HTTP/1.1 200 OK" output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" output && - test_should_contain "Content-Length: " output - ' - */ { Name: Fmt("HEAD {{name}} with no explicit format returns HTTP 200", row.Name), Request: Request(). @@ -752,15 +513,6 @@ func TestNativeDag(t *testing.T) { Header("Content-Length").Hint("includes Content-Length").Exists(), ), }, - /** - test_expect_success "HEAD $name with an explicit DAG-JSON format returns HTTP 200" ' - curl -I "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-json" -o output && - test_should_contain "HTTP/1.1 200 OK" output && - test_should_contain "Etag: \"$CID.dag-json\"" output && - test_should_contain "Content-Type: application/vnd.ipld.dag-json" output && - test_should_contain "Content-Length: " output - ' - */ { Name: Fmt("HEAD {{name}} with an explicit DAG-JSON format returns HTTP 200", row.Name), Request: Request(). @@ -775,14 +527,6 @@ func TestNativeDag(t *testing.T) { Header("Content-Length").Hint("includes Content-Length").Exists(), ), }, - /** - test_expect_success "HEAD $name with only-if-cached for missing block returns HTTP 412 Precondition Failed" ' - MISSING_CID=$(echo "{\"t\": \"$(date +{{}})\"}" | ipfs dag put --store-codec=dag-${format}) && - ipfs block rm -f -q $MISSING_CID && - curl -I -H "Cache-Control: only-if-cached" "http://127.0.0.1:$GWAY_PORT/ipfs/$MISSING_CID" -o output && - test_should_contain "HTTP/1.1 412 Precondition Failed" output - ' - */ { Name: Fmt("HEAD {{name}} with only-if-cached for missing block returns HTTP 412 Precondition Failed", row.Name), Request: Request(). @@ -792,14 +536,6 @@ func TestNativeDag(t *testing.T) { Response: Expect(). Status(412), }, - // test_expect_success "GET $name on /ipfs with Accept: text/html returns HTML (dag-index-html)" ' - // curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output 2>&1 && - // test_should_not_contain "Content-Disposition" curl_output && - // test_should_not_contain "Cache-Control" curl_output && - // test_should_contain "Etag: \"DagIndex-" curl_output && - // test_should_contain "Content-Type: text/html" curl_output && - // test_should_contain "" curl_output - // ' { Name: Fmt("GET {{name}} on /ipfs with Accept: text/html returns HTML (dag-index-html)", row.Name), Request: Request(). @@ -825,8 +561,8 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { ipnsIdDagJSON := "k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2" ipnsIdDagCBOR := "k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l" - ipnsDagJSON := ipns.MustOpenIPNSRecordWithKey(Fmt("t0123/{{id}}.ipns-record", ipnsIdDagJSON)) - ipnsDagCBOR := ipns.MustOpenIPNSRecordWithKey(Fmt("t0123/{{id}}.ipns-record", ipnsIdDagCBOR)) + ipnsDagJSON := ipns.MustOpenIPNSRecordWithKey(Fmt("path_gateway_dag/{{id}}.ipns-record", ipnsIdDagJSON)) + ipnsDagCBOR := ipns.MustOpenIPNSRecordWithKey(Fmt("path_gateway_dag/{{id}}.ipns-record", ipnsIdDagCBOR)) table := []struct { Name string @@ -840,17 +576,12 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { tests := SugarTests{} for _, row := range table { - plain := car.MustOpenUnixfsCar(Fmt("t0123/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() + plain := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() plainCID := plain.Cid() // # IPNS behavior (should be same as immutable /ipfs, but with different caching headers) // # To keep tests small we only confirm payload is the same, and then only test delta around caching headers. tests = append(tests, SugarTests{ - // test_expect_success "GET $name from /ipns without explicit format returns the same payload as /ipfs" ' - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o ipfs_output && - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID" -o ipns_output && - // test_cmp ipfs_output ipns_output - // ' { Name: Fmt("GET {{name}} from /ipns without explicit format returns the same payload as /ipfs", row.Name), Requests: Requests( @@ -862,11 +593,6 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { Responses: Responses(). HaveTheSamePayload(), }, - // test_expect_success "GET $name from /ipns without explicit format returns the same payload as /ipfs" ' - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o ipfs_output && - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID?format=dag-$format" -o ipns_output && - // test_cmp ipfs_output ipns_output - // ' { Name: Fmt("GET {{name}} from /ipns with explicit format returns the same payload as /ipfs", row.Name), Requests: Requests( @@ -880,15 +606,6 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { Responses: Responses(). HaveTheSamePayload(), }, - - // test_expect_success "GET $name from /ipns with explicit application/vnd.ipld.dag-$format has expected headers" ' - // curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID" >/dev/null 2>curl_output && - // test_should_not_contain "Cache-Control" curl_output && - // test_should_contain "< Content-Type: application/vnd.ipld.dag-$format" curl_output && - // test_should_contain "< Etag: \"${CID}.dag-$format\"" curl_output && - // test_should_contain "< X-Ipfs-Path" curl_output && - // test_should_contain "< X-Ipfs-Roots" curl_output - // ' { Name: Fmt("GET {{name}} from /ipns with explicit application/vnd.ipld.dag-{{format}} has expected headers", row.Name, row.Format), Request: Request(). @@ -902,18 +619,6 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { Header("X-Ipfs-Roots").Not().IsEmpty(), ), }, - // # When Accept header includes text/html and no explicit format is requested for DAG-(CBOR|JSON) - // # The gateway returns generated HTML index (see dag-index-html) for web browsers (similar to dir-index-html returned for unixfs dirs) - // # As this is generated, we don't return immutable Cache-Control, even on /ipfs (same as for dir-index-html) - - // test_expect_success "GET $name on /ipns with Accept: text/html returns HTML (dag-index-html)" ' - // curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID" > curl_output 2>&1 && - // test_should_not_contain "Content-Disposition" curl_output && - // test_should_not_contain "Cache-Control" curl_output && - // test_should_contain "Etag: \"DagIndex-" curl_output && - // test_should_contain "Content-Type: text/html" curl_output && - // test_should_contain "" curl_output - // ' { Name: Fmt("GET {{name}} on /ipns with Accept: text/html returns HTML (dag-index-html)", row.Name), Request: Request(). diff --git a/tests/path_gateway_raw_test.go b/tests/path_gateway_raw_test.go index b0aac353c..0dc071a99 100644 --- a/tests/path_gateway_raw_test.go +++ b/tests/path_gateway_raw_test.go @@ -12,7 +12,7 @@ import ( ) func TestGatewayBlock(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0117-gateway-block.car") + fixture := car.MustOpenUnixfsCar("gateway-raw-block.car") tests := SugarTests{ { @@ -121,6 +121,7 @@ func TestGatewayBlock(t *testing.T) { Header("Cache-Control"). Hint("It should be public, immutable and have max-age of at least 31536000."). Checks(func(v string) bool { + // TODO: port this to a regular check. directives := strings.Split(strings.ReplaceAll(v, " ", ""), ",") dir := make(map[string]string) for _, directive := range directives { diff --git a/tests/path_gateway_tar_test.go b/tests/path_gateway_tar_test.go index 3425343e2..df7145bb0 100644 --- a/tests/path_gateway_tar_test.go +++ b/tests/path_gateway_tar_test.go @@ -10,57 +10,18 @@ import ( "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this was t0122_gateway_tar_test.go - -// "Test HTTP Gateway TAR (application/x-tar) Support" func TestTar(t *testing.T) { - /** - test_expect_success "Add CARs with relative paths to test with" ' - ipfs dag import ../t0122-gateway-tar/outside-root.car > import_output && - test_should_contain $OUTSIDE_ROOT_CID import_output && - ipfs dag import ../t0122-gateway-tar/inside-root.car > import_output && - test_should_contain $INSIDE_ROOT_CID import_output - ' - */ - fixtureOutside := car.MustOpenUnixfsCar("t0122/outside-root.car") - fixtureInside := car.MustOpenUnixfsCar("t0122/inside-root.car") + fixtureOutside := car.MustOpenUnixfsCar("path_gateway_tar/outside-root.car") + fixtureInside := car.MustOpenUnixfsCar("path_gateway_tar/inside-root.car") outsideRootCID := fixtureOutside.MustGetCid() insideRootCID := fixtureInside.MustGetCid() - // OUTSIDE_ROOT_CID="bafybeicaj7kvxpcv4neaqzwhrqqmdstu4dhrwfpknrgebq6nzcecfucvyu" - // INSIDE_ROOT_CID="bafybeibfevfxlvxp5vxobr5oapczpf7resxnleb7tkqmdorc4gl5cdva3y" - // - // test_expect_success "Add the test directory" ' - // ipfs dag import ../t0122-gateway-tar/fixtures.car - // ' - // DIR_CID=bafybeig6ka5mlwkl4subqhaiatalkcleo4jgnr3hqwvpmsqfca27cijp3i # ./rootDir - // FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt - // FILE_SIZE=34 - - fixture := car.MustOpenUnixfsCar("t0122/fixtures.car") + fixture := car.MustOpenUnixfsCar("path_gateway_tar/fixtures.car") dirCID := fixture.MustGetCid() // root dir fileCID := fixture.MustGetCid("ą", "ę", "file-źł.txt") tests := SugarTests{ - /** - test_expect_success "GET TAR with format=tar and extract" ' - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=tar" | tar -x - ' - test_expect_success "GET TAR with format=tar has expected Content-Type" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=tar" > curl_output_filename 2>&1 && - test_should_contain "Content-Disposition: attachment;" curl_output_filename && - test_should_contain "Etag: W/\"$FILE_CID.x-tar" curl_output_filename && - test_should_contain "Content-Type: application/x-tar" curl_output_filename - ' - test_expect_success "GET TAR has expected root file" ' - rm -rf outputDir && mkdir outputDir && - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=tar" | tar -x -C outputDir && - test -f "outputDir/$FILE_CID" && - echo "I am a txt file on path with utf8" > expected && - test_cmp expected outputDir/$FILE_CID - ' - */ { Name: "GET TAR with format=tar and extract", Request: Request(). @@ -80,17 +41,6 @@ func TestTar(t *testing.T) { ), ), }, - /** - test_expect_success "GET TAR with 'Accept: application/x-tar' and extract" ' - curl -H "Accept: application/x-tar" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" | tar -x - ' - test_expect_success "GET TAR with 'Accept: application/x-tar' has expected Content-Type" ' - curl -sD - -H "Accept: application/x-tar" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output_filename 2>&1 && - test_should_contain "Content-Disposition: attachment;" curl_output_filename && - test_should_contain "Etag: W/\"$FILE_CID.x-tar" curl_output_filename && - test_should_contain "Content-Type: application/x-tar" curl_output_filename - ' - */ { Name: "GET TAR with 'Accept: application/x-tar' and extract", Request: Request(). @@ -106,15 +56,6 @@ func TestTar(t *testing.T) { IsTarFile(), ), }, - /** - test_expect_success "GET TAR has expected root directory" ' - rm -rf outputDir && mkdir outputDir && - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=tar" | tar -x -C outputDir && - test -d "outputDir/$DIR_CID" && - echo "I am a txt file on path with utf8" > expected && - test_cmp expected outputDir/$DIR_CID/ą/ę/file-źł.txt - ' - */ { Name: "GET TAR has expected root directory", Request: Request(). @@ -130,12 +71,6 @@ func TestTar(t *testing.T) { ), ), }, - /** - test_expect_success "GET TAR with explicit ?filename= succeeds with modified Content-Disposition header" " - curl -fo actual -D actual_headers 'http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?filename=testтест.tar&format=tar' && - grep -F 'Content-Disposition: attachment; filename=\"test____.tar\"; filename*=UTF-8'\'\''test%D1%82%D0%B5%D1%81%D1%82.tar' actual_headers - " - */ { Name: "GET TAR with explicit ?filename= succeeds with modified Content-Disposition header", Request: Request(). @@ -145,16 +80,9 @@ func TestTar(t *testing.T) { Response: Expect(). Status(200). Headers( - // Note: golang's compiler assumes the "weird" string is a format string, we use `"{{x}}"` to move it out of the way. - Header("Content-Disposition").Contains("{{x}}", `attachment; filename="test____.tar"; filename*=UTF-8''test%D1%82%D0%B5%D1%81%D1%82.tar`), + Header("Content-Disposition").Contains(`attachment; filename="test____.tar"; filename*=UTF-8''test%D1%82%D0%B5%D1%81%D1%82.tar`), ), }, - /** - test_expect_success "GET TAR with relative paths outside root fails" ' - curl -o - "http://127.0.0.1:$GWAY_PORT/ipfs/$OUTSIDE_ROOT_CID?format=tar" > curl_output_filename && - test_should_contain "relative UnixFS paths outside the root are now allowed" curl_output_filename - ' - */ { Name: "GET TAR with relative paths outside root fails", Request: Request(). @@ -165,13 +93,6 @@ func TestTar(t *testing.T) { Contains("relative UnixFS paths outside the root are now allowed"), ), }, - /** - test_expect_success "GET TAR with relative paths inside root works" ' - rm -rf outputDir && mkdir outputDir && - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$INSIDE_ROOT_CID?format=tar" | tar -x -C outputDir && - test -f outputDir/$INSIDE_ROOT_CID/foobar/file - ' - */ { Name: "GET TAR with relative paths inside root works", Request: Request(). diff --git a/tests/path_gateway_unixfs_test.go b/tests/path_gateway_unixfs_test.go index 8fe4fe77f..e0250809f 100644 --- a/tests/path_gateway_unixfs_test.go +++ b/tests/path_gateway_unixfs_test.go @@ -12,24 +12,12 @@ import ( . "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this was in t0115_gateway_dir_listing_test.go - func TestUnixFSDirectoryListing(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0115/fixtures.car") + fixture := car.MustOpenUnixfsCar("dir_listing/fixtures.car") root := fixture.MustGetNode() file := fixture.MustGetNode("ą", "ę", "file-źł.txt") tests := SugarTests{ - // ## ============================================================================ - // ## Test dir listing on path gateway (eg. 127.0.0.1:8080/ipfs/) - // ## ============================================================================ - // test_expect_success "path gw: backlink on root CID should be hidden" ' - // - // curl -sD - http://127.0.0.1:$GWAY_PORT/ipfs/${DIR_CID}/ > list_response && - // test_should_contain "Index of" list_response && - // test_should_not_contain ".." list_response, - // - // ' { Name: "path gw: backlink on root CID should be hidden (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -41,11 +29,6 @@ func TestUnixFSDirectoryListing(t *testing.T) { Not(Contains(`..`, root.Cid())), )), }, - // test_expect_success "path gw: redirect dir listing to URL with trailing slash" ' - // curl -sD - http://127.0.0.1:$GWAY_PORT/ipfs/${DIR_CID}/ą/ę > list_response && - // test_should_contain "HTTP/1.1 301 Moved Permanently" list_response && - // test_should_contain "Location: /ipfs/${DIR_CID}/%c4%85/%c4%99/" list_response - // ' { Name: "path gw: redirect dir listing to URL with trailing slash", Request: Request(). @@ -56,23 +39,6 @@ func TestUnixFSDirectoryListing(t *testing.T) { Header("Location", `/ipfs/{{cid}}/%c4%85/%c4%99/`, root.Cid()), ), }, - // 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/$DIR_CID/ą/ę" list_response - // ' - // test_expect_success "path gw: backlink on subdirectory should point at parent directory" ' - // test_should_contain ".." list_response - // ' - // test_expect_success "path gw: name column should be a link to its content path" ' - // test_should_contain "file-źł.txt" list_response - // ' - // test_expect_success "path gw: hash column should be a CID link with filename param" ' - // test_should_contain "" list_response - // ' { Name: "path gw: dir listing HTML response (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -430,10 +396,8 @@ func TestGatewayCacheWithIPNS(t *testing.T) { RunWithSpecs(t, tests, specs.PathGatewayUnixFS, specs.PathGatewayIPNS) } -// TODO(laurent): this were in t0113_gateway_symlink_test - func TestGatewaySymlink(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0113-gateway-symlink.car") + fixture := car.MustOpenUnixfsCar("path_gateway_unixfs/symlink.car") rootDirCID := fixture.MustGetCid() tests := SugarTests{ @@ -470,48 +434,3 @@ func TestGatewaySymlink(t *testing.T) { RunWithSpecs(t, tests, specs.PathGatewayUnixFS) } - -// TODO(laurent): this were in t0112_gateway_cors_test -func TestCors(t *testing.T) { - cidHello := "bafkqabtimvwgy3yk" // hello - - tests := SugarTests{ - { - Name: "GET Responses from Gateway should include CORS headers allowing JS from other origins to read the data cross-origin.", - Request: Request(). - Path("/ipfs/{{CID}}/", cidHello), - Response: Expect(). - Headers( - Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET"), - Header("Access-Control-Allow-Headers").Has("Range"), - Header("Access-Control-Expose-Headers").Has( - "Content-Range", - "Content-Length", - "X-Ipfs-Path", - "X-Ipfs-Roots", - ), - ), - }, - { - Name: "OPTIONS to Gateway succeeds", - Request: Request(). - Method("OPTIONS"). - Path("/ipfs/{{CID}}/", cidHello), - Response: Expect(). - Headers( - Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET"), - Header("Access-Control-Allow-Headers").Has("Range"), - Header("Access-Control-Expose-Headers").Has( - "Content-Range", - "Content-Length", - "X-Ipfs-Path", - "X-Ipfs-Roots", - ), - ), - }, - } - - RunWithSpecs(t, tests, specs.PathGatewayUnixFS) -} diff --git a/tests/redirects_file_test.go b/tests/redirects_file_test.go index 7f8e63b17..af1c85c9a 100644 --- a/tests/redirects_file_test.go +++ b/tests/redirects_file_test.go @@ -13,18 +13,13 @@ import ( . "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this were in t0109_gateway_web_redirects_test - func TestRedirectsFileSupport(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0109-redirects.car") + fixture := car.MustOpenUnixfsCar("redirects_file/redirects.car") redirectDir := fixture.MustGetNode("examples") redirectDirCID := redirectDir.Base32Cid() - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/404.html | cut -d "/" -f3) custom404 := fixture.MustGetNode("examples", "404.html") - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/410.html | cut -d "/" -f3) custom410 := fixture.MustGetNode("examples", "410.html") - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/451.html | cut -d "/" -f3) custom451 := fixture.MustGetNode("examples", "451.html") tests := SugarTests{} @@ -44,13 +39,6 @@ func TestRedirectsFileSupport(t *testing.T) { redirectDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, redirectDirCID, u.Host) tests = append(tests, SugarTests{ - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/redirect-one" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /one.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file", Request: Request(). @@ -62,13 +50,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/one.html"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/301-redirect-one redirects with 301, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/301-redirect-one" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /one.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/301-redirect-one redirects with 301, per _redirects file", Request: Request(). @@ -79,13 +60,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/one.html"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/302-redirect-two redirects with 302, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/302-redirect-two" > response && - // test_should_contain "302 Found" response && - // test_should_contain "Location: /two.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/302-redirect-two redirects with 302, per _redirects file", Request: Request(). @@ -96,13 +70,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/two.html"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/200-index returns 200, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/200-index" > response && - // test_should_contain "my index" response && - // test_should_contain "200 OK" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/200-index returns 200, per _redirects file", Request: Request(). @@ -111,13 +78,6 @@ func TestRedirectsFileSupport(t *testing.T) { Status(200). Body(Contains("my index")), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/posts/:year/:month/:day/:title redirects with 301 and placeholders, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/posts/2022/01/01/hello-world" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /articles/2022/01/01/hello-world" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/posts/:year/:month/:day/:title redirects with 301 and placeholders, per _redirects file", Request: Request(). @@ -128,13 +88,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/articles/2022/01/01/hello-world"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/splat/one.html redirects with 301 and splat placeholder, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/splat/one.html" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /redirected-splat/one.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/splat/one.html redirects with 301 and splat placeholder, per _redirects file", Request: Request(). @@ -145,16 +98,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/redirected-splat/one.html"), ), }, - // # ensure custom 4xx works and has the same cache headers as regular /ipfs/ path - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/not-found/has-no-redirects-entry returns custom 404, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/not-found/has-no-redirects-entry" > response && - // test_should_contain "404 Not Found" response && - // test_should_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_contain "Etag: \"$CUSTOM_4XX_CID\"" response && - // test_should_contain "my 404" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/not-found/has-no-redirects-entry returns custom 404, per _redirects file", Request: Request(). @@ -167,14 +110,6 @@ func TestRedirectsFileSupport(t *testing.T) { ). Body(Contains(custom404.ReadFile())), }, - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/410.html | cut -d "/" -f3) - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/gone/has-no-redirects-entry returns custom 410, per _redirects file" ' - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/gone/has-no-redirects-entry" > response && - // test_should_contain "410 Gone" response && - // test_should_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_contain "Etag: \"$CUSTOM_4XX_CID\"" response && - // test_should_contain "my 410" response - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/gone/has-no-redirects-entry returns custom 410, per _redirects file", Request: Request(). @@ -187,16 +122,6 @@ func TestRedirectsFileSupport(t *testing.T) { ). Body(Contains(custom410.ReadFile())), }, - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/451.html | cut -d "/" -f3) - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/unavail/has-no-redirects-entry returns custom 451, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/unavail/has-no-redirects-entry" > response && - // test_should_contain "451 Unavailable For Legal Reasons" response && - // test_should_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_contain "Etag: \"$CUSTOM_4XX_CID\"" response && - // test_should_contain "my 451" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/unavail/has-no-redirects-entry returns custom 451, per _redirects file", Request: Request(). @@ -209,13 +134,6 @@ func TestRedirectsFileSupport(t *testing.T) { ). Body(Contains(custom451.ReadFile())), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/catch-all returns 200, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/catch-all" > response && - // test_should_contain "200 OK" response && - // test_should_contain "my index" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/catch-all returns 200, per _redirects file", Request: Request(). @@ -224,46 +142,16 @@ func TestRedirectsFileSupport(t *testing.T) { Status(200). Body(Contains("my index")), }, - // # This test ensures _redirects is supported only on Web Gateways that use Host header (DNSLink, Subdomain) - // test_expect_success "request for http://127.0.0.1:$GWAY_PORT/ipfs/$REDIRECTS_DIR_CID/301-redirect-one returns generic 404 (no custom 404 from _redirects since no origin isolation)" ' - // - // curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$REDIRECTS_DIR_CID/301-redirect-one" > response && - // test_should_contain "404 Not Found" response && - // test_should_not_contain "my 404" response - // - // ' - // { - // // TODO: confirm with lidel: this should be skipped - // Name: "This test ensures _redirects is supported only on Web Gateways that use Host header (DNSLink, Subdomain)", - // Hint: ` - // We expect the request to fail with a 404 (do not use the _redirect), and that 404 should not contain the custom 404 body. - // `, - // Request: Request(). - // URL("http://127.0.0.1:8080/ipfs/{{etag}}/301-redirect-one", redirectDirCID), - // Response: Expect(). - // Status(404). - // Body(Not(Contains(custom404.ReadFile()))), - // }, }...) // # Invalid file, containing forced redirect - // INVALID_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/forced | cut -d "/" -f3) invalidRedirectsDirCID := fixture.MustGetNode("forced").Base32Cid() - // INVALID_REDIRECTS_DIR_HOSTNAME="${INVALID_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" invalidDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, invalidRedirectsDirCID, u.Host) - // TOO_LARGE_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/too-large | cut -d "/" -f3) + tooLargeRedirectsDirCID := fixture.MustGetNode("too-large").Base32Cid() - // TOO_LARGE_REDIRECTS_DIR_HOSTNAME="${TOO_LARGE_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" tooLargeDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, tooLargeRedirectsDirCID, u.Host) tests = append(tests, SugarTests{ - // # if accessing a path that doesn't exist, read _redirects and fail parsing, and return error - // test_expect_success "invalid file: request for $INVALID_REDIRECTS_DIR_HOSTNAME/not-found returns error about invalid redirects file" ' - // curl -sD - --resolve $INVALID_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$INVALID_REDIRECTS_DIR_HOSTNAME/not-found" > response && - // test_should_contain "500" response && - // test_should_contain "could not parse _redirects:" response && - // test_should_contain "forced redirects (or \"shadowing\") are not supported" response - // ' { Name: "invalid file: request for $INVALID_REDIRECTS_DIR_HOSTNAME/not-found returns error about invalid redirects file", Hint: `if accessing a path that doesn't exist, read _redirects and fail parsing, and return error`, @@ -278,13 +166,6 @@ func TestRedirectsFileSupport(t *testing.T) { ), ), }, - // # if accessing a path that doesn't exist and _redirects file is too large, return error - // test_expect_success "invalid file: request for $TOO_LARGE_REDIRECTS_DIR_HOSTNAME/not-found returns error about too large redirects file" ' - // curl -sD - --resolve $TOO_LARGE_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$TOO_LARGE_REDIRECTS_DIR_HOSTNAME/not-found" > response && - // test_should_contain "500" response && - // test_should_contain "could not parse _redirects:" response && - // test_should_contain "redirects file size cannot exceed" response - // ' { Name: "invalid file: request for $TOO_LARGE_REDIRECTS_DIR_HOSTNAME/not-found returns error about too large redirects file", Hint: `if accessing a path that doesn't exist and _redirects file is too large, return error`, @@ -300,13 +181,61 @@ func TestRedirectsFileSupport(t *testing.T) { ), }, }...) + + // # With CRLF line terminator + newlineRedirectsDirCID := fixture.MustGetNode("newlines").Base32Cid() + newlineBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, newlineRedirectsDirCID, u.Host) + + // # Good codes + goodRedirectDirCID := fixture.MustGetNode("good-codes").Base32Cid() + goodRedirectDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, goodRedirectDirCID, u.Host) + + // # Bad codes + badRedirectDirCID := fixture.MustGetNode("bad-codes").Base32Cid() + badRedirectDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, badRedirectDirCID, u.Host) + + tests = append(tests, SugarTests{ + { + Name: "newline: request for $NEWLINE_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file", + Request: Request(). + URL("{{url}}/redirect-one", newlineBaseURL), + Response: Expect(). + Status(301). + Headers( + Header("Location").Equals("/one.html"), + ), + }, + { + Name: "good codes: request for $GOOD_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file", + Request: Request(). + URL("{{url}}/a301", goodRedirectDirBaseURL), + Response: Expect(). + Status(301). + Headers( + Header("Location").Equals("/b301"), + ), + }, + { + Name: "bad codes: request for $BAD_REDIRECTS_DIR_HOSTNAME/found.html doesn't return error about bad code", + Request: Request(). + URL("{{url}}/found.html", badRedirectDirBaseURL), + Response: Expect(). + Status(200). + Body( + And( + Contains("my found"), + Not(Contains("unsupported redirect status")), + ), + ), + }, + }...) } RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGatewayIPFS, specs.RedirectsFile) } func TestRedirectsFileSupportWithDNSLink(t *testing.T) { - dnsLinks := dnslink.MustOpenDNSLink("t0109-dnslink.yml") + dnsLinks := dnslink.MustOpenDNSLink("redirects_file/dnslink.yml") dnsLink := dnsLinks.MustGet("custom-dnslink") gatewayURL := SubdomainGatewayURL @@ -318,20 +247,6 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { dnsLinkBaseUrl := Fmt("{{scheme}}://{{dnslink}}.{{host}}", u.Scheme, dnsLink, u.Host) tests := SugarTests{ - // # make sure test setup is valid (fail if CoreAPI is unable to resolve) - // test_expect_success "spoofed DNSLink record resolves in cli" " - // ipfs resolve /ipns/$DNSLINK_FQDN > result && - // test_should_contain \"$REDIRECTS_DIR_CID\" result && - // ipfs cat /ipns/$DNSLINK_FQDN/_redirects > result && - // test_should_contain \"index.html\" result - // " - // SKIPPED - - // test_expect_success "request for $DNSLINK_FQDN/redirect-one redirects with default of 301, per _redirects file" ' - // curl -sD - --resolve $DNSLINK_FQDN:$GWAY_PORT:127.0.0.1 "http://$DNSLINK_FQDN:$GWAY_PORT/redirect-one" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /one.html" response - // ' { Name: "request for $DNSLINK_FQDN/redirect-one redirects with default of 301, per _redirects file", Request: Request(). @@ -342,16 +257,6 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { Header("Location", "/one.html"), ), }, - // # ensure custom 404 works and has the same cache headers as regular /ipns/ paths - // test_expect_success "request for $DNSLINK_FQDN/en/has-no-redirects-entry returns custom 404, per _redirects file" ' - // curl -sD - --resolve $DNSLINK_FQDN:$GWAY_PORT:127.0.0.1 "http://$DNSLINK_FQDN:$GWAY_PORT/not-found/has-no-redirects-entry" > response && - // test_should_contain "404 Not Found" response && - // test_should_contain "Etag: \"Qmd9GD7Bauh6N2ZLfNnYS3b7QVAijbud83b8GE8LPMNBBP\"" response && - // test_should_not_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_not_contain "immutable" response && - // test_should_contain "Date: " response && - // test_should_contain "my 404" response - // ' { Name: "request for $DNSLINK_FQDN/en/has-no-redirects-entry returns custom 404, per _redirects file", Hint: `ensure custom 404 works and has the same cache headers as regular /ipns/ paths`, @@ -366,28 +271,9 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { Header("Date").Exists(), ). Body( - // TODO: I like the readable part here, maybe rewrite to load the file. Contains("my 404"), ), }, - // test_expect_success "request for $NO_DNSLINK_FQDN/redirect-one does not redirect, since DNSLink is disabled" ' - // curl -sD - --resolve $NO_DNSLINK_FQDN:$GWAY_PORT:127.0.0.1 "http://$NO_DNSLINK_FQDN:$GWAY_PORT/redirect-one" > response && - // test_should_not_contain "one.html" response && - // test_should_not_contain "301 Moved Permanently" response && - // test_should_not_contain "Location:" response - // ' - // TODO(lidel): this test seems to validate some kubo behavior not really gateway. - // { - // Name: "request for $NO_DNSLINK_FQDN/redirect-one does not redirect, since DNSLink is disabled", - // Request: Request(). - // URL("{{url}}/redirect-one", noDnsLinkBaseUrl), - // Response: Expect(). - // // TODO: add "status not equal to 301" check. - // // TODO: what `test_should_not_contain "one.html" response` actually means? No location correct? - // Headers( - // Header("Location").Not().Exists(), - // ), - // }, } RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.DNSLinkGateway, specs.RedirectsFile) diff --git a/tests/subdomain_gateway_ipfs_test.go b/tests/subdomain_gateway_ipfs_test.go index fad892e5e..1424e504f 100644 --- a/tests/subdomain_gateway_ipfs_test.go +++ b/tests/subdomain_gateway_ipfs_test.go @@ -14,7 +14,7 @@ import ( // TODO(laurent): this was in t0115_gateway_dir_listing_test.go func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0115/fixtures.car") + fixture := car.MustOpenUnixfsCar("dir_listing/fixtures.car") root := fixture.MustGetNode() file := fixture.MustGetNode("ą", "ę", "file-źł.txt") @@ -32,18 +32,7 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { t.Fatal(err) } - // ## ============================================================================ - // ## Test dir listing on subdomain gateway (eg. .ipfs.localhost:8080) - // ## ============================================================================ tests = append(tests, SugarTests{ - // 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 "subdomain gw: backlink on root CID should be hidden" ' - // 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_not_contain ".." list_response - // ' { Name: "backlink on root CID should be hidden (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -60,11 +49,6 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { Not(Contains(`..`)), )), }, - // test_expect_success "subdomain gw: redirect dir listing to URL with trailing slash" ' - // curl -sD - --resolve $DIR_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DIR_HOSTNAME:$GWAY_PORT/ą/ę > list_response && - // test_should_contain "HTTP/1.1 301 Moved Permanently" list_response && - // test_should_contain "Location: /%c4%85/%c4%99/" list_response - // ' { Name: "redirect dir listing to URL with trailing slash", Request: Request(). @@ -80,23 +64,6 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { Header("Location").Equals(`/%c4%85/%c4%99/`), ), }, - // test_expect_success "subdomain 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: backlink on subdirectory should point at parent directory" ' - // test_should_contain ".." list_response - // ' - // test_expect_success "subdomain gw: breadcrumbs should leverage path-based router mounted on the parent domain" ' - // test_should_contain "/ipfs/$DIR_CID/ą/ę" list_response - // ' - // test_expect_success "subdomain gw: name column should be a link to content root mounted at subdomain origin" ' - // test_should_contain "file-źł.txt" list_response - // ' - // test_expect_success "subdomain gw: hash column should be a CID link to path router with filename param" ' - // test_should_contain "" list_response - // ' { Name: "Regular dir listing HTML (TODO: cleanup Kubo-specifics)", Request: Request().URL( @@ -136,15 +103,11 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { }...) } - // Body expect to find substring '', - RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGatewayIPFS) } -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - func TestGatewaySubdomains(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0114-gateway_subdomains.car") + fixture := car.MustOpenUnixfsCar("subdomain_gateway/fixtures.car") CIDVal := string(fixture.MustGetRawData("hello-CIDv1")) // hello DirCID := fixture.MustGetCid("testdirlisting") @@ -210,10 +173,6 @@ func TestGatewaySubdomains(t *testing.T) { Contains("{{scheme}}://{{cid}}.ipfs.{{host}}/", u.Scheme, CIDv0to1, u.Host), ), }, - // ============================================================================ - // Test subdomain-based requests to a local gateway with default config - // (origin per content root at http://*.example.com) - // ============================================================================ { Name: "request for {CID}.ipfs.example.com should return expected payload", Request: Request().URL("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, CIDv1, u.Host), @@ -260,7 +219,7 @@ func TestGatewaySubdomains(t *testing.T) { )), }, { - Name: "request for deep path resource at {cid}.ipfs.localhost/sub/dir/file", + Name: "request for deep path resource at {cid}.ipfs.example.com/sub/dir/file", Request: Request().URL("{{scheme}}://{{cid}}.ipfs.{{host}}/ipfs/ipns/bar", u.Scheme, DirCID, u.Host), Response: Expect(). Status(200). @@ -283,17 +242,6 @@ func TestGatewaySubdomains(t *testing.T) { ), ), }, - // ## ============================================================================ - // ## Test subdomain-based requests with a custom hostname config - // ## (origin per content root at http://*.example.com) - // ## ============================================================================ - - // # example.com/ip(f|n)s/* - // # ============================================================================= - - // # path requests to the root hostname should redirect - // # to a subdomain URL with proper origin isolation - { Name: "request for example.com/ipfs/{CIDv1} produces redirect to {CIDv1}.ipfs.example.com", Hint: "path requests to the root hostname should redirect to a subdomain URL with proper origin isolation", @@ -303,7 +251,6 @@ func TestGatewaySubdomains(t *testing.T) { Header("Location").Equals("{{scheme}}://{{cid}}.ipfs.{{host}}/", u.Scheme, CIDv1, u.Host), ), }, - { Name: "request for example.com/ipfs/{InvalidCID} produces useful error before redirect", Hint: "error message should include original CID (and it should be case-sensitive, as we can't assume everyone uses base32)", @@ -333,7 +280,6 @@ func TestGatewaySubdomains(t *testing.T) { Header("Location").Equals("https://{{cid}}.ipfs.{{host}}/", CIDv1, u.Host), ), }, - { Name: "request for example.com/ipfs/?uri=ipfs%3A%2F%2F.. produces redirect to /ipfs/.. content path", Hint: "Support ipfs:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler", @@ -348,7 +294,7 @@ func TestGatewaySubdomains(t *testing.T) { ), }, { - Name: "request for a too long CID at localhost/ipfs/{CIDv1} returns human readable error", + Name: "request for a too long CID at example.com/ipfs/{CIDv1} returns human readable error", Hint: "router should not redirect to hostnames that could fail due to DNS limits", Request: Request().URL("{{url}}/ipfs/{{cid}}", gatewayURL, CIDv1_TOO_LONG), Response: Expect(). @@ -356,7 +302,7 @@ func TestGatewaySubdomains(t *testing.T) { Body(Contains("CID incompatible with DNS label length limit of 63")), }, { - Name: "request for a too long CID at {CIDv1}.ipfs.localhost returns expected payload", + Name: "request for a too long CID at {CIDv1}.ipfs.example.com returns expected payload", Hint: "direct request should also fail (provides the same UX as router and avoids confusion)", Request: Request().URL("{{scheme}}://{{cid}}.ipfs.{{host}}/", u.Scheme, CIDv1_TOO_LONG, u.Host), Response: Expect(). @@ -367,14 +313,16 @@ func TestGatewaySubdomains(t *testing.T) { // ## Test support for X-Forwarded-Host // ## ============================================================================ { - Name: "request for http://fake.domain.com/ipfs/{CID} doesn't match the example.com gateway", - Request: Request().URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1), + Name: "request for http://fake.domain.com/ipfs/{CID} doesn't match the example.com gateway", + Request: Request(). + URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1), Response: Expect(). Status(200), }, { Name: "request for http://fake.domain.com/ipfs/{CID} with X-Forwarded-Host: example.com match the example.com gateway", - Request: Request().URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). + Request: Request(). + URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). Header("X-Forwarded-Host", u.Host), Response: Expect(). Status(301). @@ -384,7 +332,8 @@ func TestGatewaySubdomains(t *testing.T) { }, { Name: "request for http://fake.domain.com/ipfs/{CID} with X-Forwarded-Host: example.com and X-Forwarded-Proto: https match the example.com gateway, redirect with https", - Request: Request().URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). + Request: Request(). + URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). Header("X-Forwarded-Host", u.Host). Header("X-Forwarded-Proto", "https"), Response: Expect(). diff --git a/tests/subdomain_gateway_ipns_test.go b/tests/subdomain_gateway_ipns_test.go index 3c2376aba..d99d8b5e0 100644 --- a/tests/subdomain_gateway_ipns_test.go +++ b/tests/subdomain_gateway_ipns_test.go @@ -14,17 +14,14 @@ import ( "github.com/multiformats/go-multicodec" ) -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - func TestGatewaySubdomainAndIPNS(t *testing.T) { tests := SugarTests{} - rsaFixture := ipns.MustOpenIPNSRecordWithKey("t0114/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record") - ed25519Fixture := ipns.MustOpenIPNSRecordWithKey("t0114/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record") + rsaFixture := ipns.MustOpenIPNSRecordWithKey("subdomain_gateway/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record") + ed25519Fixture := ipns.MustOpenIPNSRecordWithKey("subdomain_gateway/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record") - car := car.MustOpenUnixfsCar("t0114/fixtures.car") - helloCID := "bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am" - payload := string(car.MustGetRawData(helloCID)) + car := car.MustOpenUnixfsCar("subdomain_gateway/fixtures.car") + payload := string(car.MustGetRawData("hello-CIDv1")) // We're going to run the same test against multiple gateways (localhost, and a subdomain gateway) gatewayURLs := []string{ @@ -45,15 +42,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { for _, record := range ipnsRecords { tests = append(tests, SugarTests{ - // # /ipns/ - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "http://localhost:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \ - // "Location: http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "http://localhost:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \ - // "Location: http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" { Name: "request for /ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain", Request: Request(). @@ -65,16 +53,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { Equals("{{scheme}}://{{cid}}.ipns.{{host}}/", u.Scheme, record.IdV1(), u.Host), ), }, - // # *.ipns.localhost - // # .ipns.localhost - // test_localhost_gateway_response_should_contain \ - // "request for {CIDv1-libp2p-key}.ipns.localhost returns expected payload" \ - // "http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT" \ - // "$CID_VAL" - // test_localhost_gateway_response_should_contain \ - // "request for {CIDv1-libp2p-key}.ipns.localhost returns expected payload" \ - // "http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT" \ - // "$CID_VAL" { Name: "request for {CIDv1-libp2p-key}.ipns.{gateway} returns expected payload", Request: Request(). @@ -83,14 +61,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { Status(200). BodyWithHint("Request for {{cid}}.ipns.{{host}} returns expected payload", payload), }, - // test_localhost_gateway_response_should_contain \ - // "localhost request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ - // "http://${RSA_IPNS_IDv1_DAGPB}.ipns.localhost:$GWAY_PORT" \ - // "Location: http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" - // test_localhost_gateway_response_should_contain \ - // "localhost request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ - // "http://${ED25519_IPNS_IDv1_DAGPB}.ipns.localhost:$GWAY_PORT" \ - // "Location: http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" { Name: "request for {CIDv1-dag-pb}.ipns.{gateway} redirects to CID with libp2p-key multicodec", Request: Request(). @@ -102,19 +72,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { Equals("{{scheme}}://{{cid}}.ipns.{{host}}/", u.Scheme, record.IdV1(), u.Host), ), }, - // # example.com/ipns/ - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \ - // "Location: http://${RSA_IPNS_IDv1}.ipns.example.com/" - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \ - // "Location: http://${ED25519_IPNS_IDv1}.ipns.example.com/" - // NOTE: Done above, thanks to the loop - // // # *.ipns.example.com // # ============================================================================ @@ -184,20 +141,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { } tests = append(tests, SugarTests{ - // ## Test subdomain handling of CIDs that do not fit in a single DNS Label (>63chars) - // ## https://github.com/ipfs/go-ipfs/issues/7318 - // ## ============================================================================ - // # local: *.localhost - // test_localhost_gateway_response_should_contain \ - // "request for a ED25519 libp2p-key at localhost/ipns/{b58mh} returns Location HTTP header for DNS-safe subdomain redirect in browsers" \ - // "http://localhost:$GWAY_PORT/ipns/$IPNS_ED25519_B58MH" \ - // "Location: http://${IPNS_ED25519_B36CID}.ipns.localhost:$GWAY_PORT/" - // # public subdomain gateway: *.example.com - // test_hostname_gateway_response_should_contain \ - // "request for a ED25519 libp2p-key at example.com/ipns/{b58mh} returns Location HTTP header for DNS-safe subdomain redirect in browsers" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ED25519_B58MH" \ - // "Location: http://${IPNS_ED25519_B36CID}.ipns.example.com" { Name: "request for a ED25519 libp2p-key at example.com/ipns/{b58mh} returns Location HTTP header for DNS-safe subdomain redirect in browsers", Request: Request(). @@ -215,8 +158,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGatewayIPNS) } -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { tests := SugarTests{} @@ -226,7 +167,7 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { SubdomainLocalhostGatewayURL, } - dnsLinks := dnslink.MustOpenDNSLink("t0114/dnslink.yml") + dnsLinks := dnslink.MustOpenDNSLink("subdomain_gateway/dnslink.yml") wikipedia := dnsLinks.MustGet("wikipedia") dnsLinkTest := dnsLinks.MustGet("test") @@ -237,11 +178,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { } tests = append(tests, SugarTests{ - // # /ipns/ - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{fqdn} redirects to DNSLink in subdomain" \ - // "http://localhost:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en.wikipedia-on-ipfs.org.ipns.localhost:$GWAY_PORT/wiki" { Name: "request for /ipns/{fqdn} redirects to DNSLink in subdomain", Request: Request(). @@ -252,16 +188,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Equals("{{scheme}}://{{fqdn}}.ipns.{{host}}/wiki/", u.Scheme, dnslink.InlineDNS(wikipedia), u.Host), ), }, - // # .ipns.localhost - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // test_kill_ipfs_daemon - // DNSLINK_FQDN="dnslink-test.example.com" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1" - // test_launch_ipfs_daemon - // test_localhost_gateway_response_should_contain \ - // "request for {dnslink}.ipns.localhost returns expected payload" \ - // "http://$DNSLINK_FQDN.ipns.localhost:$GWAY_PORT" \ - // "$CID_VAL" { Name: "request for {dnslink}.ipns.{gateway} returns expected payload", Request: Request(). @@ -269,52 +195,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Response: Expect(). Body("hello\n"), }, - // ## ============================================================================ - // ## Test DNSLink inlining on HTTP gateways - // ## ============================================================================ - // # set explicit subdomain gateway config for the hostname - // ipfs config --json Gateway.PublicGateways '{ - // "localhost": { - // "UseSubdomains": true, - // "InlineDNSLink": true, - // "Paths": ["/ipfs", "/ipns", "/api"] - // }, - // "example.com": { - // "UseSubdomains": true, - // "InlineDNSLink": true, - // "Paths": ["/ipfs", "/ipns", "/api"] - // } - // }' || exit 1 - // # restart daemon to apply config changes - // test_kill_ipfs_daemon - // test_launch_ipfs_daemon_without_network - - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{fqdn} redirects to DNSLink in subdomain with DNS inlining" \ - // "http://localhost:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en-wikipedia--on--ipfs-org.ipns.localhost:$GWAY_PORT/wiki" - - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{fqdn} redirects to DNSLink in subdomain with DNS inlining" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en-wikipedia--on--ipfs-org.ipns.example.com/wiki" - - // # example.com/ipns/ - - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{fqdn} redirects to DNSLink in subdomain" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en.wikipedia-on-ipfs.org.ipns.example.com/wiki" - - // # DNSLink on Public gateway with a single-level wildcard TLS cert - // # "Option C" from https://github.com/ipfs/in-web-browsers/issues/169 - // test_expect_success \ - // "request for example.com/ipns/{fqdn} with X-Forwarded-Proto redirects to TLS-safe label in subdomain" " - // curl -H \"Host: example.com\" -H \"X-Forwarded-Proto: https\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki\" > response && - // test_should_contain \"Location: https://en-wikipedia--on--ipfs-org.ipns.example.com/wiki\" response - // " { Name: "request for example.com/ipns/{fqdn} with X-Forwarded-Proto redirects to TLS-safe label in subdomain", Hint: ` @@ -330,49 +210,17 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Equals("https://{{inlined}}.ipns.{{host}}/wiki/", dnslink.InlineDNS(wikipedia), u.Host), ), }, - // # Support ipns:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/?uri=ipns%3A%2F%2F.. produces redirect to /ipns/.. content path" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/?uri=ipns%3A%2F%2Fen.wikipedia-on-ipfs.org" \ - // "Location: /ipns/en.wikipedia-on-ipfs.org" { Name: `request for example.com/ipns/?uri=ipns%3A%2F%2F.. produces redirect to /ipns/.. content path`, Hint: "Support ipns:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler", Request: Request(). + // TODO: use Query or future QueryRaw here URL(`{{url}}/ipns/?uri=ipns%3A%2F%2F{{dnslink}}`, gatewayURL, wikipedia), Response: Expect(). Headers( Header("Location").Equals("/ipns/{{wikipedia}}", wikipedia), ), }, - // # DNSLink: .ipns.example.com - // # (not really useful outside of localhost, as setting TLS for more than one - // # level of wildcard is a pain, but we support it if someone really wants it) - // # ============================================================================ - - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // test_kill_ipfs_daemon - // DNSLINK_FQDN="dnslink-subdomain-gw-test.example.org" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1" - // test_launch_ipfs_daemon - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink}.ipns.example.com returns expected payload" \ - // "$DNSLINK_FQDN.ipns.example.com" \ - // "http://127.0.0.1:$GWAY_PORT" \ - // "$CID_VAL" - // Note: this test was merged with the test for wikipedia in the end. - - // # DNSLink on Public gateway with a single-level wildcard TLS cert - // # "Option C" from https://github.com/ipfs/in-web-browsers/issues/169 - // test_expect_success \ - // "request for {single-label-dnslink}.ipns.example.com with X-Forwarded-Proto returns expected payload" " - // curl -H \"Host: dnslink--subdomain--gw--test-example-org.ipns.example.com\" -H \"X-Forwarded-Proto: https\" -sD - \"http://127.0.0.1:$GWAY_PORT\" > response && - // test_should_contain \"$CID_VAL\" response - // " - // Note: this test was merged with the test for wikipedia in the end. - }...) } diff --git a/tests/trustless_gateway_ipns_test.go b/tests/trustless_gateway_ipns_test.go index c53a15943..e99449fbf 100644 --- a/tests/trustless_gateway_ipns_test.go +++ b/tests/trustless_gateway_ipns_test.go @@ -10,11 +10,11 @@ import ( ) func TestGatewayIPNSRecord(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0124/fixtures.car") + fixture := car.MustOpenUnixfsCar("ipns_records/fixtures.car") file := fixture.MustGetRoot() fileCID := file.Cid() - ipns := MustOpenIPNSRecordWithKey("t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record") + ipns := MustOpenIPNSRecordWithKey("ipns_records/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record") ipnsName := ipns.Key() tests := SugarTests{ diff --git a/tests/trustless_gateway_raw_test.go b/tests/trustless_gateway_raw_test.go index afa492b94..8f5962885 100644 --- a/tests/trustless_gateway_raw_test.go +++ b/tests/trustless_gateway_raw_test.go @@ -11,7 +11,7 @@ import ( ) func TestTrustlessRaw(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0117-gateway-block.car") + fixture := car.MustOpenUnixfsCar("gateway-raw-block.car") tests := SugarTests{ { diff --git a/tooling/ipns/_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record b/tooling/ipns/_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record new file mode 100644 index 000000000..ec13ec550 Binary files /dev/null and b/tooling/ipns/_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record differ diff --git a/tooling/ipns/ipns_test.go b/tooling/ipns/ipns_test.go index f84265d8b..53bdb80bd 100644 --- a/tooling/ipns/ipns_test.go +++ b/tooling/ipns/ipns_test.go @@ -36,7 +36,7 @@ func TestExtractPath(t *testing.T) { } func TestLoadIPNSRecord(t *testing.T) { - path := "../../fixtures/t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record" + path := "./_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record" ipns, err := OpenIPNSRecordWithKey(path) assert.Nil(t, err)