From 8fd60be4175b8705c10397d7b32d94f99bda5c8e Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 26 Jun 2023 14:28:31 +0200 Subject: [PATCH 01/19] test(t0112): drop test ported to conformance --- test/sharness/t0112-gateway-cors.sh | 39 +---------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/test/sharness/t0112-gateway-cors.sh b/test/sharness/t0112-gateway-cors.sh index e4fb571221a..528e469806c 100755 --- a/test/sharness/t0112-gateway-cors.sh +++ b/test/sharness/t0112-gateway-cors.sh @@ -15,11 +15,9 @@ EOF test_cmp expected actual ' -test_launch_ipfs_daemon - thash='bafkqabtimvwgy3yk' # hello -# Gateway +test_launch_ipfs_daemon # HTTP GET Request test_expect_success "GET to Gateway succeeds" ' @@ -27,47 +25,12 @@ test_expect_success "GET to Gateway succeeds" ' cat curl_output ' -# GET Response from Gateway should contain CORS headers -test_expect_success "GET response for Gateway resource looks good" ' - test_should_contain "< Access-Control-Allow-Origin: \*" curl_output && - test_should_contain "< Access-Control-Allow-Methods: GET" curl_output && - test_should_contain "< Access-Control-Allow-Methods: HEAD" curl_output && - test_should_contain "< Access-Control-Allow-Methods: OPTIONS" curl_output && - test_should_contain "< Access-Control-Allow-Headers: Content-Type" curl_output && - test_should_contain "< Access-Control-Allow-Headers: Range" curl_output && - test_should_contain "< Access-Control-Allow-Headers: User-Agent" curl_output && - test_should_contain "< Access-Control-Allow-Headers: X-Requested-With" curl_output && - test_should_contain "< Access-Control-Expose-Headers: Content-Range" curl_output && - test_should_contain "< Access-Control-Expose-Headers: Content-Length" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Chunked-Output" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Stream-Output" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Path" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Roots" curl_output -' # HTTP OPTIONS Request test_expect_success "OPTIONS to Gateway succeeds" ' curl -svX OPTIONS -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" 2>curl_output && cat curl_output ' -# OPTION Response from Gateway should contain CORS headers -test_expect_success "OPTIONS response for Gateway resource looks good" ' - test_should_contain "< Access-Control-Allow-Origin: \*" curl_output && - test_should_contain "< Access-Control-Allow-Methods: GET" curl_output && - test_should_contain "< Access-Control-Allow-Methods: HEAD" curl_output && - test_should_contain "< Access-Control-Allow-Methods: OPTIONS" curl_output && - test_should_contain "< Access-Control-Allow-Headers: Content-Type" curl_output && - test_should_contain "< Access-Control-Allow-Headers: Range" curl_output && - test_should_contain "< Access-Control-Allow-Headers: User-Agent" curl_output && - test_should_contain "< Access-Control-Allow-Headers: X-Requested-With" curl_output && - test_should_contain "< Access-Control-Expose-Headers: Content-Range" curl_output && - test_should_contain "< Access-Control-Expose-Headers: Content-Length" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Chunked-Output" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Stream-Output" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Path" curl_output && - test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Roots" curl_output -' - # HTTP OPTIONS Request on path → subdomain HTTP 301 redirect # (regression test for https://github.com/ipfs/kubo/issues/9983#issuecomment-1599673976) test_expect_success "OPTIONS to Gateway succeeds" ' From 6b9a4f657ecc5aa82f3c0e020f596a8a805daf60 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 26 Jun 2023 14:24:49 +0200 Subject: [PATCH 02/19] test(t0113): drop test ported to conformance --- test/sharness/t0113-gateway-symlink.sh | 33 ------------------ test/sharness/t0113-gateway-symlink/README.md | 17 --------- .../t0113-gateway-symlink/testfiles.car | Bin 282 -> 0 bytes 3 files changed, 50 deletions(-) delete mode 100755 test/sharness/t0113-gateway-symlink.sh delete mode 100644 test/sharness/t0113-gateway-symlink/README.md delete mode 100644 test/sharness/t0113-gateway-symlink/testfiles.car diff --git a/test/sharness/t0113-gateway-symlink.sh b/test/sharness/t0113-gateway-symlink.sh deleted file mode 100755 index 2cb4f319537..00000000000 --- a/test/sharness/t0113-gateway-symlink.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) Protocol Labs - -test_description="Test symlink support on the HTTP gateway" - -. lib/test-lib.sh - -test_init_ipfs -test_launch_ipfs_daemon - -# Import test case -# See the static fixtures in ./t0113-gateway-symlink/ -test_expect_success "Add the test directory with symlinks" ' - ipfs dag import --pin-roots ../t0113-gateway-symlink/testfiles.car -' -ROOT_DIR_CID=QmWvY6FaqFMS89YAQ9NAPjVP4WZKA1qbHbicc9HeSKQTgt # ./testfiles/ - -test_expect_success "Test the directory listing" ' - curl "$GWAY_ADDR/ipfs/$ROOT_DIR_CID/" > list_response && - test_should_contain ">foo<" list_response && - test_should_contain ">bar<" list_response -' - -test_expect_success "Test the symlink" ' - curl "$GWAY_ADDR/ipfs/$ROOT_DIR_CID/bar" > bar_actual && - echo -n "foo" > bar_expected && - test_cmp bar_expected bar_actual -' - -test_kill_ipfs_daemon - -test_done diff --git a/test/sharness/t0113-gateway-symlink/README.md b/test/sharness/t0113-gateway-symlink/README.md deleted file mode 100644 index 31a257bdded..00000000000 --- a/test/sharness/t0113-gateway-symlink/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Dataset description/sources - -- testfiles.car - - raw CARv1 - -generated with: - -```sh -# using ipfs version 0.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 > testfiles.car - -# ROOT_DIR_CID=QmWvY6FaqFMS89YAQ9NAPjVP4WZKA1qbHbicc9HeSKQTgt -``` diff --git a/test/sharness/t0113-gateway-symlink/testfiles.car b/test/sharness/t0113-gateway-symlink/testfiles.car deleted file mode 100644 index 88e5825f3029ceb158138812c946825544704d26..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 282 zcmcCmlvG!RGgWg$JoF~Sh0{cmy(cz`^^ncIdY^b8_T#q9k%X>mgtKR@Vd1l;Qez>Zf=ID z2|~NuBOwJsCUfy|FbQ!a=jWBA=9O?sZ~y=yG;7fS From c1664c1d84c23845ff37dc1d8ab43653cfbbe074 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 12:56:58 +0200 Subject: [PATCH 03/19] test(t0114): drop test ported to conformance --- test/sharness/t0114-gateway-subdomains.sh | 350 ---------------------- 1 file changed, 350 deletions(-) diff --git a/test/sharness/t0114-gateway-subdomains.sh b/test/sharness/t0114-gateway-subdomains.sh index 8be102c4f41..c3747af0fc5 100755 --- a/test/sharness/t0114-gateway-subdomains.sh +++ b/test/sharness/t0114-gateway-subdomains.sh @@ -142,57 +142,6 @@ test_localhost_gateway_response_should_contain \ # 'localhost' hostname is used for subdomains, and should not return # payload directly, but redirect to URL with proper origin isolation -test_localhost_gateway_response_should_contain \ - "request for localhost/ipfs/{CIDv1} returns HTTP 301 Moved Permanently" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv1" \ - "301 Moved Permanently" - -test_localhost_gateway_response_should_contain \ - "request for localhost/ipfs/{CIDv1} returns Location HTTP header for subdomain redirect in browsers" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv1" \ - "Location: http://$CIDv1.ipfs.localhost:$GWAY_PORT/" - -test_localhost_gateway_response_should_contain \ - "request for localhost/ipfs/{DIR_CID} returns HTTP 301 Moved Permanently" \ - "http://localhost:$GWAY_PORT/ipfs/$DIR_CID" \ - "301 Moved Permanently" - -test_localhost_gateway_response_should_contain \ - "request for localhost/ipfs/{DIR_CID} returns Location HTTP header for subdomain redirect in browsers" \ - "http://localhost:$GWAY_PORT/ipfs/$DIR_CID/" \ - "Location: http://$DIR_CID.ipfs.localhost:$GWAY_PORT/" - -# We return human-readable body with HTTP 301 so existing cli scripts that use path-based -# gateway are informed to enable following HTTP redirects -test_localhost_gateway_response_should_contain \ - "request for localhost/ipfs/{CIDv1} includes human-readable link and redirect info in HTTP 301 body" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv1" \ - ">Moved Permanently" - -test_localhost_gateway_response_should_contain \ - "request for localhost/ipfs/{CIDv0} redirects to CIDv1 representation in subdomain" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv0" \ - "Location: http://${CIDv0to1}.ipfs.localhost:$GWAY_PORT/" - -# /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/" - -# /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" - # API on localhost subdomain gateway # /api/v0 present on the root hostname @@ -219,81 +168,11 @@ test_localhost_gateway_response_should_contain \ # {CID}.ipfs.localhost -test_localhost_gateway_response_should_contain \ - "request for {CID}.ipfs.localhost should return expected payload" \ - "http://${CIDv1}.ipfs.localhost:$GWAY_PORT" \ - "$CID_VAL" - -# ensure /ipfs/ namespace is not mounted on subdomain -test_localhost_gateway_response_should_contain \ - "request for {CID}.ipfs.localhost/ipfs/{CID} should return HTTP 404" \ - "http://${CIDv1}.ipfs.localhost:$GWAY_PORT/ipfs/$CIDv1" \ - "404 Not Found" - -# ensure requests to /ipfs/* are not blocked, if content root has such subdirectory -test_localhost_gateway_response_should_contain \ - "request for {CID}.ipfs.localhost/ipfs/file.txt should return data from a file in CID content root" \ - "http://${DIR_CID}.ipfs.localhost:$GWAY_PORT/ipfs/file.txt" \ - "I am a txt file" - # {CID}.ipfs.localhost/sub/dir (Directory Listing) DIR_HOSTNAME="${DIR_CID}.ipfs.localhost:$GWAY_PORT" -test_expect_success "valid file and subdirectory paths in directory listing at {cid}.ipfs.localhost" ' - curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME" > list_response && - test_should_contain "hello" list_response && - test_should_contain "ipfs" list_response -' - -test_expect_success "valid parent directory path in directory listing at {cid}.ipfs.localhost/sub/dir" ' - curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/ipfs/ipns/" > list_response && - test_should_contain ".." list_response && - test_should_contain "bar" list_response -' - -test_expect_success "request for deep path resource at {cid}.ipfs.localhost/sub/dir/file" ' - curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/ipfs/ipns/bar" > list_response && - test_should_contain "text-file-content" list_response -' - - -# *.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" - -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/" - # .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" - # api.localhost/api # Note: we use DIR_CID so refs -r returns some CIDs for child nodes @@ -323,17 +202,6 @@ ipfs config --json Gateway.PublicGateways '{ 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" - ## ============================================================================ ## Test subdomain-based requests with a custom hostname config ## (origin per content root at http://*.example.com) @@ -354,121 +222,11 @@ test_launch_ipfs_daemon_without_network # example.com/ip(f|n)s/* # ============================================================================= -# path requests to the root hostname should redirect -# to a subdomain URL with proper origin isolation - -test_hostname_gateway_response_should_contain \ - "request for example.com/ipfs/{CIDv1} produces redirect to {CIDv1}.ipfs.example.com" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ - "Location: http://$CIDv1.ipfs.example.com/" - -# error message should include original CID -# (and it should be case-sensitive, as we can't assume everyone uses base32) -test_hostname_gateway_response_should_contain \ - "request for example.com/ipfs/{InvalidCID} produces useful error before redirect" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/QmInvalidCID" \ - 'invalid path \"/ipfs/QmInvalidCID\"' - -test_hostname_gateway_response_should_contain \ - "request for example.com/ipfs/{CIDv0} produces redirect to {CIDv1}.ipfs.example.com" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv0" \ - "Location: http://${CIDv0to1}.ipfs.example.com/" - -# Support X-Forwarded-Proto -test_expect_success "request for http://example.com/ipfs/{CID} with X-Forwarded-Proto: https produces redirect to HTTPS URL" " - curl -H \"X-Forwarded-Proto: https\" -H \"Host: example.com\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && - test_should_contain \"Location: https://$CIDv1.ipfs.example.com/\" response -" - -# Support ipfs:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler -test_hostname_gateway_response_should_contain \ - "request for example.com/ipfs/?uri=ipfs%3A%2F%2F.. produces redirect to /ipfs/.. content path" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/?uri=ipfs%3A%2F%2FQmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco%2Fwiki%2FDiego_Maradona.html" \ - "Location: /ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Diego_Maradona.html" - -# 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/" - -# 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 - " - -# 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" - # *.ipfs.example.com: subdomain requests made with custom FQDN in Host header -test_hostname_gateway_response_should_contain \ - "request for {CID}.ipfs.example.com should return expected payload" \ - "${CIDv1}.ipfs.example.com" \ - "http://127.0.0.1:$GWAY_PORT/" \ - "$CID_VAL" - -test_hostname_gateway_response_should_contain \ - "request for {CID}.ipfs.example.com/ipfs/{CID} should return HTTP 404" \ - "${CIDv1}.ipfs.example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ - "404 Not Found" - # {CID}.ipfs.example.com/sub/dir (Directory Listing) DIR_FQDN="${DIR_CID}.ipfs.example.com" -test_expect_success "valid file and directory paths in directory listing at {cid}.ipfs.example.com" ' - curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT > list_response && - test_should_contain "hello" list_response && - test_should_contain "ipfs" list_response -' - -test_expect_success "valid parent directory path in directory listing at {cid}.ipfs.example.com/sub/dir" ' - curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/ > list_response && - test_should_contain ".." list_response && - test_should_contain "bar" list_response -' - -# Note 1: we test for sneaky subdir names {cid}.ipfs.example.com/ipfs/ipns/ :^) -# Note 2: example.com/ipfs/.. present in HTML will be redirected to subdomain, so this is expected behavior -test_expect_success "valid breadcrumb links in the header of directory listing at {cid}.ipfs.example.com/sub/dir" ' - curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/ > list_response && - test_should_contain "Index of" list_response && - test_should_contain "/ipfs/${DIR_CID}/ipfs/ipns" list_response -' - -test_expect_success "request for deep path resource {cid}.ipfs.example.com/sub/dir/file" ' - curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/bar > list_response && - test_should_contain "text-file-content" list_response -' - # *.ipns.example.com # ============================================================================ @@ -546,84 +304,6 @@ test_hostname_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/api/file.txt" \ "I am a txt file" -# 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" - -# 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 - " - -## 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/" - -# router should not redirect to hostnames that could fail due to DNS limits -test_localhost_gateway_response_should_contain \ - "request for a too long CID at localhost/ipfs/{CIDv1} returns human readable error" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "CID incompatible with DNS label length limit of 63" - -test_localhost_gateway_response_should_contain \ - "request for a too long CID at localhost/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "400 Bad Request" - -# direct request should also fail (provides the same UX as router and avoids confusion) -test_localhost_gateway_response_should_contain \ - "request for a too long CID at {CIDv1}.ipfs.localhost returns expected payload" \ - "http://$CIDv1_TOO_LONG.ipfs.localhost:$GWAY_PORT" \ - "400 Bad Request" - -# 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" - -test_hostname_gateway_response_should_contain \ - "request for a too long CID at example.com/ipfs/{CIDv1} returns human readable error" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "CID incompatible with DNS label length limit of 63" - -test_hostname_gateway_response_should_contain \ - "request for a too long CID at example.com/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "400 Bad Request" - -test_hostname_gateway_response_should_contain \ - "request for a too long CID at {CIDv1}.ipfs.example.com returns HTTP Error 400 Bad Request" \ - "$CIDv1_TOO_LONG.ipfs.example.com" \ - "http://127.0.0.1:$GWAY_PORT/" \ - "400 Bad Request" - # Disable selected Paths for the subdomain gateway hostname # ============================================================================= @@ -825,36 +505,6 @@ test_hostname_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/" \ "$CID_VAL" -## ============================================================================ -## Test support for X-Forwarded-Host -## ============================================================================ - -# set explicit subdomain gateway config for the hostname -ipfs config --json Gateway.PublicGateways '{ - "example.com": { - "UseSubdomains": true, - "Paths": ["/ipfs", "/ipns", "/api"] - } -}' || exit 1 -# restart daemon to apply config changes -test_kill_ipfs_daemon -test_launch_ipfs_daemon_without_network - -test_expect_success "request for http://fake.domain.com/ipfs/{CID} doesn't match the example.com gateway" " - curl -H \"Host: fake.domain.com\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && - test_should_contain \"200 OK\" response -" - -test_expect_success "request for http://fake.domain.com/ipfs/{CID} with X-Forwarded-Host: example.com match the example.com gateway" " - curl -H \"Host: fake.domain.com\" -H \"X-Forwarded-Host: example.com\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && - test_should_contain \"Location: http://$CIDv1.ipfs.example.com/\" response -" - -test_expect_success "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" " - curl -H \"Host: fake.domain.com\" -H \"X-Forwarded-Host: example.com\" -H \"X-Forwarded-Proto: https\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && - test_should_contain \"Location: https://$CIDv1.ipfs.example.com/\" response -" - ## ============================================================================ ## Test support for wildcards in gateway config ## ============================================================================ From 63a04e276fbaa7a745c532f4b67e0c7d0220aef7 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 17:09:48 +0200 Subject: [PATCH 04/19] test(t0114): drop test ported to conformance --- test/sharness/t0114-gateway-subdomains.sh | 127 +++++++++++++++------- 1 file changed, 89 insertions(+), 38 deletions(-) diff --git a/test/sharness/t0114-gateway-subdomains.sh b/test/sharness/t0114-gateway-subdomains.sh index c3747af0fc5..7655f8a8764 100755 --- a/test/sharness/t0114-gateway-subdomains.sh +++ b/test/sharness/t0114-gateway-subdomains.sh @@ -139,9 +139,6 @@ test_localhost_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ "$CID_VAL" -# 'localhost' hostname is used for subdomains, and should not return -# payload directly, but redirect to URL with proper origin isolation - # API on localhost subdomain gateway # /api/v0 present on the root hostname @@ -166,13 +163,14 @@ test_localhost_gateway_response_should_contain \ ## (origin per content root at http://*.localhost) ## ============================================================================ -# {CID}.ipfs.localhost - -# {CID}.ipfs.localhost/sub/dir (Directory Listing) -DIR_HOSTNAME="${DIR_CID}.ipfs.localhost:$GWAY_PORT" - # .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 + # api.localhost/api # Note: we use DIR_CID so refs -r returns some CIDs for child nodes @@ -222,40 +220,12 @@ test_launch_ipfs_daemon_without_network # example.com/ip(f|n)s/* # ============================================================================= -# *.ipfs.example.com: subdomain requests made with custom FQDN in Host header - -# {CID}.ipfs.example.com/sub/dir (Directory Listing) -DIR_FQDN="${DIR_CID}.ipfs.example.com" +# path requests to the root hostname should redirect +# to a subdomain URL with proper origin isolation # *.ipns.example.com # ============================================================================ -# .ipns.example.com - -test_hostname_gateway_response_should_contain \ - "request for {CIDv1-libp2p-key}.ipns.example.com returns expected payload" \ - "${RSA_IPNS_IDv1}.ipns.example.com" \ - "http://127.0.0.1:$GWAY_PORT" \ - "$CID_VAL" - -test_hostname_gateway_response_should_contain \ - "request for {CIDv1-libp2p-key}.ipns.example.com returns expected payload" \ - "${ED25519_IPNS_IDv1}.ipns.example.com" \ - "http://127.0.0.1:$GWAY_PORT" \ - "$CID_VAL" - -test_hostname_gateway_response_should_contain \ - "hostname request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ - "${RSA_IPNS_IDv1_DAGPB}.ipns.example.com" \ - "http://127.0.0.1:$GWAY_PORT" \ - "Location: http://${RSA_IPNS_IDv1}.ipns.example.com/" - -test_hostname_gateway_response_should_contain \ - "hostname request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ - "${ED25519_IPNS_IDv1_DAGPB}.ipns.example.com" \ - "http://127.0.0.1:$GWAY_PORT" \ - "Location: http://${ED25519_IPNS_IDv1}.ipns.example.com/" - # API on subdomain gateway example.com # ============================================================================ @@ -304,6 +274,87 @@ test_hostname_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/api/file.txt" \ "I am a txt file" +# 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 + +# TODO: dns inlining? +# this lives in subdomain_gateway_ipns_test.go for now + +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" + +# 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 + " + +## 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/" + +# router should not redirect to hostnames that could fail due to DNS limits +test_localhost_gateway_response_should_contain \ + "request for a too long CID at localhost/ipfs/{CIDv1} returns human readable error" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "CID incompatible with DNS label length limit of 63" + +test_localhost_gateway_response_should_contain \ + "request for a too long CID at localhost/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "400 Bad Request" + +# direct request should also fail (provides the same UX as router and avoids confusion) +test_localhost_gateway_response_should_contain \ + "request for a too long CID at {CIDv1}.ipfs.localhost returns expected payload" \ + "http://$CIDv1_TOO_LONG.ipfs.localhost:$GWAY_PORT" \ + "400 Bad Request" + +# 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" + +test_hostname_gateway_response_should_contain \ + "request for a too long CID at example.com/ipfs/{CIDv1} returns human readable error" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "CID incompatible with DNS label length limit of 63" + +test_hostname_gateway_response_should_contain \ + "request for a too long CID at example.com/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "400 Bad Request" + +test_hostname_gateway_response_should_contain \ + "request for a too long CID at {CIDv1}.ipfs.example.com returns HTTP Error 400 Bad Request" \ + "$CIDv1_TOO_LONG.ipfs.example.com" \ + "http://127.0.0.1:$GWAY_PORT/" \ + "400 Bad Request" + # Disable selected Paths for the subdomain gateway hostname # ============================================================================= From 1c69b94637211963588a497e0cbb0c58ad03b3f6 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 17:36:07 +0200 Subject: [PATCH 05/19] test(t0115): drop test ported to conformance --- test/sharness/t0115-gateway-dir-listing.sh | 168 ------------------ .../t0115-gateway-dir-listing/README.md | 32 ---- .../t0115-gateway-dir-listing/fixtures.car | Bin 1053 -> 0 bytes 3 files changed, 200 deletions(-) delete mode 100755 test/sharness/t0115-gateway-dir-listing.sh delete mode 100644 test/sharness/t0115-gateway-dir-listing/README.md delete mode 100644 test/sharness/t0115-gateway-dir-listing/fixtures.car diff --git a/test/sharness/t0115-gateway-dir-listing.sh b/test/sharness/t0115-gateway-dir-listing.sh deleted file mode 100755 index 1ce0861b2eb..00000000000 --- a/test/sharness/t0115-gateway-dir-listing.sh +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) Protocol Labs - -test_description="Test directory listing (dir-index-html) on the HTTP gateway" - - -. lib/test-lib.sh - -## ============================================================================ -## Start IPFS Node and prepare test CIDs -## ============================================================================ - -test_expect_success "ipfs init" ' - export IPFS_PATH="$(pwd)/.ipfs" && - ipfs init --profile=test > /dev/null -' - -test_launch_ipfs_daemon_without_network - -# Import test case -# See the static fixtures in ./t0115-gateway-dir-listing/ -test_expect_success "Add the test directory" ' - ipfs dag import --pin-roots ../t0115-gateway-dir-listing/fixtures.car -' -DIR_CID=bafybeig6ka5mlwkl4subqhaiatalkcleo4jgnr3hqwvpmsqfca27cijp3i # ./rootDir/ -FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt -FILE_SIZE=34 - -## ============================================================================ -## 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 -' - -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 -' - -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 -' - -## ============================================================================ -## Test dir listing on subdomain gateway (eg. .ipfs.localhost:8080) -## ============================================================================ - -DIR_HOSTNAME="${DIR_CID}.ipfs.localhost" -# note: we skip DNS lookup by running curl with --resolve $DIR_HOSTNAME:127.0.0.1 - -test_expect_success "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 -' - -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 -' - -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 -' - -## ============================================================================ -## Test dir listing on DNSLink gateway (eg. example.com) -## ============================================================================ - -# DNSLink test requires a daemon in online mode with precached /ipns/ mapping -test_kill_ipfs_daemon -DNSLINK_HOSTNAME="website.example.com" -export IPFS_NS_MAP="$DNSLINK_HOSTNAME:/ipfs/$DIR_CID" -test_launch_ipfs_daemon - -# Note that: -# - this type of gateway is also tested in gateway_test.go#TestIPNSHostnameBacklinks -# (go tests and sharness tests should be kept in sync) -# - we skip DNS lookup by running curl with --resolve $DNSLINK_HOSTNAME:127.0.0.1 - -test_expect_success "dnslink gw: backlink on root CID should 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 -' - -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 -' - -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 -' - -## ============================================================================ -## End of tests, cleanup -## ============================================================================ - -test_kill_ipfs_daemon -test_expect_success "clean up ipfs dir" ' - rm -rf "$IPFS_PATH" -' -test_done diff --git a/test/sharness/t0115-gateway-dir-listing/README.md b/test/sharness/t0115-gateway-dir-listing/README.md deleted file mode 100644 index 937438bcd65..00000000000 --- a/test/sharness/t0115-gateway-dir-listing/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Dataset description/sources - -- fixtures.car - - raw CARv1 - -generated with: - -```sh -# using ipfs version 0.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} -echo FILE_CID=${FILE_CID} -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/test/sharness/t0115-gateway-dir-listing/fixtures.car b/test/sharness/t0115-gateway-dir-listing/fixtures.car deleted file mode 100644 index 71a5603822741f25320438bd70823589120e313c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1053 zcmcColvR$Z!{1TqeSN@tUjjg{Tlgc7mrAdS5w!gPn*17KH6I(#F3Vnld4xzQ6ixRGTe(8O`Zyg zxeAF2KuroD-3pm`3d#9-X{E)PdFcxJz;IJY$t>amyOUtJLEZWM>i;({85gv-W(d_V zKa@*2eN@-d)vWbj%$Z-NzS6vINbXbzxziiuPC}aSyAu>)2!|4kFsMU?&s>>u#q@K) zg=4JD+Ddu%u4<)wm#M_8IM$cG*3(nQFic@T$&fnuIuO3{I&*k2EHJEuD( zXEu8GPP(?~NTtQ!*2R(r|4!eUF1UKJ@frzWikc}A4+_gfkg)`nn?n*5x8rrT>037M zkdg1bF*9{rSzCT(#hs2>E#m S1&JjY3gwwVqO>H Date: Tue, 27 Jun 2023 17:45:21 +0200 Subject: [PATCH 06/19] test(t0122): drop test ported to conformance --- test/sharness/t0122-gateway-tar.sh | 85 ------------------ test/sharness/t0122-gateway-tar/README.md | 37 -------- test/sharness/t0122-gateway-tar/fixtures.car | Bin 1053 -> 0 bytes .../t0122-gateway-tar/inside-root.car | Bin 383 -> 0 bytes .../t0122-gateway-tar/outside-root.car | Bin 249 -> 0 bytes 5 files changed, 122 deletions(-) delete mode 100755 test/sharness/t0122-gateway-tar.sh delete mode 100644 test/sharness/t0122-gateway-tar/README.md delete mode 100644 test/sharness/t0122-gateway-tar/fixtures.car delete mode 100644 test/sharness/t0122-gateway-tar/inside-root.car delete mode 100644 test/sharness/t0122-gateway-tar/outside-root.car diff --git a/test/sharness/t0122-gateway-tar.sh b/test/sharness/t0122-gateway-tar.sh deleted file mode 100755 index 435623547a3..00000000000 --- a/test/sharness/t0122-gateway-tar.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env bash - -test_description="Test HTTP Gateway TAR (application/x-tar) Support" - -. lib/test-lib.sh - -test_init_ipfs -test_launch_ipfs_daemon_without_network - -OUTSIDE_ROOT_CID="bafybeicaj7kvxpcv4neaqzwhrqqmdstu4dhrwfpknrgebq6nzcecfucvyu" -INSIDE_ROOT_CID="bafybeibfevfxlvxp5vxobr5oapczpf7resxnleb7tkqmdorc4gl5cdva3y" - -# Import test case -# See the static fixtures in ./t0122-gateway-tar/ -test_expect_success "Add the test directory" ' - ipfs dag import --pin-roots ../t0122-gateway-tar/fixtures.car -' -DIR_CID=bafybeig6ka5mlwkl4subqhaiatalkcleo4jgnr3hqwvpmsqfca27cijp3i # ./rootDir -FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt -FILE_SIZE=34 - -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 '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 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 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 -' - -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 -' - -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 -' - -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 -" - -test_expect_success "Add CARs with relative paths to test with" ' - ipfs dag import --pin-roots ../t0122-gateway-tar/outside-root.car > import_output && - test_should_contain $OUTSIDE_ROOT_CID import_output && - ipfs dag import --pin-roots ../t0122-gateway-tar/inside-root.car > import_output && - test_should_contain $INSIDE_ROOT_CID import_output -' - -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 -' - -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 -' - -test_kill_ipfs_daemon - -test_done diff --git a/test/sharness/t0122-gateway-tar/README.md b/test/sharness/t0122-gateway-tar/README.md deleted file mode 100644 index 8b9311277cc..00000000000 --- a/test/sharness/t0122-gateway-tar/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# Dataset description/sources - -- inside-root.car - -- outside-root.car - -- fixtures.car - - raw CARv1 - -generated with: - -```sh -# ipfs version 0.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/test/sharness/t0122-gateway-tar/fixtures.car b/test/sharness/t0122-gateway-tar/fixtures.car deleted file mode 100644 index 71a5603822741f25320438bd70823589120e313c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1053 zcmcColvR$Z!{1TqeSN@tUjjg{Tlgc7mrAdS5w!gPn*17KH6I(#F3Vnld4xzQ6ixRGTe(8O`Zyg zxeAF2KuroD-3pm`3d#9-X{E)PdFcxJz;IJY$t>amyOUtJLEZWM>i;({85gv-W(d_V zKa@*2eN@-d)vWbj%$Z-NzS6vINbXbzxziiuPC}aSyAu>)2!|4kFsMU?&s>>u#q@K) zg=4JD+Ddu%u4<)wm#M_8IM$cG*3(nQFic@T$&fnuIuO3{I&*k2EHJEuD( zXEu8GPP(?~NTtQ!*2R(r|4!eUF1UKJ@frzWikc}A4+_gfkg)`nn?n*5x8rrT>037M zkdg1bF*9{rSzCT(#hs2>E#m S1&JjY3gwwVqO>Hee^xFHkc@K`SV?H{4`bU*@S0~udT5xce(!=Q& z`4-$uFH0>d&dkqaj37p}kRF!`NF7V9N~fsTRp-u?;^j5_^n32ysn~q^+RC22)y!qz zgARrYv8CnbCnXkfF>x?P6Q#irV(`1uv2n9Mx30H1R<)FoX-6hgLt#_gqO@SXiDDIH zM?cOJ;!MdbN=+`wFRFx_O;8WW>`)|0=|$r>CEmpD)2Dq)Vg@=A^_T2|g|+4n`wlZ170U$;sDID9 Date: Wed, 28 Jun 2023 09:41:03 +0200 Subject: [PATCH 07/19] test(t0123): drop test ported to conformance --- test/sharness/t0123-gateway-json-cbor.sh | 379 ------------------ .../t0123-gateway-json-cbor/README.md | 66 --- .../dag-cbor-traversal.car | Bin 318 -> 0 bytes .../dag-json-traversal.car | Bin 406 -> 0 bytes .../t0123-gateway-json-cbor/dag-pb.car | Bin 392 -> 0 bytes .../t0123-gateway-json-cbor/dag-pb.json | 23 -- .../t0123-gateway-json-cbor/fixtures.car | Bin 1179 -> 0 bytes ...xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record | Bin 394 -> 0 bytes ...e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record | Bin 398 -> 0 bytes 9 files changed, 468 deletions(-) delete mode 100755 test/sharness/t0123-gateway-json-cbor.sh delete mode 100644 test/sharness/t0123-gateway-json-cbor/README.md delete mode 100644 test/sharness/t0123-gateway-json-cbor/dag-cbor-traversal.car delete mode 100644 test/sharness/t0123-gateway-json-cbor/dag-json-traversal.car delete mode 100644 test/sharness/t0123-gateway-json-cbor/dag-pb.car delete mode 100644 test/sharness/t0123-gateway-json-cbor/dag-pb.json delete mode 100644 test/sharness/t0123-gateway-json-cbor/fixtures.car delete mode 100644 test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record delete mode 100644 test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record diff --git a/test/sharness/t0123-gateway-json-cbor.sh b/test/sharness/t0123-gateway-json-cbor.sh deleted file mode 100755 index 323d23d584f..00000000000 --- a/test/sharness/t0123-gateway-json-cbor.sh +++ /dev/null @@ -1,379 +0,0 @@ -#!/usr/bin/env bash - -test_description="Test HTTP Gateway DAG-JSON (application/vnd.ipld.dag-json) and DAG-CBOR (application/vnd.ipld.dag-cbor) Support" - -. lib/test-lib.sh - -test_init_ipfs -test_launch_ipfs_daemon_without_network - -# Import test case -# See the static fixtures in ./t0123-gateway-json-cbor/ -test_expect_success "Add the test directory" ' - ipfs dag import --pin-roots ../t0123-gateway-json-cbor/fixtures.car -' -DIR_CID=bafybeiafyvqlazbbbtjnn6how5d6h6l6rxbqc4qgpbmteaiskjrffmyy4a # ./rootDir -FILE_JSON_CID=bafkreibrppizs3g7axs2jdlnjua6vgpmltv7k72l7v7sa6mmht6mne3qqe # ./rootDir/ą/ę/t.json -FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt -FILE_SIZE=34 - -## Quick regression check for JSON stored on UnixFS: -## it has nothing to do with DAG-JSON and JSON codecs, -## but a lot of JSON data is stored on UnixFS and is requested with or without various hints -## and we want to avoid surprises like https://github.com/protocol/bifrost-infra/issues/2290 -test_expect_success "GET UnixFS file with JSON bytes is returned with application/json Content-Type" ' - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_JSON_CID" > curl_output 2>&1 && - curl -sD headers_accept -H "Accept: application/json" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_JSON_CID" > curl_output_accept 2>&1 && - ipfs cat $FILE_JSON_CID > ipfs_cat_output 2>&1 && - test_should_contain "Content-Type: application/json" headers && - test_should_contain "Content-Type: application/json" headers_accept && - test_cmp ipfs_cat_output curl_output && - test_cmp curl_output curl_output_accept -' - - -## 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) - -test_dag_pb_conversion () { - name=$1 - format=$2 - disposition=$3 - - 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 - ' - - 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 - ' - - 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 - ' - - 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 - ' - - 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 - ' - - 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 - ' -} - -test_dag_pb_conversion "DAG-JSON" "json" "inline" -test_dag_pb_conversion "DAG-CBOR" "cbor" "attachment" - - -# Requesting CID with plain json (0x0200) and cbor (0x51) codecs -# (note these are not UnixFS, not DAG-* variants, just raw block identified by a CID with a special codec) -test_plain_codec () { - name=$1 - format=$2 - disposition=$3 - - # 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 - ' - - # 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 - ' - - # 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 - ' - - # 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 - ' - -} - -test_plain_codec "plain JSON codec" "json" "inline" -test_plain_codec "plain CBOR codec" "cbor" "attachment" - -## Pathing, traversal over DAG-JSON and DAG-CBOR - -DAG_CBOR_TRAVERSAL_CID="bafyreibs4utpgbn7uqegmd2goqz4bkyflre2ek2iwv743fhvylwi4zeeim" -DAG_JSON_TRAVERSAL_CID="baguqeeram5ujjqrwheyaty3w5gdsmoz6vittchvhk723jjqxk7hakxkd47xq" -DAG_PB_CID="bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke" - -test_expect_success "Add CARs for path traversal and DAG-PB representation tests" ' - ipfs dag import --pin-roots ../t0123-gateway-json-cbor/dag-cbor-traversal.car > import_output && - test_should_contain $DAG_CBOR_TRAVERSAL_CID import_output && - ipfs dag import --pin-roots ../t0123-gateway-json-cbor/dag-json-traversal.car > import_output && - test_should_contain $DAG_JSON_TRAVERSAL_CID import_output && - ipfs dag import --pin-roots ../t0123-gateway-json-cbor/dag-pb.car > import_output && - test_should_contain $DAG_PB_CID import_output -' - -IPNS_ID_DAG_JSON=k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2 -IPNS_ID_DAG_CBOR=k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l - -test_expect_success "Add ipns records for path traversal and DAG-PB representation tests" ' - ipfs routing put --allow-offline /ipns/${IPNS_ID_DAG_JSON} ../t0123-gateway-json-cbor/${IPNS_ID_DAG_JSON}.ipns-record && - ipfs routing put --allow-offline /ipns/${IPNS_ID_DAG_CBOR} ../t0123-gateway-json-cbor/${IPNS_ID_DAG_CBOR}.ipns-record -' - -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 -' - -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 -' - -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 -' - -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 -' - -## NATIVE TESTS for DAG-JSON (0x0129) and DAG-CBOR (0x71): -## DAG- regression tests for core behaviors when native DAG-(CBOR|JSON) is requested - -test_native_dag () { - name=$1 - format=$2 - disposition=$3 - CID=$4 - IPNS_ID=$5 - - # 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 - ' - - # 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 - ' - - 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 - ' - - 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 - ' - - # 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 - ' - - 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 - ' - - - # 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 - ' - - 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 - ' - - 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 - ' - - # 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 - ' - - # 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 - ' - 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 - ' - test_expect_success "HEAD $name with only-if-cached for missing block returns HTTP 412 Precondition Failed" ' - MISSING_CID=$(echo "{\"t\": \"$(date +%s)\"}" | 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 - ' - - # 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. - - 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 - ' - - 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 - ' - - 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 - ' - - - # 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 /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 - ' - - 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 - ' - - -} - -test_native_dag "DAG-JSON" "json" "inline" "$DAG_JSON_TRAVERSAL_CID" ${IPNS_ID_DAG_JSON} -test_native_dag "DAG-CBOR" "cbor" "attachment" "$DAG_CBOR_TRAVERSAL_CID" ${IPNS_ID_DAG_CBOR} - -test_kill_ipfs_daemon - -test_done - -# vim: set ts=2 sw=2 et: diff --git a/test/sharness/t0123-gateway-json-cbor/README.md b/test/sharness/t0123-gateway-json-cbor/README.md deleted file mode 100644 index 5a63b192af8..00000000000 --- a/test/sharness/t0123-gateway-json-cbor/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# Dataset description/sources - -- dag-cbor-traversal.car - -- dag-json-traversal.car - -- dag-pb.car - -- dag-pb.json - -- fixtures.car - - raw CARv1 - -generated with: - -```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) - -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} > fixtures.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/test/sharness/t0123-gateway-json-cbor/dag-cbor-traversal.car b/test/sharness/t0123-gateway-json-cbor/dag-cbor-traversal.car deleted file mode 100644 index 92c3d4f3e21718627007431c6b6d0cc1693be206..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 318 zcmcColvlXV(2oIMVptN{kPzW{vS&r0ub_{_K>mhu-w1 zv^b}ir4|)u=I1dM5Tklwa$0`=qLiG>yll7)cbQITWL7ctu-q3j&R(lE-F}^dl&{i> zKYDy?e%dYj{535;Oie9HtSCq+tW3+S zN-Qr(GOx-pP0uSxH_s|J&aEu1%u6yc%1f`xP0cs2$TQ8(%{47ZOe!%eRI1fc%1_El zO)dc$mz0EK_&Lb+xI#2#-t#MrbvfF8z zZSAu%HyyJ6o*#0o^a0ObkQqf7E=#I1%FigR$SF!oPs}qet|&?`PD`!KG%e4s$jmO! z&n(R|%`{C;EzUElN-r=@Ez7Mm0lKW#8EhqA$>U3}JAK&Rg?BCqN|fEat~K(+;;O!m mNqL*n-%L%jtX9fM&B*}i+sBr1Tzs1^WU$DR8C diff --git a/test/sharness/t0123-gateway-json-cbor/dag-pb.car b/test/sharness/t0123-gateway-json-cbor/dag-pb.car deleted file mode 100644 index a6bb076c7e323e449dfe3f6290adbe7e3826cf21..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 392 zcmcColv6N9G>c!tg+FvpA8Lzlk~eSLZrIRuTwwE~hlf;U z76qo4r4|)u=I1eXF%qL(NS8|mq^|IQa`O8b2I)OECVzyMewgCAPNpIter34l*}|*5 zT4#fWnA7s}C0vCJfyzUL6rzjWn-?3Nly$m#PLi+f!g;?F8kf!m7^ME`R`a{7@j*j~ z9jIKdq@qNEmy3ymF`6hVpl07>^l?*Z@mjj;ut>RWcE+qL>A(DBr2-c2SUERp>UaIG uLhMP2MPRe}KxP|(+(Sr@M`}(^zK%k9eo;<}B9|dCUVv)x3~&opR$Z!{1Tq}`!({@E*_B@ucod~pEh~Fe6+Vnh$AgCCsnVcqC`RsWVjbGnmiQ} za}^R5fSMFQx)n0>6q57v(n^an^U@Xcf#If*l3BzBb|=AbgSzwi)&Fl^GA?Lu%@C?# zekhl4`lzm@t6A&6m@~gjeWiKbkld*ba;G=QorE;ucPA*q5Dq06VNiz(pSd#Sis|Qo z3&&WQwUzSjUDZnWE>nqFajY+Wv%U0UCaex6q=}G2^B@il2gN+Wlmbmr3p)>Tspfra zzuq^&%Z+8;aog1@_L@tNFW#`M%_oCfEfAQZW=d=Wr>M!`oI_B9IV4GOJ6>m-zGd?c z8TsBDGgG&fwdGf4EPLy4gI8MqnXLZyU?E;mqR>6M>u3`=T`36}Kr|XwU!0k9pY`dI z-dtbCS2N$ly#8A6{kLABvd8AnvB?FELTn{^S;hHz5~`pWb_2yQA-m86EKFpafyI_VZ5QMu0#h}}HQ*$!q)^KR00zs~cmMzZ diff --git a/test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record b/test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record deleted file mode 100644 index 7186c709e3ceb29fbfda0fd38b4e43109f26ce55..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 394 zcmd;b)XywPE7ng+OsgzP%}gpbDJ>~TPs%edElf?%O)*N(FRU_2%C1byDM~d;%{Iy` zFEckWPRl5(%qh<_sY*@F%oTE|Wo^}bx%d5*Sx4q7wQu^*{jh&wK$gukjlQ6!w<^zC z3zgkZ3FJ7HbjEJnE2pg~YAb1T`}pU#Pwl?`TRqWK?I))MgOaq7p^>q!fr+l6afpG1 zm4T&|siB^QrJ=E@n00{M& AZ2$lO diff --git a/test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record b/test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record deleted file mode 100644 index 28676f4d9a8824989d039a03376aeea9ae63d0d3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 398 zcmd;b*3T?RE7ng+OfM}=O)W~yH7(7`Dl96`NUcmPsWdJ(O;0J#&95>m%Pc8L&M3>s zHa9W`DyYad&q&O!$WAdauP799P;T3(=A&^x$Y#D|lG@q>LT5|;wEh}r>YUo65W?xX z)~)KP*_E#3s?1Ys{Wt72pZosTYWup`{b6o#URK<3lJD3g7?h-q42_I+4NPq4G7B@V2@KoE$;q~X{`u_XeTsd(Ml(;WP%n0C_P+X~( z`|*~;{f_SyrzS~i|89=(;gu+H(2(HipQ0Kl{`~X07?TnkT`#}eZV&jprZX;04hiv* z);`_Lz>>_skQ$blQ<@q Date: Wed, 28 Jun 2023 09:56:34 +0200 Subject: [PATCH 08/19] test(t0117): drop test ported to conformance --- test/sharness/t0117-gateway-block.sh | 90 ------------------ test/sharness/t0117-gateway-block/README.md | 21 ---- .../sharness/t0117-gateway-block/fixtures.car | Bin 309 -> 0 bytes 3 files changed, 111 deletions(-) delete mode 100755 test/sharness/t0117-gateway-block.sh delete mode 100644 test/sharness/t0117-gateway-block/README.md delete mode 100644 test/sharness/t0117-gateway-block/fixtures.car diff --git a/test/sharness/t0117-gateway-block.sh b/test/sharness/t0117-gateway-block.sh deleted file mode 100755 index a4a661bd194..00000000000 --- a/test/sharness/t0117-gateway-block.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash - -test_description="Test HTTP Gateway Raw Block (application/vnd.ipld.raw) Support" - -. lib/test-lib.sh - -test_init_ipfs -test_launch_ipfs_daemon_without_network - -# Import test case -# See the static fixtures in ./t0117-gateway-block/ -test_expect_success "Add the dir test directory" ' - ipfs dag import --pin-roots ../t0117-gateway-block/fixtures.car -' -ROOT_DIR_CID=bafybeie72edlprgtlwwctzljf6gkn2wnlrddqjbkxo3jomh4n7omwblxly # ./ -FILE_CID=bafkreihhpc5y2pqvl5rbe5uuyhqjouybfs3rvlmisccgzue2kkt5zq6upq # ./dir/ascii.txt - -# GET unixfs dir root block and compare it with `ipfs block get` output - - test_expect_success "GET with format=raw param returns a raw block" ' - ipfs block get "/ipfs/$ROOT_DIR_CID/dir" > expected && - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT_DIR_CID/dir?format=raw" -o curl_ipfs_dir_block_param_output && - test_cmp expected curl_ipfs_dir_block_param_output - ' - - test_expect_success "GET for application/vnd.ipld.raw returns a raw block" ' - ipfs block get "/ipfs/$ROOT_DIR_CID/dir" > expected_block && - curl -sX GET -H "Accept: application/vnd.ipld.raw" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT_DIR_CID/dir" -o curl_ipfs_dir_block_accept_output && - test_cmp expected_block curl_ipfs_dir_block_accept_output - ' - - test_expect_success "GET for application/vnd.ipld.raw with single range request includes correct bytes" ' - echo -n "application" > expected_file_block_single_range && - curl -sX GET -H "Accept: application/vnd.ipld.raw" -H "Range: bytes=6-16" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" -o curl_ipfs_file_block_single_range && - test_cmp expected_file_block_single_range curl_ipfs_file_block_single_range - ' - - test_expect_success "GET for application/vnd.ipld.raw with multiple range request includes correct bytes" ' - curl -sX GET -H "Accept: application/vnd.ipld.raw" -H "Range: bytes=6-16,0-4" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" -o curl_ipfs_file_block_multiple_range && - test_should_contain "Content-Range: bytes 6-16/31" curl_ipfs_file_block_multiple_range && - test_should_contain "Content-Type: application/vnd.ipld.raw" curl_ipfs_file_block_multiple_range && - test_should_contain "application" curl_ipfs_file_block_multiple_range && - test_should_contain "Content-Range: bytes 0-4/31" curl_ipfs_file_block_multiple_range && - test_should_contain "hello" curl_ipfs_file_block_multiple_range - ' - -# Make sure expected HTTP headers are returned with the block bytes - - test_expect_success "GET response for application/vnd.ipld.raw has expected Content-Type" ' - curl -svX GET -H "Accept: application/vnd.ipld.raw" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT_DIR_CID/dir/ascii.txt" >/dev/null 2>curl_output && - test_should_contain "< Content-Type: application/vnd.ipld.raw" curl_output - ' - - test_expect_success "GET response for application/vnd.ipld.raw includes Content-Length" ' - BYTES=$(ipfs block get $FILE_CID | wc --bytes) - test_should_contain "< Content-Length: $BYTES" curl_output - ' - - test_expect_success "GET response for application/vnd.ipld.raw includes Content-Disposition" ' - test_should_contain "< Content-Disposition: attachment\; filename=\"${FILE_CID}.bin\"" curl_output - ' - - test_expect_success "GET response for application/vnd.ipld.raw includes nosniff hint" ' - test_should_contain "< X-Content-Type-Options: nosniff" curl_output - ' - - test_expect_success "GET for application/vnd.ipld.raw with query filename includes Content-Disposition with custom filename" ' - curl -svX GET -H "Accept: application/vnd.ipld.raw" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT_DIR_CID/dir/ascii.txt?filename=foobar.bin" >/dev/null 2>curl_output_filename && - test_should_contain "< Content-Disposition: attachment\; filename=\"foobar.bin\"" curl_output_filename - ' - -# Cache control HTTP headers -# (basic checks, detailed behavior is tested in t0116-gateway-cache.sh) - - test_expect_success "GET response for application/vnd.ipld.raw includes Etag" ' - test_should_contain "< Etag: \"${FILE_CID}.raw\"" curl_output - ' - - test_expect_success "GET response for application/vnd.ipld.raw 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.raw includes Cache-Control" ' - test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_output - ' - -test_kill_ipfs_daemon - -test_done diff --git a/test/sharness/t0117-gateway-block/README.md b/test/sharness/t0117-gateway-block/README.md deleted file mode 100644 index 4ce37ae086f..00000000000 --- a/test/sharness/t0117-gateway-block/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Dataset description/sources - -- fixtures.car - - raw CARv1 - -generated with: - -```sh -# using ipfs version 0.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 > fixtures.car - -echo ROOT_DIR_CID=${ROOT_DIR_CID} # ./ -echo FILE_CID=${FILE_CID} # ./dir/ascii.txt - -# ROOT_DIR_CID=bafybeie72edlprgtlwwctzljf6gkn2wnlrddqjbkxo3jomh4n7omwblxly # ./ -# FILE_CID=bafkreihhpc5y2pqvl5rbe5uuyhqjouybfs3rvlmisccgzue2kkt5zq6upq # ./dir/ascii.txt -``` diff --git a/test/sharness/t0117-gateway-block/fixtures.car b/test/sharness/t0117-gateway-block/fixtures.car deleted file mode 100644 index 77da1b5542e281eb1c80a4a8763c85bd7424b60b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 309 zcmcColveYNahp`Ifpb-g~vLz*Snd z?RAF`b4q5BLWzWsh6*V>uh`vdCmNq5R5s<{gXzJHI@_hzc1&o=xiBke z`JKa8YJ@lwi<2`m^-3yAB;-M+I}@WTBQ+-{Um>xeASW|9u>|N@{j$6iz087~6uqLv GaxMV9-hqPv From e4528d09ca81e791da4758c026e6eaa08bfe48db Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 10:03:18 +0200 Subject: [PATCH 09/19] test(t0124): drop test ported to conformance --- test/sharness/t0124-gateway-ipns-record.sh | 58 ------------------ .../t0124-gateway-ipns-record/README.md | 27 -------- .../t0124-gateway-ipns-record/fixtures.car | Bin 107 -> 0 bytes ...i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record | Bin 392 -> 0 bytes 4 files changed, 85 deletions(-) delete mode 100755 test/sharness/t0124-gateway-ipns-record.sh delete mode 100644 test/sharness/t0124-gateway-ipns-record/README.md delete mode 100644 test/sharness/t0124-gateway-ipns-record/fixtures.car delete mode 100644 test/sharness/t0124-gateway-ipns-record/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record diff --git a/test/sharness/t0124-gateway-ipns-record.sh b/test/sharness/t0124-gateway-ipns-record.sh deleted file mode 100755 index 1d05b56985a..00000000000 --- a/test/sharness/t0124-gateway-ipns-record.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -test_description="Test HTTP Gateway IPNS Record (application/vnd.ipfs.ipns-record) Support" - -. lib/test-lib.sh - -test_init_ipfs -test_launch_ipfs_daemon - -# Import test case -# See the static fixtures in ./t0124-gateway-ipns-record/ -IPNS_KEY=k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab -FILE_CID=bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244 # A file containing Hello IPFS -test_expect_success "Add the test directory & IPNS records" ' - ipfs dag import ../t0124-gateway-ipns-record/fixtures.car && - ipfs routing put /ipns/${IPNS_KEY} ../t0124-gateway-ipns-record/${IPNS_KEY}.ipns-record -' - -test_expect_success "Create and Publish IPNS Key" ' - curl "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY" > curl_output_filename && - test_should_contain "Hello IPFS" curl_output_filename -' - -test_expect_success "GET KEY with format=ipns-record and validate key" ' - curl "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY?format=ipns-record" > curl_output_filename && - ipfs name inspect --verify $IPNS_KEY < curl_output_filename > verify_output && - test_should_contain "$FILE_CID" verify_output -' - -test_expect_success "GET KEY with 'Accept: application/vnd.ipfs.ipns-record' and validate key" ' - curl -H "Accept: application/vnd.ipfs.ipns-record" "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY" > curl_output_filename && - ipfs name inspect --verify $IPNS_KEY < curl_output_filename > verify_output && - test_should_contain "$FILE_CID" verify_output -' - -test_expect_success "GET KEY with format=ipns-record has expected HTTP headers" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY?format=ipns-record" > curl_output_filename 2>&1 && - test_should_contain "Content-Disposition: attachment;" curl_output_filename && - test_should_contain "Content-Type: application/vnd.ipfs.ipns-record" curl_output_filename && - test_should_contain "Cache-Control: public, max-age=3155760000" curl_output_filename -' - -test_expect_success "GET KEY with 'Accept: application/vnd.ipfs.ipns-record' has expected HTTP headers" ' - curl -H "Accept: application/vnd.ipfs.ipns-record" -sD - "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY" > curl_output_filename 2>&1 && - test_should_contain "Content-Disposition: attachment;" curl_output_filename && - test_should_contain "Content-Type: application/vnd.ipfs.ipns-record" curl_output_filename && - test_should_contain "Cache-Control: public, max-age=3155760000" curl_output_filename -' - -test_expect_success "GET KEY with expliciy ?filename= succeeds with modified Content-Disposition header" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY?format=ipns-record&filename=testтест.ipns-record" > curl_output_filename 2>&1 && - grep -F "Content-Disposition: attachment; filename=\"test____.ipns-record\"; filename*=UTF-8'\'\''test%D1%82%D0%B5%D1%81%D1%82.ipns-record" curl_output_filename && - test_should_contain "Content-Type: application/vnd.ipfs.ipns-record" curl_output_filename -' - -test_kill_ipfs_daemon - -test_done diff --git a/test/sharness/t0124-gateway-ipns-record/README.md b/test/sharness/t0124-gateway-ipns-record/README.md deleted file mode 100644 index 8ada577d4d7..00000000000 --- a/test/sharness/t0124-gateway-ipns-record/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Dataset description/sources - -- fixtures.car - - raw CARv1 - -- k51....ipns-record - - ipns record, encoded with protocol buffer - -generated with: - -```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) -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/test/sharness/t0124-gateway-ipns-record/fixtures.car b/test/sharness/t0124-gateway-ipns-record/fixtures.car deleted file mode 100644 index 5c541e430ea6d1aed7c20545c40c9a56994ac546..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 107 zcmcColvSFJ04j^dIZkA-4vOEfq6H0ie39ZWWO|7T-n zhTD&u+CmfaOSEsE-5&R2o=I`u(JdVUdxTlHr4_DQ%+Dynpd@8vXk@HwV4`bi6k=#> zWo%|;YN2OjY;I&8rNLm((9pBE;lYEa+D;DZwog8P;JtWuR2%!>xl6YFEuU6)>E){C z#}a3ym{+MAwLQ!K{b1W$zOv&|S}J#Rzj~K(y{i5eAFDB8+QsA7xBcYvn!>m=IV8kK zTKjY}14}XkLuy!JPHAcc<>8PKoLX3#nwOl)kO4F@GbOX6G6Ijca$t%=DhpB>023mb A4*&oF From daa415880ec7cf2be5f8f0791419e0230d3c3232 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 10:33:33 +0200 Subject: [PATCH 10/19] test(t0114): simplify tests --- test/sharness/t0114-gateway-subdomains.sh | 63 ----------------------- 1 file changed, 63 deletions(-) diff --git a/test/sharness/t0114-gateway-subdomains.sh b/test/sharness/t0114-gateway-subdomains.sh index 7655f8a8764..4ec5dc2bd00 100755 --- a/test/sharness/t0114-gateway-subdomains.sh +++ b/test/sharness/t0114-gateway-subdomains.sh @@ -216,16 +216,6 @@ ipfs config --json Gateway.PublicGateways '{ test_kill_ipfs_daemon test_launch_ipfs_daemon_without_network - -# example.com/ip(f|n)s/* -# ============================================================================= - -# path requests to the root hostname should redirect -# to a subdomain URL with proper origin isolation - -# *.ipns.example.com -# ============================================================================ - # API on subdomain gateway example.com # ============================================================================ @@ -302,59 +292,6 @@ test_expect_success \ test_should_contain \"$CID_VAL\" response " -## 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/" - -# router should not redirect to hostnames that could fail due to DNS limits -test_localhost_gateway_response_should_contain \ - "request for a too long CID at localhost/ipfs/{CIDv1} returns human readable error" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "CID incompatible with DNS label length limit of 63" - -test_localhost_gateway_response_should_contain \ - "request for a too long CID at localhost/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ - "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "400 Bad Request" - -# direct request should also fail (provides the same UX as router and avoids confusion) -test_localhost_gateway_response_should_contain \ - "request for a too long CID at {CIDv1}.ipfs.localhost returns expected payload" \ - "http://$CIDv1_TOO_LONG.ipfs.localhost:$GWAY_PORT" \ - "400 Bad Request" - -# 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" - -test_hostname_gateway_response_should_contain \ - "request for a too long CID at example.com/ipfs/{CIDv1} returns human readable error" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "CID incompatible with DNS label length limit of 63" - -test_hostname_gateway_response_should_contain \ - "request for a too long CID at example.com/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ - "example.com" \ - "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ - "400 Bad Request" - -test_hostname_gateway_response_should_contain \ - "request for a too long CID at {CIDv1}.ipfs.example.com returns HTTP Error 400 Bad Request" \ - "$CIDv1_TOO_LONG.ipfs.example.com" \ - "http://127.0.0.1:$GWAY_PORT/" \ - "400 Bad Request" - # Disable selected Paths for the subdomain gateway hostname # ============================================================================= From 0c188445ff7615e6e63b2844643b27af600efeee Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 11:17:05 +0200 Subject: [PATCH 11/19] test(t0112): drop test ported to conformance --- test/sharness/t0109-gateway-web-_redirects.sh | 165 ------------------ 1 file changed, 165 deletions(-) diff --git a/test/sharness/t0109-gateway-web-_redirects.sh b/test/sharness/t0109-gateway-web-_redirects.sh index 0bc2a23b600..d6a27db7f04 100755 --- a/test/sharness/t0109-gateway-web-_redirects.sh +++ b/test/sharness/t0109-gateway-web-_redirects.sh @@ -21,160 +21,12 @@ CAR_ROOT_CID=QmQyqMY5vUBSbSxyitJqthgwZunCQjDVtNd8ggVCxzuPQ4 REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples | cut -d "/" -f3) REDIRECTS_DIR_HOSTNAME="${REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" -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 -' - -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 -' - -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 -' - -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 -' - -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 -' - -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 -' - -# ensure custom 4xx works and has the same cache headers as regular /ipfs/ path -CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/404.html | cut -d "/" -f3) -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 -' - -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 -' - -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 -' - -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 -' - # 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 ' - -# With CRLF line terminator -NEWLINE_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/newlines | cut -d "/" -f3) -NEWLINE_REDIRECTS_DIR_HOSTNAME="${NEWLINE_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" - -test_expect_success "newline: _redirects has CRLF line terminators" ' - ipfs cat /ipfs/$NEWLINE_REDIRECTS_DIR_CID/_redirects | file - > response && - test_should_contain "with CRLF line terminators" response -' - -test_expect_success "newline: request for $NEWLINE_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file" ' - curl -sD - --resolve $NEWLINE_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$NEWLINE_REDIRECTS_DIR_HOSTNAME/redirect-one" > response && - test_should_contain "301 Moved Permanently" response && - test_should_contain "Location: /one.html" response -' - -# Good codes -GOOD_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/good-codes | cut -d "/" -f3) -GOOD_REDIRECTS_DIR_HOSTNAME="${GOOD_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" - -test_expect_success "good codes: request for $GOOD_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file" ' - curl -sD - --resolve $GOOD_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$GOOD_REDIRECTS_DIR_HOSTNAME/a301" > response && - test_should_contain "301 Moved Permanently" response && - test_should_contain "Location: /b301" response -' - -# Bad codes -BAD_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/bad-codes | cut -d "/" -f3) -BAD_REDIRECTS_DIR_HOSTNAME="${BAD_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" - -# if accessing a path that doesn't exist, read _redirects and fail parsing, and return error -test_expect_success "bad codes: request for $BAD_REDIRECTS_DIR_HOSTNAME/not-found returns error about bad code" ' - curl -sD - --resolve $BAD_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$BAD_REDIRECTS_DIR_HOSTNAME/not-found" > response && - test_should_contain "500" response && - test_should_contain "status code 999 is not supported" response -' - -# if accessing a path that does exist, don't read _redirects and therefore don't fail parsing -test_expect_success "bad codes: request for $BAD_REDIRECTS_DIR_HOSTNAME/found.html doesn't return error about bad code" ' - curl -sD - --resolve $BAD_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$BAD_REDIRECTS_DIR_HOSTNAME/found.html" > response && - test_should_contain "200" response && - test_should_contain "my found" response && - test_should_not_contain "unsupported redirect status" response -' - -# Invalid file, containing "hello" -INVALID_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/invalid | cut -d "/" -f3) -INVALID_REDIRECTS_DIR_HOSTNAME="${INVALID_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" - -# 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 -' - -# Invalid file, containing forced redirect -INVALID_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/forced | cut -d "/" -f3) -INVALID_REDIRECTS_DIR_HOSTNAME="${INVALID_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" - -# 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 -' - -# if accessing a path that doesn't exist and _redirects file is too large, return error -TOO_LARGE_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/too-large | cut -d "/" -f3) -TOO_LARGE_REDIRECTS_DIR_HOSTNAME="${TOO_LARGE_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" -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 -' - test_kill_ipfs_daemon # disable wildcard DNSLink gateway @@ -210,23 +62,6 @@ test_expect_success "spoofed DNSLink record resolves in cli" " test_should_contain \"index.html\" result " -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 -' - -# 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 -' - 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 && From cabcef6708ba7fab1eb7521a4368967b1c924703 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 14:44:05 +0200 Subject: [PATCH 12/19] test(t0116): drop test ported to conformance --- test/sharness/t0116-gateway-cache.sh | 272 ------------------ test/sharness/t0116-gateway-cache/README.md | 39 --- .../sharness/t0116-gateway-cache/fixtures.car | Bin 468 -> 0 bytes ...p32iwm9pdt9nq3y5rpn3ln9j12zfhe.ipns-record | Bin 394 -> 0 bytes 4 files changed, 311 deletions(-) delete mode 100755 test/sharness/t0116-gateway-cache.sh delete mode 100644 test/sharness/t0116-gateway-cache/README.md delete mode 100644 test/sharness/t0116-gateway-cache/fixtures.car delete mode 100644 test/sharness/t0116-gateway-cache/k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe.ipns-record diff --git a/test/sharness/t0116-gateway-cache.sh b/test/sharness/t0116-gateway-cache.sh deleted file mode 100755 index 2c0f2f83301..00000000000 --- a/test/sharness/t0116-gateway-cache.sh +++ /dev/null @@ -1,272 +0,0 @@ -#!/usr/bin/env bash - -test_description="Test HTTP Gateway Cache Control Support" - -. lib/test-lib.sh - -test_init_ipfs -test_launch_ipfs_daemon_without_network - -# Cache control support is based on logical roots (each path segment == one logical root). -# To maximize the test surface, we want to test: -# - /ipfs/ content path -# - /ipns/ content path -# - at least 3 levels -# - separate tests for a directory listing and a file -# - have implicit index.html for a good measure -# /ipns/root1/root2/root3/ (/ipns/root1/root2/root3/index.html) - -# Note: we cover important UnixFS-focused edge case here: -# -# ROOT3_CID - dir listing (dir-index-html response) -# ROOT4_CID - index.html returned as a root response (dir/), instead of generated dir-index-html -# FILE_CID - index.html returned directly, as a file -# -# Caching of things like raw blocks, CARs, dag-json and dag-cbor -# is tested in their respective suites. - -ROOT1_CID=bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui # ./ -ROOT2_CID=bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii # ./root2 -ROOT3_CID=bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja # ./root2/root3 -ROOT4_CID=bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q # ./root2/root3/root4 -FILE_CID=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am # ./root2/root3/root4/index.html -TEST_IPNS_ID=k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe - -# Import test case -# See the static fixtures in ./t0116-gateway-cache/ -test_expect_success "Add the test directory" ' - ipfs dag import --pin-roots ../t0116-gateway-cache/fixtures.car - ipfs routing put --allow-offline /ipns/${TEST_IPNS_ID} ../t0116-gateway-cache/${TEST_IPNS_ID}.ipns-record -' - -# GET /ipfs/ - # unixfs - test_expect_success "GET for /ipfs/ unixfs dir listing succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/" >/dev/null 2>curl_ipfs_dir_listing_output - ' - test_expect_success "GET for /ipfs/ unixfs dir with index.html succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/" >/dev/null 2>curl_ipfs_dir_index.html_output - ' - test_expect_success "GET for /ipfs/ unixfs file succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" >/dev/null 2>curl_ipfs_file_output - ' - # unixfs dir as dag-json - test_expect_success "GET for /ipfs/ unixfs dir as DAG-JSON succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/?format=dag-json" >/dev/null 2>curl_ipfs_dir_dag-json_output && - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/?format=json" >/dev/null 2>curl_ipfs_dir_json_output - ' -# GET /ipns/ - # unixfs - test_expect_success "GET for /ipns/ unixfs dir listing succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/" >/dev/null 2>curl_ipns_dir_listing_output - ' - test_expect_success "GET for /ipns/ unixfs dir with index.html succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/root4/" >/dev/null 2>curl_ipns_dir_index.html_output - ' - test_expect_success "GET for /ipns/ unixfs file succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/root4/index.html" >/dev/null 2>curl_ipns_file_output - ' - # unixfs dir as dag-json - test_expect_success "GET for /ipns/ unixfs dir as DAG-JSON succeeds" ' - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/root4/?format=dag-json" >/dev/null 2>curl_ipns_dir_dag-json_output && - curl -svX GET "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/root4/?format=json" >/dev/null 2>curl_ipns_dir_json_output - ' - -# Cache-Control - -# Cache-Control: immutable /ipfs/ file - test_expect_success "GET /ipfs/ unixfs file has expected Cache-Control" ' - test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_ipfs_file_output - ' -# Cache-Control: generated /ipfs/dir/ (listing) - # TODO: test_should_contain "< Cache-Control: public, max-age=TBD" curl_ipfs_dir_listing_output - test_expect_success "GET /ipfs/ unixfs dir listing has no Cache-Control" ' - test_should_not_contain "< Cache-Control" curl_ipns_dir_listing_output - ' -# Cache-Control: immutable /ipfs/dir/ (index.html) - test_expect_success "GET /ipfs/ unixfs dir with index.html has expected Cache-Control" ' - test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_ipfs_dir_index.html_output - ' -# Cache-Control: immutable /ipfs/ unixfs dir as dag-json - test_expect_success "GET /ipfs/ dag-json has expected Cache-Control" ' - test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_ipfs_dir_dag-json_output - ' -# Cache-Control: immutable /ipfs/ unixfs dir as json - test_expect_success "GET /ipfs/ unixfs dir as json has expected Cache-Control" ' - test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_ipfs_dir_json_output - ' -# Cache-Control: mutable /ipns/ file - test_expect_success "GET /ipns/ unixfs file has no Cache-Control" ' - test_should_not_contain "< Cache-Control" curl_ipns_file_output - ' -# Cache-Control: mutable /ipns/dir/ (generated listing) - test_expect_success "GET /ipns/ unixfs dir listing has no Cache-Control" ' - test_should_not_contain "< Cache-Control" curl_ipns_dir_listing_output - ' -# Cache-Control: mutable /ipns/dir/ (index.html) - test_expect_success "GET /ipns/ unixfs dir with index.html has no Cache-Control" ' - test_should_not_contain "< Cache-Control" curl_ipns_dir_index.html_output - ' -# Cache-Control: mutable /ipns/dir/ as dag-json - test_expect_success "GET /ipns/ unixfs dir as dag-json has no Cache-Control" ' - test_should_not_contain "< Cache-Control" curl_ipns_dir_dag-json_output - ' -# Cache-Control: mutable /ipns/dir/ as json - test_expect_success "GET /ipns/ unixfs dir as json has no Cache-Control" ' - test_should_not_contain "< Cache-Control" curl_ipns_dir_json_output - ' - -# Cache-Control: only-if-cached - test_expect_success "HEAD for /ipfs/ with only-if-cached succeeds when in local datastore" ' - curl -sv -I -H "Cache-Control: only-if-cached" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" > curl_onlyifcached_postitive_head 2>&1 && - cat curl_onlyifcached_postitive_head && - grep "< HTTP/1.1 200 OK" curl_onlyifcached_postitive_head - ' - test_expect_success "HEAD for /ipfs/ with only-if-cached fails when not in local datastore" ' - curl -sv -I -H "Cache-Control: only-if-cached" "http://127.0.0.1:$GWAY_PORT/ipfs/$(date | ipfs add --only-hash -Q)" > curl_onlyifcached_negative_head 2>&1 && - cat curl_onlyifcached_negative_head && - grep "< HTTP/1.1 412 Precondition Failed" curl_onlyifcached_negative_head - ' - test_expect_success "GET for /ipfs/ with only-if-cached succeeds when in local datastore" ' - curl -svX GET -H "Cache-Control: only-if-cached" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" >/dev/null 2>curl_onlyifcached_postitive_out && - cat curl_onlyifcached_postitive_out && - grep "< HTTP/1.1 200 OK" curl_onlyifcached_postitive_out - ' - test_expect_success "GET for /ipfs/ with only-if-cached fails when not in local datastore" ' - curl -svX GET -H "Cache-Control: only-if-cached" "http://127.0.0.1:$GWAY_PORT/ipfs/$(date | ipfs add --only-hash -Q)" >/dev/null 2>curl_onlyifcached_negative_out && - cat curl_onlyifcached_negative_out && - grep "< HTTP/1.1 412 Precondition Failed" curl_onlyifcached_negative_out - ' - -# X-Ipfs-Path - - ## dir generated listing - test_expect_success "GET /ipfs/ dir listing response has original content path in X-Ipfs-Path" ' - test_should_contain "< X-Ipfs-Path: /ipfs/$ROOT1_CID/root2/root3" curl_ipfs_dir_listing_output - ' - test_expect_success "GET /ipns/ dir listing response has original content path in X-Ipfs-Path" ' - test_should_contain "< X-Ipfs-Path: /ipns/$TEST_IPNS_ID/root2/root3" curl_ipns_dir_listing_output - ' - - ## dir static index.html - test_expect_success "GET /ipfs/ dir index.html response has original content path in X-Ipfs-Path" ' - test_should_contain "< X-Ipfs-Path: /ipfs/$ROOT1_CID/root2/root3/root4/" curl_ipfs_dir_index.html_output - ' - test_expect_success "GET /ipns/ dir index.html response has original content path in X-Ipfs-Path" ' - test_should_contain "< X-Ipfs-Path: /ipns/$TEST_IPNS_ID/root2/root3/root4/" curl_ipns_dir_index.html_output - ' - - # file - test_expect_success "GET /ipfs/ file response has original content path in X-Ipfs-Path" ' - test_should_contain "< X-Ipfs-Path: /ipfs/$ROOT1_CID/root2/root3/root4/index.html" curl_ipfs_file_output - ' - test_expect_success "GET /ipns/ file response has original content path in X-Ipfs-Path" ' - test_should_contain "< X-Ipfs-Path: /ipns/$TEST_IPNS_ID/root2/root3/root4/index.html" curl_ipns_file_output - ' - -# X-Ipfs-Roots - - ## dir generated listing - test_expect_success "GET /ipfs/ dir listing response has logical CID roots in X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID}" curl_ipfs_dir_listing_output - ' - test_expect_success "GET /ipns/ dir listing response has logical CID roots in X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID}" curl_ipns_dir_listing_output - ' - - ## dir static index.html - test_expect_success "GET /ipfs/ dir index.html response has logical CID roots in X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID},${ROOT4_CID}" curl_ipfs_dir_index.html_output - ' - test_expect_success "GET /ipns/ dir index.html response has logical CID roots in X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID},${ROOT4_CID}" curl_ipns_dir_index.html_output - ' - - ## file - test_expect_success "GET /ipfs/ file response has logical CID roots in X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID},${ROOT4_CID},${FILE_CID}" curl_ipfs_file_output - ' - test_expect_success "GET /ipns/ file response has logical CID roots in X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Roots: ${ROOT1_CID},${ROOT2_CID},${ROOT3_CID},${ROOT4_CID},${FILE_CID}" curl_ipns_file_output - ' - -# Etag - - ## dir generated listing - test_expect_success "GET /ipfs/ dir response has special Etag for generated dir listing" ' - test_should_contain "< Etag: \"DirIndex" curl_ipfs_dir_listing_output && - grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipfs_dir_listing_output - ' - test_expect_success "GET /ipns/ dir response has special Etag for generated dir listing" ' - test_should_contain "< Etag: \"DirIndex" curl_ipns_dir_listing_output && - grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipns_dir_listing_output - ' - - ## dir static index.html should use CID of the index.html file for improved HTTP caching - test_expect_success "GET /ipfs/ dir index.html response has dir CID as Etag" ' - test_should_contain "< Etag: \"${ROOT4_CID}\"" curl_ipfs_dir_index.html_output - ' - test_expect_success "GET /ipns/ dir index.html response has dir CID as Etag" ' - test_should_contain "< Etag: \"${ROOT4_CID}\"" curl_ipns_dir_index.html_output - ' - - ## file - test_expect_success "GET /ipfs/ response has CID as Etag for a file" ' - test_should_contain "< Etag: \"${FILE_CID}\"" curl_ipfs_file_output - ' - test_expect_success "GET /ipns/ response has CID as Etag for a file" ' - test_should_contain "< Etag: \"${FILE_CID}\"" curl_ipns_file_output - ' - -# If-None-Match (return 304 Not Modified when client sends matching Etag they already have) - - test_expect_success "GET for /ipfs/ file with matching Etag in If-None-Match returns 304 Not Modified" ' - curl -svX GET -H "If-None-Match: \"$FILE_CID\"" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" >/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - - test_expect_success "GET for /ipfs/ dir with index.html file with matching Etag in If-None-Match returns 304 Not Modified" ' - curl -svX GET -H "If-None-Match: \"$ROOT4_CID\"" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/" >/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - - test_expect_success "GET for /ipfs/ file with matching third Etag in If-None-Match returns 304 Not Modified" ' - curl -svX GET -H "If-None-Match: \"fakeEtag1\", \"fakeEtag2\", \"$FILE_CID\"" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" >/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - - test_expect_success "GET for /ipfs/ file with matching weak Etag in If-None-Match returns 304 Not Modified" ' - curl -svX GET -H "If-None-Match: W/\"$FILE_CID\"" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" >/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - - test_expect_success "GET for /ipfs/ file with wildcard Etag in If-None-Match returns 304 Not Modified" ' - curl -svX GET -H "If-None-Match: *" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" >/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - - test_expect_success "GET for /ipns/ file with matching Etag in If-None-Match returns 304 Not Modified" ' - curl -svX GET -H "If-None-Match: \"$FILE_CID\"" "http://127.0.0.1:$GWAY_PORT/ipns/$TEST_IPNS_ID/root2/root3/root4/index.html" >/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - - test_expect_success "GET for /ipfs/ dir listing with matching weak Etag in If-None-Match returns 304 Not Modified" ' - curl -svX GET -H "If-None-Match: W/\"$ROOT3_CID\"" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/" >/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - - # DirIndex etag is based on xxhash(./assets/dir-index-html), so we need to fetch it dynamically - test_expect_success "GET for /ipfs/ dir listing with matching strong Etag in If-None-Match returns 304 Not Modified" ' - curl -Is "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/"| grep -i Etag | cut -f2- -d: | tr -d "[:space:]\"" > dir_index_etag && - curl -svX GET -H "If-None-Match: \"$(/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - test_expect_success "GET for /ipfs/ dir listing with matching weak Etag in If-None-Match returns 304 Not Modified" ' - curl -Is "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/"| grep -i Etag | cut -f2- -d: | tr -d "[:space:]\"" > dir_index_etag && - curl -svX GET -H "If-None-Match: W/\"$(/dev/null 2>curl_output && - test_should_contain "304 Not Modified" curl_output - ' - -test_kill_ipfs_daemon - -test_done diff --git a/test/sharness/t0116-gateway-cache/README.md b/test/sharness/t0116-gateway-cache/README.md deleted file mode 100644 index 1be92f45456..00000000000 --- a/test/sharness/t0116-gateway-cache/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Dataset description/sources - -- fixtures.car - - raw CARv1 - -generated with: - -```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) - -mkdir -p root2/root3/root4 && -echo "hello" > root2/root3/root4/index.html && -ROOT1_CID=$(ipfs add -Qrw --cid-version 1 root2) -ROOT2_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2 | cut -d "/" -f3) -ROOT3_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3 | cut -d "/" -f3) -ROOT4_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3/root4 | cut -d "/" -f3) -FILE_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3/root4/index.html | cut -d "/" -f3) - -TEST_IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 cache_test_key | head -n1 | tr -d "\n") -# publish a record valid for a 100 years -ipfs name publish --key cache_test_key --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$ROOT1_CID" -ipfs routing get /ipns/${TEST_IPNS_ID} > ${TEST_IPNS_ID}.ipns-record - -echo ROOT1_CID=${ROOT1_CID} # ./ -echo ROOT2_CID=${ROOT2_CID} # ./root2 -echo ROOT3_CID=${ROOT3_CID} # ./root2/root3 -echo ROOT4_CID=${ROOT4_CID} # ./root2/root3/root4 -echo FILE_CID=${FILE_CID} # ./root2/root3/root4/index.html -echo TEST_IPNS_ID=${TEST_IPNS_ID} - -ipfs dag export ${ROOT1_CID} > ./fixtures.car - -# ROOT1_CID=bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui # ./ -# ROOT2_CID=bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii # ./root2 -# ROOT3_CID=bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja # ./root2/root3 -# ROOT4_CID=bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q # ./root2/root3/root4 -# FILE_CID=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am # ./root2/root3/root4/index.html -# TEST_IPNS_ID=k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe -``` diff --git a/test/sharness/t0116-gateway-cache/fixtures.car b/test/sharness/t0116-gateway-cache/fixtures.car deleted file mode 100644 index 43e570e1d6acb0a03531b47feb540318f5027204..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 468 zcmcColvx?P5~W2SVzij7-;r*+x4)dz{ z2?vnLaUeGn)L{a2bEuF)#Kf&zm9F0B$mRdAQQ-H@OVV5Z6eh1XxzN*OUp4TNzE)w$xALX&dsheDKaunGEFWiD$lMeD#}PM zNlD5}HOoxOPpqsct;jYl%@lIj#Aa`PX!4XzpKmQY)6e$9U7<`kzNU$F%{D)#mwVMZ z{GZ-h%zgj3z3+a9thHt*l@~txHDQw3!_thyQ+_E$H*2s|5P0dSAWyk;;nVFJVQW=5IUpX*UA(aKG3;+eR BnWX># From f8d2e53264cf7e934f060ce3ca3cd34d4f74f836 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Fri, 30 Jun 2023 09:51:22 +0200 Subject: [PATCH 13/19] t0114: restore tests flagged by lidel --- test/sharness/t0114-gateway-subdomains.sh | 86 +++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/test/sharness/t0114-gateway-subdomains.sh b/test/sharness/t0114-gateway-subdomains.sh index 4ec5dc2bd00..931e6d0ad64 100755 --- a/test/sharness/t0114-gateway-subdomains.sh +++ b/test/sharness/t0114-gateway-subdomains.sh @@ -139,6 +139,30 @@ test_localhost_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ "$CID_VAL" + +# Kubo specific end-to-end test +# (independend of gateway-conformance) + +# We return human-readable body with HTTP 301 so existing cli scripts that use path-based +# gateway are informed to enable following HTTP redirects +test_localhost_gateway_response_should_contain \ + "request for localhost/ipfs/{CIDv1} includes human-readable link and redirect info in HTTP 301 body" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv1" \ + ">Moved Permanently" + +# end Kubo specific end-to-end test + + +# Kubo specific end-to-end test +# (independend of gateway-conformance) + +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" + +# end Kubo specific end-to-end test + # API on localhost subdomain gateway # /api/v0 present on the root hostname @@ -163,6 +187,32 @@ test_localhost_gateway_response_should_contain \ ## (origin per content root at http://*.localhost) ## ============================================================================ + +# Kubo specific end-to-end test +# (independend of gateway-conformance) +# This tests link to parent specific to boxo + relative pathing end-to-end tests specific to Kubo. + +# {CID}.ipfs.localhost/sub/dir (Directory Listing) +DIR_HOSTNAME="${DIR_CID}.ipfs.localhost:$GWAY_PORT" + +test_expect_success "valid file and subdirectory paths in directory listing at {cid}.ipfs.localhost" ' + curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME" > list_response && + test_should_contain "hello" list_response && + test_should_contain "ipfs" list_response +' + +test_expect_success "valid parent directory path in directory listing at {cid}.ipfs.localhost/sub/dir" ' + curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/ipfs/ipns/" > list_response && + test_should_contain ".." list_response && + test_should_contain "bar" list_response +' + +test_expect_success "request for deep path resource at {cid}.ipfs.localhost/sub/dir/file" ' + curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/ipfs/ipns/bar" > list_response && + test_should_contain "text-file-content" list_response +' +# end Kubo specific end-to-end test + # .ipns.localhost # DNSLink test requires a daemon in online mode with precached /ipns/ mapping @@ -216,6 +266,35 @@ ipfs config --json Gateway.PublicGateways '{ test_kill_ipfs_daemon test_launch_ipfs_daemon_without_network + +# Kubo specific end-to-end test +# (independend of gateway-conformance) +# HTML specific to Boxo/Kubo, and relative pathing specific to code in Kubo + +# {CID}.ipfs.example.com/sub/dir (Directory Listing) +DIR_FQDN="${DIR_CID}.ipfs.example.com" + +test_expect_success "valid file and directory paths in directory listing at {cid}.ipfs.example.com" ' + curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT > list_response && + test_should_contain "hello" list_response && + test_should_contain "ipfs" list_response +' + +test_expect_success "valid parent directory path in directory listing at {cid}.ipfs.example.com/sub/dir" ' + curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/ > list_response && + test_should_contain ".." list_response && + test_should_contain "bar" list_response +' + +# Note 1: we test for sneaky subdir names {cid}.ipfs.example.com/ipfs/ipns/ :^) +# Note 2: example.com/ipfs/.. present in HTML will be redirected to subdomain, so this is expected behavior +test_expect_success "valid breadcrumb links in the header of directory listing at {cid}.ipfs.example.com/sub/dir" ' + curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/ > list_response && + test_should_contain "Index of" list_response && + test_should_contain "/ipfs/${DIR_CID}/ipfs/ipns" list_response +' + +# end Kubo specific end-to-end test # API on subdomain gateway example.com # ============================================================================ @@ -493,6 +572,11 @@ test_hostname_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/" \ "$CID_VAL" + +# Kubo specific end-to-end test +# (independend of gateway-conformance) +# test cofiguration beign wired up correctly end-to-end + ## ============================================================================ ## Test support for wildcards in gateway config ## ============================================================================ @@ -604,3 +688,5 @@ test_expect_success "clean up ipfs dir" ' ' test_done + +# end Kubo specific end-to-end test \ No newline at end of file From a4e1f56b699cd691cc18adb437a81d5e3cfb0a24 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Fri, 30 Jun 2023 09:52:29 +0200 Subject: [PATCH 14/19] t0112: restore --- test/sharness/t0112-gateway-cors.sh | 39 ++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test/sharness/t0112-gateway-cors.sh b/test/sharness/t0112-gateway-cors.sh index 528e469806c..e4fb571221a 100755 --- a/test/sharness/t0112-gateway-cors.sh +++ b/test/sharness/t0112-gateway-cors.sh @@ -15,9 +15,11 @@ EOF test_cmp expected actual ' +test_launch_ipfs_daemon + thash='bafkqabtimvwgy3yk' # hello -test_launch_ipfs_daemon +# Gateway # HTTP GET Request test_expect_success "GET to Gateway succeeds" ' @@ -25,12 +27,47 @@ test_expect_success "GET to Gateway succeeds" ' cat curl_output ' +# GET Response from Gateway should contain CORS headers +test_expect_success "GET response for Gateway resource looks good" ' + test_should_contain "< Access-Control-Allow-Origin: \*" curl_output && + test_should_contain "< Access-Control-Allow-Methods: GET" curl_output && + test_should_contain "< Access-Control-Allow-Methods: HEAD" curl_output && + test_should_contain "< Access-Control-Allow-Methods: OPTIONS" curl_output && + test_should_contain "< Access-Control-Allow-Headers: Content-Type" curl_output && + test_should_contain "< Access-Control-Allow-Headers: Range" curl_output && + test_should_contain "< Access-Control-Allow-Headers: User-Agent" curl_output && + test_should_contain "< Access-Control-Allow-Headers: X-Requested-With" curl_output && + test_should_contain "< Access-Control-Expose-Headers: Content-Range" curl_output && + test_should_contain "< Access-Control-Expose-Headers: Content-Length" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Chunked-Output" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Stream-Output" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Path" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Roots" curl_output +' # HTTP OPTIONS Request test_expect_success "OPTIONS to Gateway succeeds" ' curl -svX OPTIONS -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/ipfs/$thash" 2>curl_output && cat curl_output ' +# OPTION Response from Gateway should contain CORS headers +test_expect_success "OPTIONS response for Gateway resource looks good" ' + test_should_contain "< Access-Control-Allow-Origin: \*" curl_output && + test_should_contain "< Access-Control-Allow-Methods: GET" curl_output && + test_should_contain "< Access-Control-Allow-Methods: HEAD" curl_output && + test_should_contain "< Access-Control-Allow-Methods: OPTIONS" curl_output && + test_should_contain "< Access-Control-Allow-Headers: Content-Type" curl_output && + test_should_contain "< Access-Control-Allow-Headers: Range" curl_output && + test_should_contain "< Access-Control-Allow-Headers: User-Agent" curl_output && + test_should_contain "< Access-Control-Allow-Headers: X-Requested-With" curl_output && + test_should_contain "< Access-Control-Expose-Headers: Content-Range" curl_output && + test_should_contain "< Access-Control-Expose-Headers: Content-Length" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Chunked-Output" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Stream-Output" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Path" curl_output && + test_should_contain "< Access-Control-Expose-Headers: X-Ipfs-Roots" curl_output +' + # HTTP OPTIONS Request on path → subdomain HTTP 301 redirect # (regression test for https://github.com/ipfs/kubo/issues/9983#issuecomment-1599673976) test_expect_success "OPTIONS to Gateway succeeds" ' From 2f51a411a934f2261a1c6802c331ad61f8cbbc6a Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Fri, 30 Jun 2023 09:57:00 +0200 Subject: [PATCH 15/19] t0116: restore dirindex check --- test/sharness/t0116-gateway-cache.sh | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/sharness/t0116-gateway-cache.sh diff --git a/test/sharness/t0116-gateway-cache.sh b/test/sharness/t0116-gateway-cache.sh new file mode 100644 index 00000000000..0986ffa419a --- /dev/null +++ b/test/sharness/t0116-gateway-cache.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +test_description="Test HTTP Gateway Cache Control Support" + +. lib/test-lib.sh + +test_init_ipfs +test_launch_ipfs_daemon_without_network + +# Cache control support is based on logical roots (each path segment == one logical root). +# To maximize the test surface, we want to test: +# - /ipfs/ content path +# - /ipns/ content path +# - at least 3 levels +# - separate tests for a directory listing and a file +# - have implicit index.html for a good measure +# /ipns/root1/root2/root3/ (/ipns/root1/root2/root3/index.html) + +# Note: we cover important UnixFS-focused edge case here: +# +# ROOT3_CID - dir listing (dir-index-html response) +# ROOT4_CID - index.html returned as a root response (dir/), instead of generated dir-index-html +# FILE_CID - index.html returned directly, as a file +# +# Caching of things like raw blocks, CARs, dag-json and dag-cbor +# is tested in their respective suites. + +ROOT1_CID=bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui # ./ +ROOT2_CID=bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii # ./root2 +ROOT3_CID=bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja # ./root2/root3 +ROOT4_CID=bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q # ./root2/root3/root4 +FILE_CID=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am # ./root2/root3/root4/index.html +TEST_IPNS_ID=k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe + +# Import test case +# See the static fixtures in ./t0116-gateway-cache/ +test_expect_success "Add the test directory" ' + ipfs dag import --pin-roots ../t0116-gateway-cache/fixtures.car + ipfs routing put --allow-offline /ipns/${TEST_IPNS_ID} ../t0116-gateway-cache/${TEST_IPNS_ID}.ipns-record +' + + +# Etag + + ## dir generated listing + test_expect_success "GET /ipfs/ dir response has special Etag for generated dir listing" ' + test_should_contain "< Etag: \"DirIndex" curl_ipfs_dir_listing_output && + grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipfs_dir_listing_output + ' + test_expect_success "GET /ipns/ dir response has special Etag for generated dir listing" ' + test_should_contain "< Etag: \"DirIndex" curl_ipns_dir_listing_output && + grep -E "< Etag: \"DirIndex-.+_CID-${ROOT3_CID}\"" curl_ipns_dir_listing_output + ' + + +test_kill_ipfs_daemon + +test_done From 7b3972db8a76ae4bd0e1a71769050409b1cbf4f9 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Fri, 30 Jun 2023 09:57:52 +0200 Subject: [PATCH 16/19] t0109: restore file --- test/sharness/t0109-gateway-web-_redirects.sh | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/test/sharness/t0109-gateway-web-_redirects.sh b/test/sharness/t0109-gateway-web-_redirects.sh index d6a27db7f04..0bc2a23b600 100755 --- a/test/sharness/t0109-gateway-web-_redirects.sh +++ b/test/sharness/t0109-gateway-web-_redirects.sh @@ -21,12 +21,160 @@ CAR_ROOT_CID=QmQyqMY5vUBSbSxyitJqthgwZunCQjDVtNd8ggVCxzuPQ4 REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples | cut -d "/" -f3) REDIRECTS_DIR_HOSTNAME="${REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" +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 +' + +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 +' + +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 +' + +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 +' + +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 +' + +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 +' + +# ensure custom 4xx works and has the same cache headers as regular /ipfs/ path +CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/404.html | cut -d "/" -f3) +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 +' + +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 +' + +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 +' + +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 +' + # 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 ' + +# With CRLF line terminator +NEWLINE_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/newlines | cut -d "/" -f3) +NEWLINE_REDIRECTS_DIR_HOSTNAME="${NEWLINE_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" + +test_expect_success "newline: _redirects has CRLF line terminators" ' + ipfs cat /ipfs/$NEWLINE_REDIRECTS_DIR_CID/_redirects | file - > response && + test_should_contain "with CRLF line terminators" response +' + +test_expect_success "newline: request for $NEWLINE_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file" ' + curl -sD - --resolve $NEWLINE_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$NEWLINE_REDIRECTS_DIR_HOSTNAME/redirect-one" > response && + test_should_contain "301 Moved Permanently" response && + test_should_contain "Location: /one.html" response +' + +# Good codes +GOOD_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/good-codes | cut -d "/" -f3) +GOOD_REDIRECTS_DIR_HOSTNAME="${GOOD_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" + +test_expect_success "good codes: request for $GOOD_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file" ' + curl -sD - --resolve $GOOD_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$GOOD_REDIRECTS_DIR_HOSTNAME/a301" > response && + test_should_contain "301 Moved Permanently" response && + test_should_contain "Location: /b301" response +' + +# Bad codes +BAD_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/bad-codes | cut -d "/" -f3) +BAD_REDIRECTS_DIR_HOSTNAME="${BAD_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" + +# if accessing a path that doesn't exist, read _redirects and fail parsing, and return error +test_expect_success "bad codes: request for $BAD_REDIRECTS_DIR_HOSTNAME/not-found returns error about bad code" ' + curl -sD - --resolve $BAD_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$BAD_REDIRECTS_DIR_HOSTNAME/not-found" > response && + test_should_contain "500" response && + test_should_contain "status code 999 is not supported" response +' + +# if accessing a path that does exist, don't read _redirects and therefore don't fail parsing +test_expect_success "bad codes: request for $BAD_REDIRECTS_DIR_HOSTNAME/found.html doesn't return error about bad code" ' + curl -sD - --resolve $BAD_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$BAD_REDIRECTS_DIR_HOSTNAME/found.html" > response && + test_should_contain "200" response && + test_should_contain "my found" response && + test_should_not_contain "unsupported redirect status" response +' + +# Invalid file, containing "hello" +INVALID_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/invalid | cut -d "/" -f3) +INVALID_REDIRECTS_DIR_HOSTNAME="${INVALID_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" + +# 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 +' + +# Invalid file, containing forced redirect +INVALID_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/forced | cut -d "/" -f3) +INVALID_REDIRECTS_DIR_HOSTNAME="${INVALID_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" + +# 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 +' + +# if accessing a path that doesn't exist and _redirects file is too large, return error +TOO_LARGE_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/too-large | cut -d "/" -f3) +TOO_LARGE_REDIRECTS_DIR_HOSTNAME="${TOO_LARGE_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" +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 +' + test_kill_ipfs_daemon # disable wildcard DNSLink gateway @@ -62,6 +210,23 @@ test_expect_success "spoofed DNSLink record resolves in cli" " test_should_contain \"index.html\" result " +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 +' + +# 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 +' + 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 && From 130a1d923482a4d4c458dbe0e65b7e7d7e5ed184 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Fri, 30 Jun 2023 10:00:35 +0200 Subject: [PATCH 17/19] t0115: restore full file --- test/sharness/t0115-gateway-dir-listing.sh | 168 ++++++++++++++++++ .../t0115-gateway-dir-listing/README.md | 32 ++++ .../t0115-gateway-dir-listing/fixtures.car | Bin 0 -> 1053 bytes 3 files changed, 200 insertions(+) create mode 100755 test/sharness/t0115-gateway-dir-listing.sh create mode 100644 test/sharness/t0115-gateway-dir-listing/README.md create mode 100644 test/sharness/t0115-gateway-dir-listing/fixtures.car diff --git a/test/sharness/t0115-gateway-dir-listing.sh b/test/sharness/t0115-gateway-dir-listing.sh new file mode 100755 index 00000000000..1ce0861b2eb --- /dev/null +++ b/test/sharness/t0115-gateway-dir-listing.sh @@ -0,0 +1,168 @@ +#!/usr/bin/env bash +# +# Copyright (c) Protocol Labs + +test_description="Test directory listing (dir-index-html) on the HTTP gateway" + + +. lib/test-lib.sh + +## ============================================================================ +## Start IPFS Node and prepare test CIDs +## ============================================================================ + +test_expect_success "ipfs init" ' + export IPFS_PATH="$(pwd)/.ipfs" && + ipfs init --profile=test > /dev/null +' + +test_launch_ipfs_daemon_without_network + +# Import test case +# See the static fixtures in ./t0115-gateway-dir-listing/ +test_expect_success "Add the test directory" ' + ipfs dag import --pin-roots ../t0115-gateway-dir-listing/fixtures.car +' +DIR_CID=bafybeig6ka5mlwkl4subqhaiatalkcleo4jgnr3hqwvpmsqfca27cijp3i # ./rootDir/ +FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt +FILE_SIZE=34 + +## ============================================================================ +## 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 +' + +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 +' + +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 +' + +## ============================================================================ +## Test dir listing on subdomain gateway (eg. .ipfs.localhost:8080) +## ============================================================================ + +DIR_HOSTNAME="${DIR_CID}.ipfs.localhost" +# note: we skip DNS lookup by running curl with --resolve $DIR_HOSTNAME:127.0.0.1 + +test_expect_success "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 +' + +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 +' + +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 +' + +## ============================================================================ +## Test dir listing on DNSLink gateway (eg. example.com) +## ============================================================================ + +# DNSLink test requires a daemon in online mode with precached /ipns/ mapping +test_kill_ipfs_daemon +DNSLINK_HOSTNAME="website.example.com" +export IPFS_NS_MAP="$DNSLINK_HOSTNAME:/ipfs/$DIR_CID" +test_launch_ipfs_daemon + +# Note that: +# - this type of gateway is also tested in gateway_test.go#TestIPNSHostnameBacklinks +# (go tests and sharness tests should be kept in sync) +# - we skip DNS lookup by running curl with --resolve $DNSLINK_HOSTNAME:127.0.0.1 + +test_expect_success "dnslink gw: backlink on root CID should 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 +' + +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 +' + +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 +' + +## ============================================================================ +## End of tests, cleanup +## ============================================================================ + +test_kill_ipfs_daemon +test_expect_success "clean up ipfs dir" ' + rm -rf "$IPFS_PATH" +' +test_done diff --git a/test/sharness/t0115-gateway-dir-listing/README.md b/test/sharness/t0115-gateway-dir-listing/README.md new file mode 100644 index 00000000000..937438bcd65 --- /dev/null +++ b/test/sharness/t0115-gateway-dir-listing/README.md @@ -0,0 +1,32 @@ +# Dataset description/sources + +- fixtures.car + - raw CARv1 + +generated with: + +```sh +# using ipfs version 0.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} +echo FILE_CID=${FILE_CID} +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/test/sharness/t0115-gateway-dir-listing/fixtures.car b/test/sharness/t0115-gateway-dir-listing/fixtures.car new file mode 100644 index 0000000000000000000000000000000000000000..71a5603822741f25320438bd70823589120e313c GIT binary patch literal 1053 zcmcColvR$Z!{1TqeSN@tUjjg{Tlgc7mrAdS5w!gPn*17KH6I(#F3Vnld4xzQ6ixRGTe(8O`Zyg zxeAF2KuroD-3pm`3d#9-X{E)PdFcxJz;IJY$t>amyOUtJLEZWM>i;({85gv-W(d_V zKa@*2eN@-d)vWbj%$Z-NzS6vINbXbzxziiuPC}aSyAu>)2!|4kFsMU?&s>>u#q@K) zg=4JD+Ddu%u4<)wm#M_8IM$cG*3(nQFic@T$&fnuIuO3{I&*k2EHJEuD( zXEu8GPP(?~NTtQ!*2R(r|4!eUF1UKJ@frzWikc}A4+_gfkg)`nn?n*5x8rrT>037M zkdg1bF*9{rSzCT(#hs2>E#m S1&JjY3gwwVqO>H Date: Fri, 30 Jun 2023 10:04:59 +0200 Subject: [PATCH 18/19] t0114: restored rest of file --- test/sharness/t0114-gateway-subdomains.sh | 308 +++++++++++++++++++++- 1 file changed, 305 insertions(+), 3 deletions(-) diff --git a/test/sharness/t0114-gateway-subdomains.sh b/test/sharness/t0114-gateway-subdomains.sh index 931e6d0ad64..2596bb49254 100755 --- a/test/sharness/t0114-gateway-subdomains.sh +++ b/test/sharness/t0114-gateway-subdomains.sh @@ -139,6 +139,28 @@ test_localhost_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ "$CID_VAL" +# 'localhost' hostname is used for subdomains, and should not return +# payload directly, but redirect to URL with proper origin isolation + +test_localhost_gateway_response_should_contain \ + "request for localhost/ipfs/{CIDv1} returns HTTP 301 Moved Permanently" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv1" \ + "301 Moved Permanently" + +test_localhost_gateway_response_should_contain \ + "request for localhost/ipfs/{CIDv1} returns Location HTTP header for subdomain redirect in browsers" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv1" \ + "Location: http://$CIDv1.ipfs.localhost:$GWAY_PORT/" + +test_localhost_gateway_response_should_contain \ + "request for localhost/ipfs/{DIR_CID} returns HTTP 301 Moved Permanently" \ + "http://localhost:$GWAY_PORT/ipfs/$DIR_CID" \ + "301 Moved Permanently" + +test_localhost_gateway_response_should_contain \ + "request for localhost/ipfs/{DIR_CID} returns Location HTTP header for subdomain redirect in browsers" \ + "http://localhost:$GWAY_PORT/ipfs/$DIR_CID/" \ + "Location: http://$DIR_CID.ipfs.localhost:$GWAY_PORT/" # Kubo specific end-to-end test # (independend of gateway-conformance) @@ -152,6 +174,24 @@ test_localhost_gateway_response_should_contain \ # end Kubo specific end-to-end test +test_localhost_gateway_response_should_contain \ + "request for localhost/ipfs/{CIDv0} redirects to CIDv1 representation in subdomain" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv0" \ + "Location: http://${CIDv0to1}.ipfs.localhost:$GWAY_PORT/" + +# /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/" + +# /ipns/ # Kubo specific end-to-end test # (independend of gateway-conformance) @@ -187,6 +227,24 @@ test_localhost_gateway_response_should_contain \ ## (origin per content root at http://*.localhost) ## ============================================================================ +# {CID}.ipfs.localhost + +test_localhost_gateway_response_should_contain \ + "request for {CID}.ipfs.localhost should return expected payload" \ + "http://${CIDv1}.ipfs.localhost:$GWAY_PORT" \ + "$CID_VAL" + +# ensure /ipfs/ namespace is not mounted on subdomain +test_localhost_gateway_response_should_contain \ + "request for {CID}.ipfs.localhost/ipfs/{CID} should return HTTP 404" \ + "http://${CIDv1}.ipfs.localhost:$GWAY_PORT/ipfs/$CIDv1" \ + "404 Not Found" + +# ensure requests to /ipfs/* are not blocked, if content root has such subdirectory +test_localhost_gateway_response_should_contain \ + "request for {CID}.ipfs.localhost/ipfs/file.txt should return data from a file in CID content root" \ + "http://${DIR_CID}.ipfs.localhost:$GWAY_PORT/ipfs/file.txt" \ + "I am a txt file" # Kubo specific end-to-end test # (independend of gateway-conformance) @@ -213,6 +271,30 @@ test_expect_success "request for deep path resource at {cid}.ipfs.localhost/sub/ ' # end Kubo specific end-to-end test +# *.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" + +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/" + # .ipns.localhost # DNSLink test requires a daemon in online mode with precached /ipns/ mapping @@ -221,6 +303,11 @@ 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" + # api.localhost/api # Note: we use DIR_CID so refs -r returns some CIDs for child nodes @@ -250,6 +337,17 @@ ipfs config --json Gateway.PublicGateways '{ 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" + ## ============================================================================ ## Test subdomain-based requests with a custom hostname config ## (origin per content root at http://*.example.com) @@ -267,6 +365,96 @@ test_kill_ipfs_daemon test_launch_ipfs_daemon_without_network +# example.com/ip(f|n)s/* +# ============================================================================= + +# path requests to the root hostname should redirect +# to a subdomain URL with proper origin isolation + +test_hostname_gateway_response_should_contain \ + "request for example.com/ipfs/{CIDv1} produces redirect to {CIDv1}.ipfs.example.com" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ + "Location: http://$CIDv1.ipfs.example.com/" + +# error message should include original CID +# (and it should be case-sensitive, as we can't assume everyone uses base32) +test_hostname_gateway_response_should_contain \ + "request for example.com/ipfs/{InvalidCID} produces useful error before redirect" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/QmInvalidCID" \ + 'invalid path \"/ipfs/QmInvalidCID\"' + +test_hostname_gateway_response_should_contain \ + "request for example.com/ipfs/{CIDv0} produces redirect to {CIDv1}.ipfs.example.com" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv0" \ + "Location: http://${CIDv0to1}.ipfs.example.com/" + +# Support X-Forwarded-Proto +test_expect_success "request for http://example.com/ipfs/{CID} with X-Forwarded-Proto: https produces redirect to HTTPS URL" " + curl -H \"X-Forwarded-Proto: https\" -H \"Host: example.com\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && + test_should_contain \"Location: https://$CIDv1.ipfs.example.com/\" response +" + +# Support ipfs:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler +test_hostname_gateway_response_should_contain \ + "request for example.com/ipfs/?uri=ipfs%3A%2F%2F.. produces redirect to /ipfs/.. content path" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/?uri=ipfs%3A%2F%2FQmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco%2Fwiki%2FDiego_Maradona.html" \ + "Location: /ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/wiki/Diego_Maradona.html" + +# 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/" + +# 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 + " + +# 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" + +# *.ipfs.example.com: subdomain requests made with custom FQDN in Host header + +test_hostname_gateway_response_should_contain \ + "request for {CID}.ipfs.example.com should return expected payload" \ + "${CIDv1}.ipfs.example.com" \ + "http://127.0.0.1:$GWAY_PORT/" \ + "$CID_VAL" + +test_hostname_gateway_response_should_contain \ + "request for {CID}.ipfs.example.com/ipfs/{CID} should return HTTP 404" \ + "${CIDv1}.ipfs.example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ + "404 Not Found" + # Kubo specific end-to-end test # (independend of gateway-conformance) # HTML specific to Boxo/Kubo, and relative pathing specific to code in Kubo @@ -295,6 +483,41 @@ test_expect_success "valid breadcrumb links in the header of directory listing a ' # end Kubo specific end-to-end test + +test_expect_success "request for deep path resource {cid}.ipfs.example.com/sub/dir/file" ' + curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/bar > list_response && + test_should_contain "text-file-content" list_response +' + +# *.ipns.example.com +# ============================================================================ + +# .ipns.example.com + +test_hostname_gateway_response_should_contain \ + "request for {CIDv1-libp2p-key}.ipns.example.com returns expected payload" \ + "${RSA_IPNS_IDv1}.ipns.example.com" \ + "http://127.0.0.1:$GWAY_PORT" \ + "$CID_VAL" + +test_hostname_gateway_response_should_contain \ + "request for {CIDv1-libp2p-key}.ipns.example.com returns expected payload" \ + "${ED25519_IPNS_IDv1}.ipns.example.com" \ + "http://127.0.0.1:$GWAY_PORT" \ + "$CID_VAL" + +test_hostname_gateway_response_should_contain \ + "hostname request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ + "${RSA_IPNS_IDv1_DAGPB}.ipns.example.com" \ + "http://127.0.0.1:$GWAY_PORT" \ + "Location: http://${RSA_IPNS_IDv1}.ipns.example.com/" + +test_hostname_gateway_response_should_contain \ + "hostname request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ + "${ED25519_IPNS_IDv1_DAGPB}.ipns.example.com" \ + "http://127.0.0.1:$GWAY_PORT" \ + "Location: http://${ED25519_IPNS_IDv1}.ipns.example.com/" + # API on subdomain gateway example.com # ============================================================================ @@ -354,9 +577,6 @@ DNSLINK_FQDN="dnslink-subdomain-gw-test.example.org" export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1" test_launch_ipfs_daemon -# TODO: dns inlining? -# this lives in subdomain_gateway_ipns_test.go for now - test_hostname_gateway_response_should_contain \ "request for {dnslink}.ipns.example.com returns expected payload" \ "$DNSLINK_FQDN.ipns.example.com" \ @@ -371,6 +591,59 @@ test_expect_success \ test_should_contain \"$CID_VAL\" response " +## 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/" + +# router should not redirect to hostnames that could fail due to DNS limits +test_localhost_gateway_response_should_contain \ + "request for a too long CID at localhost/ipfs/{CIDv1} returns human readable error" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "CID incompatible with DNS label length limit of 63" + +test_localhost_gateway_response_should_contain \ + "request for a too long CID at localhost/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ + "http://localhost:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "400 Bad Request" + +# direct request should also fail (provides the same UX as router and avoids confusion) +test_localhost_gateway_response_should_contain \ + "request for a too long CID at {CIDv1}.ipfs.localhost returns expected payload" \ + "http://$CIDv1_TOO_LONG.ipfs.localhost:$GWAY_PORT" \ + "400 Bad Request" + +# 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" + +test_hostname_gateway_response_should_contain \ + "request for a too long CID at example.com/ipfs/{CIDv1} returns human readable error" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "CID incompatible with DNS label length limit of 63" + +test_hostname_gateway_response_should_contain \ + "request for a too long CID at example.com/ipfs/{CIDv1} returns HTTP Error 400 Bad Request" \ + "example.com" \ + "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1_TOO_LONG" \ + "400 Bad Request" + +test_hostname_gateway_response_should_contain \ + "request for a too long CID at {CIDv1}.ipfs.example.com returns HTTP Error 400 Bad Request" \ + "$CIDv1_TOO_LONG.ipfs.example.com" \ + "http://127.0.0.1:$GWAY_PORT/" \ + "400 Bad Request" + # Disable selected Paths for the subdomain gateway hostname # ============================================================================= @@ -572,6 +845,35 @@ test_hostname_gateway_response_should_contain \ "http://127.0.0.1:$GWAY_PORT/" \ "$CID_VAL" +## ============================================================================ +## Test support for X-Forwarded-Host +## ============================================================================ + +# set explicit subdomain gateway config for the hostname +ipfs config --json Gateway.PublicGateways '{ + "example.com": { + "UseSubdomains": true, + "Paths": ["/ipfs", "/ipns", "/api"] + } +}' || exit 1 +# restart daemon to apply config changes +test_kill_ipfs_daemon +test_launch_ipfs_daemon_without_network + +test_expect_success "request for http://fake.domain.com/ipfs/{CID} doesn't match the example.com gateway" " + curl -H \"Host: fake.domain.com\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && + test_should_contain \"200 OK\" response +" + +test_expect_success "request for http://fake.domain.com/ipfs/{CID} with X-Forwarded-Host: example.com match the example.com gateway" " + curl -H \"Host: fake.domain.com\" -H \"X-Forwarded-Host: example.com\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && + test_should_contain \"Location: http://$CIDv1.ipfs.example.com/\" response +" + +test_expect_success "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" " + curl -H \"Host: fake.domain.com\" -H \"X-Forwarded-Host: example.com\" -H \"X-Forwarded-Proto: https\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1\" > response && + test_should_contain \"Location: https://$CIDv1.ipfs.example.com/\" response +" # Kubo specific end-to-end test # (independend of gateway-conformance) From c0e6f5971002950511d49316f8a1e754e4b63a29 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Fri, 30 Jun 2023 11:56:08 +0200 Subject: [PATCH 19/19] fix: kill the iptb cluster --- test/sharness/t0026-id.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/sharness/t0026-id.sh b/test/sharness/t0026-id.sh index 5ae5f500609..d4248c56295 100755 --- a/test/sharness/t0026-id.sh +++ b/test/sharness/t0026-id.sh @@ -61,6 +61,8 @@ test_expect_success "checking AgentVersion with suffix (fetched via libp2p ident ipfsi 1 id "$(ipfsi 0 config Identity.PeerID)" -f "\n" > actual-libp2p-identify-agent-version && test_cmp expected-identify-agent-version actual-libp2p-identify-agent-version ' +iptb stop + test_kill_ipfs_daemon