From 7e9823732d7525ca42dd1c326965502e96cc6145 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 26 Jun 2023 12:49:18 +0200 Subject: [PATCH 01/24] t0109: clear --- fixtures/redirects_file/README.md | 12 ++ .../dnslink.yml} | 2 +- .../redirects.car} | Bin tests/redirects_file_test.go | 160 +----------------- 4 files changed, 22 insertions(+), 152 deletions(-) create mode 100644 fixtures/redirects_file/README.md rename fixtures/{t0109-dnslink.yml => redirects_file/dnslink.yml} (85%) rename fixtures/{t0109-redirects.car => redirects_file/redirects.car} (100%) diff --git a/fixtures/redirects_file/README.md b/fixtures/redirects_file/README.md new file mode 100644 index 000000000..482f90e33 --- /dev/null +++ b/fixtures/redirects_file/README.md @@ -0,0 +1,12 @@ +# Fixture for Redirects File Testing + +## Recipes + +### [dnslink.yml](./dnslink.yml) + +See comments in the yml file. + + +### [redirects.car](./redirects.car) + +Fixtures was provided in [specs.ipfs.tech](https://specs.ipfs.tech/http-gateways/web-redirects-file/#test-fixtures) \ No newline at end of file diff --git a/fixtures/t0109-dnslink.yml b/fixtures/redirects_file/dnslink.yml similarity index 85% rename from fixtures/t0109-dnslink.yml rename to fixtures/redirects_file/dnslink.yml index d65b5f638..15be77219 100644 --- a/fixtures/t0109-dnslink.yml +++ b/fixtures/redirects_file/dnslink.yml @@ -3,5 +3,5 @@ dnslinks: custom-dnslink: subdomain: dnslink-enabled-on-fqdn # this is the cid of the folder - # t0109-redirects.car:/examples/ + # ./redirects.car:/examples/ path: /ipfs/QmYBhLYDwVFvxos9h8CGU2ibaY66QNgv8hpfewxaQrPiZj \ No newline at end of file diff --git a/fixtures/t0109-redirects.car b/fixtures/redirects_file/redirects.car similarity index 100% rename from fixtures/t0109-redirects.car rename to fixtures/redirects_file/redirects.car diff --git a/tests/redirects_file_test.go b/tests/redirects_file_test.go index 7f8e63b17..18cbd2000 100644 --- a/tests/redirects_file_test.go +++ b/tests/redirects_file_test.go @@ -13,18 +13,13 @@ import ( . "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this were in t0109_gateway_web_redirects_test - func TestRedirectsFileSupport(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0109-redirects.car") + fixture := car.MustOpenUnixfsCar("redirects_file/redirects.car") redirectDir := fixture.MustGetNode("examples") redirectDirCID := redirectDir.Base32Cid() - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/404.html | cut -d "/" -f3) custom404 := fixture.MustGetNode("examples", "404.html") - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/410.html | cut -d "/" -f3) custom410 := fixture.MustGetNode("examples", "410.html") - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/451.html | cut -d "/" -f3) custom451 := fixture.MustGetNode("examples", "451.html") tests := SugarTests{} @@ -44,13 +39,6 @@ func TestRedirectsFileSupport(t *testing.T) { redirectDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, redirectDirCID, u.Host) tests = append(tests, SugarTests{ - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/redirect-one" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /one.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file", Request: Request(). @@ -62,13 +50,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/one.html"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/301-redirect-one redirects with 301, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/301-redirect-one" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /one.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/301-redirect-one redirects with 301, per _redirects file", Request: Request(). @@ -79,13 +60,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/one.html"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/302-redirect-two redirects with 302, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/302-redirect-two" > response && - // test_should_contain "302 Found" response && - // test_should_contain "Location: /two.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/302-redirect-two redirects with 302, per _redirects file", Request: Request(). @@ -96,13 +70,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/two.html"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/200-index returns 200, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/200-index" > response && - // test_should_contain "my index" response && - // test_should_contain "200 OK" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/200-index returns 200, per _redirects file", Request: Request(). @@ -111,13 +78,6 @@ func TestRedirectsFileSupport(t *testing.T) { Status(200). Body(Contains("my index")), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/posts/:year/:month/:day/:title redirects with 301 and placeholders, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/posts/2022/01/01/hello-world" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /articles/2022/01/01/hello-world" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/posts/:year/:month/:day/:title redirects with 301 and placeholders, per _redirects file", Request: Request(). @@ -128,13 +88,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/articles/2022/01/01/hello-world"), ), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/splat/one.html redirects with 301 and splat placeholder, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/splat/one.html" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /redirected-splat/one.html" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/splat/one.html redirects with 301 and splat placeholder, per _redirects file", Request: Request(). @@ -145,16 +98,6 @@ func TestRedirectsFileSupport(t *testing.T) { Header("Location").Equals("/redirected-splat/one.html"), ), }, - // # ensure custom 4xx works and has the same cache headers as regular /ipfs/ path - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/not-found/has-no-redirects-entry returns custom 404, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/not-found/has-no-redirects-entry" > response && - // test_should_contain "404 Not Found" response && - // test_should_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_contain "Etag: \"$CUSTOM_4XX_CID\"" response && - // test_should_contain "my 404" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/not-found/has-no-redirects-entry returns custom 404, per _redirects file", Request: Request(). @@ -167,14 +110,6 @@ func TestRedirectsFileSupport(t *testing.T) { ). Body(Contains(custom404.ReadFile())), }, - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/410.html | cut -d "/" -f3) - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/gone/has-no-redirects-entry returns custom 410, per _redirects file" ' - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/gone/has-no-redirects-entry" > response && - // test_should_contain "410 Gone" response && - // test_should_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_contain "Etag: \"$CUSTOM_4XX_CID\"" response && - // test_should_contain "my 410" response - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/gone/has-no-redirects-entry returns custom 410, per _redirects file", Request: Request(). @@ -187,16 +122,6 @@ func TestRedirectsFileSupport(t *testing.T) { ). Body(Contains(custom410.ReadFile())), }, - // CUSTOM_4XX_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/examples/451.html | cut -d "/" -f3) - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/unavail/has-no-redirects-entry returns custom 451, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/unavail/has-no-redirects-entry" > response && - // test_should_contain "451 Unavailable For Legal Reasons" response && - // test_should_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_contain "Etag: \"$CUSTOM_4XX_CID\"" response && - // test_should_contain "my 451" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/unavail/has-no-redirects-entry returns custom 451, per _redirects file", Request: Request(). @@ -209,13 +134,6 @@ func TestRedirectsFileSupport(t *testing.T) { ). Body(Contains(custom451.ReadFile())), }, - // test_expect_success "request for $REDIRECTS_DIR_HOSTNAME/catch-all returns 200, per _redirects file" ' - // - // curl -sD - --resolve $REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$REDIRECTS_DIR_HOSTNAME/catch-all" > response && - // test_should_contain "200 OK" response && - // test_should_contain "my index" response - // - // ' { Name: "request for $REDIRECTS_DIR_HOSTNAME/catch-all returns 200, per _redirects file", Request: Request(). @@ -232,38 +150,19 @@ func TestRedirectsFileSupport(t *testing.T) { // test_should_not_contain "my 404" response // // ' - // { - // // TODO: confirm with lidel: this should be skipped - // Name: "This test ensures _redirects is supported only on Web Gateways that use Host header (DNSLink, Subdomain)", - // Hint: ` - // We expect the request to fail with a 404 (do not use the _redirect), and that 404 should not contain the custom 404 body. - // `, - // Request: Request(). - // URL("http://127.0.0.1:8080/ipfs/{{etag}}/301-redirect-one", redirectDirCID), - // Response: Expect(). - // Status(404). - // Body(Not(Contains(custom404.ReadFile()))), - // }, + // TODO(lidel): Do we want to explicitly test something like "if the spec `redirect` is not enabled, then test this case"? + // Recommendation: don't (because you might disable a spec just because it's not fully implemented yet, which is different from not supporting it) + // and keep the test in kubo sharness. }...) // # Invalid file, containing forced redirect - // INVALID_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/forced | cut -d "/" -f3) invalidRedirectsDirCID := fixture.MustGetNode("forced").Base32Cid() - // INVALID_REDIRECTS_DIR_HOSTNAME="${INVALID_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" invalidDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, invalidRedirectsDirCID, u.Host) - // TOO_LARGE_REDIRECTS_DIR_CID=$(ipfs resolve -r /ipfs/$CAR_ROOT_CID/too-large | cut -d "/" -f3) + tooLargeRedirectsDirCID := fixture.MustGetNode("too-large").Base32Cid() - // TOO_LARGE_REDIRECTS_DIR_HOSTNAME="${TOO_LARGE_REDIRECTS_DIR_CID}.ipfs.localhost:$GWAY_PORT" tooLargeDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, tooLargeRedirectsDirCID, u.Host) tests = append(tests, SugarTests{ - // # if accessing a path that doesn't exist, read _redirects and fail parsing, and return error - // test_expect_success "invalid file: request for $INVALID_REDIRECTS_DIR_HOSTNAME/not-found returns error about invalid redirects file" ' - // curl -sD - --resolve $INVALID_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$INVALID_REDIRECTS_DIR_HOSTNAME/not-found" > response && - // test_should_contain "500" response && - // test_should_contain "could not parse _redirects:" response && - // test_should_contain "forced redirects (or \"shadowing\") are not supported" response - // ' { Name: "invalid file: request for $INVALID_REDIRECTS_DIR_HOSTNAME/not-found returns error about invalid redirects file", Hint: `if accessing a path that doesn't exist, read _redirects and fail parsing, and return error`, @@ -278,13 +177,6 @@ func TestRedirectsFileSupport(t *testing.T) { ), ), }, - // # if accessing a path that doesn't exist and _redirects file is too large, return error - // test_expect_success "invalid file: request for $TOO_LARGE_REDIRECTS_DIR_HOSTNAME/not-found returns error about too large redirects file" ' - // curl -sD - --resolve $TOO_LARGE_REDIRECTS_DIR_HOSTNAME:127.0.0.1 "http://$TOO_LARGE_REDIRECTS_DIR_HOSTNAME/not-found" > response && - // test_should_contain "500" response && - // test_should_contain "could not parse _redirects:" response && - // test_should_contain "redirects file size cannot exceed" response - // ' { Name: "invalid file: request for $TOO_LARGE_REDIRECTS_DIR_HOSTNAME/not-found returns error about too large redirects file", Hint: `if accessing a path that doesn't exist and _redirects file is too large, return error`, @@ -306,7 +198,7 @@ func TestRedirectsFileSupport(t *testing.T) { } func TestRedirectsFileSupportWithDNSLink(t *testing.T) { - dnsLinks := dnslink.MustOpenDNSLink("t0109-dnslink.yml") + dnsLinks := dnslink.MustOpenDNSLink("redirects_file/dnslink.yml") dnsLink := dnsLinks.MustGet("custom-dnslink") gatewayURL := SubdomainGatewayURL @@ -318,20 +210,6 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { dnsLinkBaseUrl := Fmt("{{scheme}}://{{dnslink}}.{{host}}", u.Scheme, dnsLink, u.Host) tests := SugarTests{ - // # make sure test setup is valid (fail if CoreAPI is unable to resolve) - // test_expect_success "spoofed DNSLink record resolves in cli" " - // ipfs resolve /ipns/$DNSLINK_FQDN > result && - // test_should_contain \"$REDIRECTS_DIR_CID\" result && - // ipfs cat /ipns/$DNSLINK_FQDN/_redirects > result && - // test_should_contain \"index.html\" result - // " - // SKIPPED - - // test_expect_success "request for $DNSLINK_FQDN/redirect-one redirects with default of 301, per _redirects file" ' - // curl -sD - --resolve $DNSLINK_FQDN:$GWAY_PORT:127.0.0.1 "http://$DNSLINK_FQDN:$GWAY_PORT/redirect-one" > response && - // test_should_contain "301 Moved Permanently" response && - // test_should_contain "Location: /one.html" response - // ' { Name: "request for $DNSLINK_FQDN/redirect-one redirects with default of 301, per _redirects file", Request: Request(). @@ -342,16 +220,6 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { Header("Location", "/one.html"), ), }, - // # ensure custom 404 works and has the same cache headers as regular /ipns/ paths - // test_expect_success "request for $DNSLINK_FQDN/en/has-no-redirects-entry returns custom 404, per _redirects file" ' - // curl -sD - --resolve $DNSLINK_FQDN:$GWAY_PORT:127.0.0.1 "http://$DNSLINK_FQDN:$GWAY_PORT/not-found/has-no-redirects-entry" > response && - // test_should_contain "404 Not Found" response && - // test_should_contain "Etag: \"Qmd9GD7Bauh6N2ZLfNnYS3b7QVAijbud83b8GE8LPMNBBP\"" response && - // test_should_not_contain "Cache-Control: public, max-age=29030400, immutable" response && - // test_should_not_contain "immutable" response && - // test_should_contain "Date: " response && - // test_should_contain "my 404" response - // ' { Name: "request for $DNSLINK_FQDN/en/has-no-redirects-entry returns custom 404, per _redirects file", Hint: `ensure custom 404 works and has the same cache headers as regular /ipns/ paths`, @@ -366,7 +234,6 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { Header("Date").Exists(), ). Body( - // TODO: I like the readable part here, maybe rewrite to load the file. Contains("my 404"), ), }, @@ -376,18 +243,9 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { // test_should_not_contain "301 Moved Permanently" response && // test_should_not_contain "Location:" response // ' - // TODO(lidel): this test seems to validate some kubo behavior not really gateway. - // { - // Name: "request for $NO_DNSLINK_FQDN/redirect-one does not redirect, since DNSLink is disabled", - // Request: Request(). - // URL("{{url}}/redirect-one", noDnsLinkBaseUrl), - // Response: Expect(). - // // TODO: add "status not equal to 301" check. - // // TODO: what `test_should_not_contain "one.html" response` actually means? No location correct? - // Headers( - // Header("Location").Not().Exists(), - // ), - // }, + // TODO(lidel): Do we want to explicitly test something like "if the spec is not enabled, then test this case"? + // Recommendation: don't (because you might disable a spec just because it's not fully implemented yet, which is different from not supporting it) + // and keep the test in kubo sharness. } RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.DNSLinkGateway, specs.RedirectsFile) From 20d7295676066feadebaa2af7bbe55caef0f0d69 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 26 Jun 2023 14:20:12 +0200 Subject: [PATCH 02/24] t0112: clear --- tests/path_gateway_unixfs_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/path_gateway_unixfs_test.go b/tests/path_gateway_unixfs_test.go index 8fe4fe77f..1503b05ee 100644 --- a/tests/path_gateway_unixfs_test.go +++ b/tests/path_gateway_unixfs_test.go @@ -471,7 +471,6 @@ func TestGatewaySymlink(t *testing.T) { RunWithSpecs(t, tests, specs.PathGatewayUnixFS) } -// TODO(laurent): this were in t0112_gateway_cors_test func TestCors(t *testing.T) { cidHello := "bafkqabtimvwgy3yk" // hello From 278dde008964fc9706f653b9209e8dc4ba76649d Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 26 Jun 2023 14:24:15 +0200 Subject: [PATCH 03/24] t0113: clear --- fixtures/path_gateway_unixfs/README.md | 14 ++++++++++++++ .../symlink.car} | Bin tests/path_gateway_unixfs_test.go | 4 +--- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 fixtures/path_gateway_unixfs/README.md rename fixtures/{t0113-gateway-symlink.car => path_gateway_unixfs/symlink.car} (100%) diff --git a/fixtures/path_gateway_unixfs/README.md b/fixtures/path_gateway_unixfs/README.md new file mode 100644 index 000000000..5593db3a9 --- /dev/null +++ b/fixtures/path_gateway_unixfs/README.md @@ -0,0 +1,14 @@ +# Path Gateway Fixtures + +## Recipes + +### [symlink.car](./symlink.car) + +```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 > symlink.car +``` diff --git a/fixtures/t0113-gateway-symlink.car b/fixtures/path_gateway_unixfs/symlink.car similarity index 100% rename from fixtures/t0113-gateway-symlink.car rename to fixtures/path_gateway_unixfs/symlink.car diff --git a/tests/path_gateway_unixfs_test.go b/tests/path_gateway_unixfs_test.go index 1503b05ee..ed6c25790 100644 --- a/tests/path_gateway_unixfs_test.go +++ b/tests/path_gateway_unixfs_test.go @@ -430,10 +430,8 @@ func TestGatewayCacheWithIPNS(t *testing.T) { RunWithSpecs(t, tests, specs.PathGatewayUnixFS, specs.PathGatewayIPNS) } -// TODO(laurent): this were in t0113_gateway_symlink_test - func TestGatewaySymlink(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0113-gateway-symlink.car") + fixture := car.MustOpenUnixfsCar("path_gateway_unixfs/symlink.car") rootDirCID := fixture.MustGetCid() tests := SugarTests{ From fa4ddce8e41355ed317c008bc9b1497f1b0dd992 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 26 Jun 2023 15:23:04 +0200 Subject: [PATCH 04/24] t0114: clear (a) --- fixtures/subdomain_gateway_ipfs/README.md | 47 ++++++++++++++++++ .../fixtures.car} | Bin tests/subdomain_gateway_ipfs_test.go | 19 +------ 3 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 fixtures/subdomain_gateway_ipfs/README.md rename fixtures/{t0114-gateway_subdomains.car => subdomain_gateway_ipfs/fixtures.car} (100%) diff --git a/fixtures/subdomain_gateway_ipfs/README.md b/fixtures/subdomain_gateway_ipfs/README.md new file mode 100644 index 000000000..140f2e9c3 --- /dev/null +++ b/fixtures/subdomain_gateway_ipfs/README.md @@ -0,0 +1,47 @@ +# Subdomain Gateway Fixtures + +## Recipes + +### [fixtures.car](./fixtures.car) + +```sh +# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) + +# CIDv0to1 is necessary because raw-leaves are enabled by default during +# "ipfs add" with CIDv1 and disabled with CIDv0 +CID_VAL="hello" +CIDv1=$(echo $CID_VAL | ipfs add --cid-version 1 -Q) +CIDv0=$(echo $CID_VAL | ipfs add --cid-version 0 -Q) +CIDv0to1=$(echo "$CIDv0" | ipfs cid base32) +# sha512 will be over 63char limit, even when represented in Base36 +CIDv1_TOO_LONG=$(echo $CID_VAL | ipfs add --cid-version 1 --hash sha2-512 -Q) + +echo CID_VAL=${CID_VAL} +echo CIDv1=${CIDv1} +echo CIDv0=${CIDv0} +echo CIDv0to1=${CIDv0to1} +echo CIDv1_TOO_LONG=${CIDv1_TOO_LONG} + +# Directory tree crafted to test for edge cases like "/ipfs/ipfs/ipns/bar" +mkdir -p testdirlisting/ipfs/ipns && +echo "hello" > testdirlisting/hello && +echo "text-file-content" > testdirlisting/ipfs/ipns/bar && +mkdir -p testdirlisting/api && +mkdir -p testdirlisting/ipfs && +echo "I am a txt file" > testdirlisting/api/file.txt && +echo "I am a txt file" > testdirlisting/ipfs/file.txt && +DIR_CID=$(ipfs add -Qr --cid-version 1 testdirlisting) + +echo DIR_CID=${DIR_CID} # ./testdirlisting + +ipfs files mkdir /t0114/ +ipfs files cp /ipfs/${CIDv1} /t0114/ +ipfs files cp /ipfs/${CIDv0} /t0114/ +ipfs files cp /ipfs/${CIDv0to1} /t0114/ +ipfs files cp /ipfs/${DIR_CID} /t0114/ +ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/ + +ROOT=`ipfs files stat /t0114/ --hash` + +ipfs dag export ${ROOT} > ./fixtures.car +``` \ No newline at end of file diff --git a/fixtures/t0114-gateway_subdomains.car b/fixtures/subdomain_gateway_ipfs/fixtures.car similarity index 100% rename from fixtures/t0114-gateway_subdomains.car rename to fixtures/subdomain_gateway_ipfs/fixtures.car diff --git a/tests/subdomain_gateway_ipfs_test.go b/tests/subdomain_gateway_ipfs_test.go index fad892e5e..26856b859 100644 --- a/tests/subdomain_gateway_ipfs_test.go +++ b/tests/subdomain_gateway_ipfs_test.go @@ -144,7 +144,7 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { // TODO(laurent): this were in t0114_gateway_subdomains_test.go func TestGatewaySubdomains(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0114-gateway_subdomains.car") + fixture := car.MustOpenUnixfsCar("subdomain_gateway_ipfs/fixtures.car") CIDVal := string(fixture.MustGetRawData("hello-CIDv1")) // hello DirCID := fixture.MustGetCid("testdirlisting") @@ -210,10 +210,6 @@ func TestGatewaySubdomains(t *testing.T) { Contains("{{scheme}}://{{cid}}.ipfs.{{host}}/", u.Scheme, CIDv0to1, u.Host), ), }, - // ============================================================================ - // Test subdomain-based requests to a local gateway with default config - // (origin per content root at http://*.example.com) - // ============================================================================ { Name: "request for {CID}.ipfs.example.com should return expected payload", Request: Request().URL("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, CIDv1, u.Host), @@ -283,17 +279,6 @@ func TestGatewaySubdomains(t *testing.T) { ), ), }, - // ## ============================================================================ - // ## Test subdomain-based requests with a custom hostname config - // ## (origin per content root at http://*.example.com) - // ## ============================================================================ - - // # example.com/ip(f|n)s/* - // # ============================================================================= - - // # path requests to the root hostname should redirect - // # to a subdomain URL with proper origin isolation - { Name: "request for example.com/ipfs/{CIDv1} produces redirect to {CIDv1}.ipfs.example.com", Hint: "path requests to the root hostname should redirect to a subdomain URL with proper origin isolation", @@ -303,7 +288,6 @@ func TestGatewaySubdomains(t *testing.T) { Header("Location").Equals("{{scheme}}://{{cid}}.ipfs.{{host}}/", u.Scheme, CIDv1, u.Host), ), }, - { Name: "request for example.com/ipfs/{InvalidCID} produces useful error before redirect", Hint: "error message should include original CID (and it should be case-sensitive, as we can't assume everyone uses base32)", @@ -333,7 +317,6 @@ func TestGatewaySubdomains(t *testing.T) { Header("Location").Equals("https://{{cid}}.ipfs.{{host}}/", CIDv1, u.Host), ), }, - { Name: "request for example.com/ipfs/?uri=ipfs%3A%2F%2F.. produces redirect to /ipfs/.. content path", Hint: "Support ipfs:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler", From 74eca4efb50f7b0adf2419d1b520ccb91a909087 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 26 Jun 2023 15:37:05 +0200 Subject: [PATCH 05/24] t0114: clear (b) --- ...XSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record | Bin ...8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record | Bin fixtures/subdomain_gateway/README.md | 93 ++++++++++ .../{t0114 => subdomain_gateway}/dnslink.yml | 0 .../fixtures.car | Bin fixtures/subdomain_gateway_ipfs/README.md | 47 ----- tests/subdomain_gateway_ipfs_test.go | 4 +- tests/subdomain_gateway_ipns_test.go | 160 +----------------- 8 files changed, 98 insertions(+), 206 deletions(-) rename fixtures/{t0114 => subdomain_gateway}/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record (100%) rename fixtures/{t0114 => subdomain_gateway}/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record (100%) create mode 100644 fixtures/subdomain_gateway/README.md rename fixtures/{t0114 => subdomain_gateway}/dnslink.yml (100%) rename fixtures/{subdomain_gateway_ipfs => subdomain_gateway}/fixtures.car (100%) delete mode 100644 fixtures/subdomain_gateway_ipfs/README.md diff --git a/fixtures/t0114/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record b/fixtures/subdomain_gateway/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record similarity index 100% rename from fixtures/t0114/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record rename to fixtures/subdomain_gateway/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record diff --git a/fixtures/t0114/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record b/fixtures/subdomain_gateway/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record similarity index 100% rename from fixtures/t0114/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record rename to fixtures/subdomain_gateway/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record diff --git a/fixtures/subdomain_gateway/README.md b/fixtures/subdomain_gateway/README.md new file mode 100644 index 000000000..746ed7db8 --- /dev/null +++ b/fixtures/subdomain_gateway/README.md @@ -0,0 +1,93 @@ +# Subdomain Gateway Fixtures + +## Recipes + +### [dnslink.yml](./dnslink.yml) + +See comments in the yml file. + +### [fixtures.car](./fixtures.car) + +```sh +# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) + +# CIDv0to1 is necessary because raw-leaves are enabled by default during +# "ipfs add" with CIDv1 and disabled with CIDv0 +CID_VAL="hello" +CIDv1=$(echo $CID_VAL | ipfs add --cid-version 1 -Q) +CIDv0=$(echo $CID_VAL | ipfs add --cid-version 0 -Q) +CIDv0to1=$(echo "$CIDv0" | ipfs cid base32) +# sha512 will be over 63char limit, even when represented in Base36 +CIDv1_TOO_LONG=$(echo $CID_VAL | ipfs add --cid-version 1 --hash sha2-512 -Q) + +echo CID_VAL=${CID_VAL} +echo CIDv1=${CIDv1} +echo CIDv0=${CIDv0} +echo CIDv0to1=${CIDv0to1} +echo CIDv1_TOO_LONG=${CIDv1_TOO_LONG} + +# Directory tree crafted to test for edge cases like "/ipfs/ipfs/ipns/bar" +mkdir -p testdirlisting/ipfs/ipns && +echo "hello" > testdirlisting/hello && +echo "text-file-content" > testdirlisting/ipfs/ipns/bar && +mkdir -p testdirlisting/api && +mkdir -p testdirlisting/ipfs && +echo "I am a txt file" > testdirlisting/api/file.txt && +echo "I am a txt file" > testdirlisting/ipfs/file.txt && +DIR_CID=$(ipfs add -Qr --cid-version 1 testdirlisting) + +echo DIR_CID=${DIR_CID} # ./testdirlisting + +ipfs files mkdir /t0114/ +ipfs files cp /ipfs/${CIDv1} /t0114/ +ipfs files cp /ipfs/${CIDv0} /t0114/ +ipfs files cp /ipfs/${CIDv0to1} /t0114/ +ipfs files cp /ipfs/${DIR_CID} /t0114/ +ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/ + +ROOT=`ipfs files stat /t0114/ --hash` + +ipfs dag export ${ROOT} > ./fixtures.car +``` + +### [ipns-records](./) + +We create ipns-records pointing to the CIDv1 generated above: + +```sh +KEY_NAME=test_key_rsa_$RANDOM +RSA_KEY=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 ${KEY_NAME} | head -n1 | tr -d "\n") +RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0) +RSA_IPNS_IDv1=$(echo "$RSA_KEY" | ipfs cid format -v 1 --mc libp2p-key -b base36) +RSA_IPNS_IDv1_DAGPB=$(echo "$RSA_IPNS_IDv0" | ipfs cid format -v 1 -b base36) + +# publish a record valid for a 100 years +ipfs name publish --key ${KEY_NAME} --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$CIDv1" +ipfs routing get /ipns/${RSA_KEY} > ${RSA_KEY}.ipns-record + +echo RSA_KEY=${RSA_KEY} +echo RSA_IPNS_IDv0=${RSA_IPNS_IDv0} +echo RSA_IPNS_IDv1=${RSA_IPNS_IDv1} +echo RSA_IPNS_IDv1_DAGPB=${RSA_IPNS_IDv1_DAGPB} + +KEY_NAME=test_key_ed25519_$RANDOM +ED25519_KEY=$(ipfs key gen --ipns-base=b58mh --type=ed25519 ${KEY_NAME} | head -n1 | tr -d "\n") +ED25519_IPNS_IDv0=$ED25519_KEY +ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=base36 | grep ${KEY_NAME} | cut -d " " -f1 | tr -d "\n") +ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --mc dag-pb) + +# ed25519 fits under 63 char limit when represented in base36 +IPNS_ED25519_B58MH=$(ipfs key list -l --ipns-base b58mh | grep $KEY_NAME | cut -d" " -f1 | tr -d "\n") +IPNS_ED25519_B36CID=$(ipfs key list -l --ipns-base base36 | grep $KEY_NAME | cut -d" " -f1 | tr -d "\n") + +# publish a record valid for a 100 years +ipfs name publish --key ${KEY_NAME} --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$CIDv1" +ipfs routing get /ipns/${ED25519_KEY} > ${ED25519_KEY}.ipns-record + +echo ED25519_KEY=${ED25519_KEY} +echo ED25519_IPNS_IDv0=${ED25519_IPNS_IDv0} +echo ED25519_IPNS_IDv1=${ED25519_IPNS_IDv1} +echo ED25519_IPNS_IDv1_DAGPB=${ED25519_IPNS_IDv1_DAGPB} +echo IPNS_ED25519_B58MH=${IPNS_ED25519_B58MH} +echo IPNS_ED25519_B36CID=${IPNS_ED25519_B36CID} +``` diff --git a/fixtures/t0114/dnslink.yml b/fixtures/subdomain_gateway/dnslink.yml similarity index 100% rename from fixtures/t0114/dnslink.yml rename to fixtures/subdomain_gateway/dnslink.yml diff --git a/fixtures/subdomain_gateway_ipfs/fixtures.car b/fixtures/subdomain_gateway/fixtures.car similarity index 100% rename from fixtures/subdomain_gateway_ipfs/fixtures.car rename to fixtures/subdomain_gateway/fixtures.car diff --git a/fixtures/subdomain_gateway_ipfs/README.md b/fixtures/subdomain_gateway_ipfs/README.md deleted file mode 100644 index 140f2e9c3..000000000 --- a/fixtures/subdomain_gateway_ipfs/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Subdomain Gateway Fixtures - -## Recipes - -### [fixtures.car](./fixtures.car) - -```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) - -# CIDv0to1 is necessary because raw-leaves are enabled by default during -# "ipfs add" with CIDv1 and disabled with CIDv0 -CID_VAL="hello" -CIDv1=$(echo $CID_VAL | ipfs add --cid-version 1 -Q) -CIDv0=$(echo $CID_VAL | ipfs add --cid-version 0 -Q) -CIDv0to1=$(echo "$CIDv0" | ipfs cid base32) -# sha512 will be over 63char limit, even when represented in Base36 -CIDv1_TOO_LONG=$(echo $CID_VAL | ipfs add --cid-version 1 --hash sha2-512 -Q) - -echo CID_VAL=${CID_VAL} -echo CIDv1=${CIDv1} -echo CIDv0=${CIDv0} -echo CIDv0to1=${CIDv0to1} -echo CIDv1_TOO_LONG=${CIDv1_TOO_LONG} - -# Directory tree crafted to test for edge cases like "/ipfs/ipfs/ipns/bar" -mkdir -p testdirlisting/ipfs/ipns && -echo "hello" > testdirlisting/hello && -echo "text-file-content" > testdirlisting/ipfs/ipns/bar && -mkdir -p testdirlisting/api && -mkdir -p testdirlisting/ipfs && -echo "I am a txt file" > testdirlisting/api/file.txt && -echo "I am a txt file" > testdirlisting/ipfs/file.txt && -DIR_CID=$(ipfs add -Qr --cid-version 1 testdirlisting) - -echo DIR_CID=${DIR_CID} # ./testdirlisting - -ipfs files mkdir /t0114/ -ipfs files cp /ipfs/${CIDv1} /t0114/ -ipfs files cp /ipfs/${CIDv0} /t0114/ -ipfs files cp /ipfs/${CIDv0to1} /t0114/ -ipfs files cp /ipfs/${DIR_CID} /t0114/ -ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/ - -ROOT=`ipfs files stat /t0114/ --hash` - -ipfs dag export ${ROOT} > ./fixtures.car -``` \ No newline at end of file diff --git a/tests/subdomain_gateway_ipfs_test.go b/tests/subdomain_gateway_ipfs_test.go index 26856b859..9a29b0f57 100644 --- a/tests/subdomain_gateway_ipfs_test.go +++ b/tests/subdomain_gateway_ipfs_test.go @@ -141,10 +141,8 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGatewayIPFS) } -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - func TestGatewaySubdomains(t *testing.T) { - fixture := car.MustOpenUnixfsCar("subdomain_gateway_ipfs/fixtures.car") + fixture := car.MustOpenUnixfsCar("subdomain_gateway/fixtures.car") CIDVal := string(fixture.MustGetRawData("hello-CIDv1")) // hello DirCID := fixture.MustGetCid("testdirlisting") diff --git a/tests/subdomain_gateway_ipns_test.go b/tests/subdomain_gateway_ipns_test.go index 3c2376aba..8669a86f3 100644 --- a/tests/subdomain_gateway_ipns_test.go +++ b/tests/subdomain_gateway_ipns_test.go @@ -14,15 +14,13 @@ import ( "github.com/multiformats/go-multicodec" ) -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - func TestGatewaySubdomainAndIPNS(t *testing.T) { tests := SugarTests{} - rsaFixture := ipns.MustOpenIPNSRecordWithKey("t0114/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record") - ed25519Fixture := ipns.MustOpenIPNSRecordWithKey("t0114/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record") + rsaFixture := ipns.MustOpenIPNSRecordWithKey("subdomain_gateway/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record") + ed25519Fixture := ipns.MustOpenIPNSRecordWithKey("subdomain_gateway/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record") - car := car.MustOpenUnixfsCar("t0114/fixtures.car") + car := car.MustOpenUnixfsCar("subdomain_gateway/fixtures.car") helloCID := "bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am" payload := string(car.MustGetRawData(helloCID)) @@ -45,15 +43,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { for _, record := range ipnsRecords { tests = append(tests, SugarTests{ - // # /ipns/ - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "http://localhost:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \ - // "Location: http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "http://localhost:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \ - // "Location: http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" { Name: "request for /ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain", Request: Request(). @@ -65,16 +54,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { Equals("{{scheme}}://{{cid}}.ipns.{{host}}/", u.Scheme, record.IdV1(), u.Host), ), }, - // # *.ipns.localhost - // # .ipns.localhost - // test_localhost_gateway_response_should_contain \ - // "request for {CIDv1-libp2p-key}.ipns.localhost returns expected payload" \ - // "http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT" \ - // "$CID_VAL" - // test_localhost_gateway_response_should_contain \ - // "request for {CIDv1-libp2p-key}.ipns.localhost returns expected payload" \ - // "http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT" \ - // "$CID_VAL" { Name: "request for {CIDv1-libp2p-key}.ipns.{gateway} returns expected payload", Request: Request(). @@ -83,14 +62,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { Status(200). BodyWithHint("Request for {{cid}}.ipns.{{host}} returns expected payload", payload), }, - // test_localhost_gateway_response_should_contain \ - // "localhost request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ - // "http://${RSA_IPNS_IDv1_DAGPB}.ipns.localhost:$GWAY_PORT" \ - // "Location: http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" - // test_localhost_gateway_response_should_contain \ - // "localhost request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \ - // "http://${ED25519_IPNS_IDv1_DAGPB}.ipns.localhost:$GWAY_PORT" \ - // "Location: http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/" { Name: "request for {CIDv1-dag-pb}.ipns.{gateway} redirects to CID with libp2p-key multicodec", Request: Request(). @@ -102,19 +73,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { Equals("{{scheme}}://{{cid}}.ipns.{{host}}/", u.Scheme, record.IdV1(), u.Host), ), }, - // # example.com/ipns/ - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \ - // "Location: http://${RSA_IPNS_IDv1}.ipns.example.com/" - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \ - // "Location: http://${ED25519_IPNS_IDv1}.ipns.example.com/" - // NOTE: Done above, thanks to the loop - // // # *.ipns.example.com // # ============================================================================ @@ -184,20 +142,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { } tests = append(tests, SugarTests{ - // ## Test subdomain handling of CIDs that do not fit in a single DNS Label (>63chars) - // ## https://github.com/ipfs/go-ipfs/issues/7318 - // ## ============================================================================ - // # local: *.localhost - // test_localhost_gateway_response_should_contain \ - // "request for a ED25519 libp2p-key at localhost/ipns/{b58mh} returns Location HTTP header for DNS-safe subdomain redirect in browsers" \ - // "http://localhost:$GWAY_PORT/ipns/$IPNS_ED25519_B58MH" \ - // "Location: http://${IPNS_ED25519_B36CID}.ipns.localhost:$GWAY_PORT/" - // # public subdomain gateway: *.example.com - // test_hostname_gateway_response_should_contain \ - // "request for a ED25519 libp2p-key at example.com/ipns/{b58mh} returns Location HTTP header for DNS-safe subdomain redirect in browsers" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ED25519_B58MH" \ - // "Location: http://${IPNS_ED25519_B36CID}.ipns.example.com" { Name: "request for a ED25519 libp2p-key at example.com/ipns/{b58mh} returns Location HTTP header for DNS-safe subdomain redirect in browsers", Request: Request(). @@ -215,8 +159,6 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGatewayIPNS) } -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { tests := SugarTests{} @@ -226,7 +168,7 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { SubdomainLocalhostGatewayURL, } - dnsLinks := dnslink.MustOpenDNSLink("t0114/dnslink.yml") + dnsLinks := dnslink.MustOpenDNSLink("subdomain_gateway/dnslink.yml") wikipedia := dnsLinks.MustGet("wikipedia") dnsLinkTest := dnsLinks.MustGet("test") @@ -237,11 +179,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { } tests = append(tests, SugarTests{ - // # /ipns/ - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{fqdn} redirects to DNSLink in subdomain" \ - // "http://localhost:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en.wikipedia-on-ipfs.org.ipns.localhost:$GWAY_PORT/wiki" { Name: "request for /ipns/{fqdn} redirects to DNSLink in subdomain", Request: Request(). @@ -252,16 +189,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Equals("{{scheme}}://{{fqdn}}.ipns.{{host}}/wiki/", u.Scheme, dnslink.InlineDNS(wikipedia), u.Host), ), }, - // # .ipns.localhost - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // test_kill_ipfs_daemon - // DNSLINK_FQDN="dnslink-test.example.com" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1" - // test_launch_ipfs_daemon - // test_localhost_gateway_response_should_contain \ - // "request for {dnslink}.ipns.localhost returns expected payload" \ - // "http://$DNSLINK_FQDN.ipns.localhost:$GWAY_PORT" \ - // "$CID_VAL" { Name: "request for {dnslink}.ipns.{gateway} returns expected payload", Request: Request(). @@ -269,52 +196,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Response: Expect(). Body("hello\n"), }, - // ## ============================================================================ - // ## Test DNSLink inlining on HTTP gateways - // ## ============================================================================ - // # set explicit subdomain gateway config for the hostname - // ipfs config --json Gateway.PublicGateways '{ - // "localhost": { - // "UseSubdomains": true, - // "InlineDNSLink": true, - // "Paths": ["/ipfs", "/ipns", "/api"] - // }, - // "example.com": { - // "UseSubdomains": true, - // "InlineDNSLink": true, - // "Paths": ["/ipfs", "/ipns", "/api"] - // } - // }' || exit 1 - // # restart daemon to apply config changes - // test_kill_ipfs_daemon - // test_launch_ipfs_daemon_without_network - - // test_localhost_gateway_response_should_contain \ - // "request for localhost/ipns/{fqdn} redirects to DNSLink in subdomain with DNS inlining" \ - // "http://localhost:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en-wikipedia--on--ipfs-org.ipns.localhost:$GWAY_PORT/wiki" - - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{fqdn} redirects to DNSLink in subdomain with DNS inlining" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en-wikipedia--on--ipfs-org.ipns.example.com/wiki" - - // # example.com/ipns/ - - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/{fqdn} redirects to DNSLink in subdomain" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki" \ - // "Location: http://en.wikipedia-on-ipfs.org.ipns.example.com/wiki" - - // # DNSLink on Public gateway with a single-level wildcard TLS cert - // # "Option C" from https://github.com/ipfs/in-web-browsers/issues/169 - // test_expect_success \ - // "request for example.com/ipns/{fqdn} with X-Forwarded-Proto redirects to TLS-safe label in subdomain" " - // curl -H \"Host: example.com\" -H \"X-Forwarded-Proto: https\" -sD - \"http://127.0.0.1:$GWAY_PORT/ipns/en.wikipedia-on-ipfs.org/wiki\" > response && - // test_should_contain \"Location: https://en-wikipedia--on--ipfs-org.ipns.example.com/wiki\" response - // " { Name: "request for example.com/ipns/{fqdn} with X-Forwarded-Proto redirects to TLS-safe label in subdomain", Hint: ` @@ -330,12 +211,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Equals("https://{{inlined}}.ipns.{{host}}/wiki/", dnslink.InlineDNS(wikipedia), u.Host), ), }, - // # Support ipns:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler - // test_hostname_gateway_response_should_contain \ - // "request for example.com/ipns/?uri=ipns%3A%2F%2F.. produces redirect to /ipns/.. content path" \ - // "example.com" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/?uri=ipns%3A%2F%2Fen.wikipedia-on-ipfs.org" \ - // "Location: /ipns/en.wikipedia-on-ipfs.org" { Name: `request for example.com/ipns/?uri=ipns%3A%2F%2F.. produces redirect to /ipns/.. content path`, Hint: "Support ipns:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler", @@ -346,33 +221,6 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Header("Location").Equals("/ipns/{{wikipedia}}", wikipedia), ), }, - // # DNSLink: .ipns.example.com - // # (not really useful outside of localhost, as setting TLS for more than one - // # level of wildcard is a pain, but we support it if someone really wants it) - // # ============================================================================ - - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // test_kill_ipfs_daemon - // DNSLINK_FQDN="dnslink-subdomain-gw-test.example.org" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1" - // test_launch_ipfs_daemon - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink}.ipns.example.com returns expected payload" \ - // "$DNSLINK_FQDN.ipns.example.com" \ - // "http://127.0.0.1:$GWAY_PORT" \ - // "$CID_VAL" - // Note: this test was merged with the test for wikipedia in the end. - - // # DNSLink on Public gateway with a single-level wildcard TLS cert - // # "Option C" from https://github.com/ipfs/in-web-browsers/issues/169 - // test_expect_success \ - // "request for {single-label-dnslink}.ipns.example.com with X-Forwarded-Proto returns expected payload" " - // curl -H \"Host: dnslink--subdomain--gw--test-example-org.ipns.example.com\" -H \"X-Forwarded-Proto: https\" -sD - \"http://127.0.0.1:$GWAY_PORT\" > response && - // test_should_contain \"$CID_VAL\" response - // " - // Note: this test was merged with the test for wikipedia in the end. - }...) } From dd048bd32a5d2e4457a2c8f04d6fb1f73f17559f Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 17:06:54 +0200 Subject: [PATCH 06/24] t0114: clear (c) --- tests/subdomain_gateway_ipfs_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/subdomain_gateway_ipfs_test.go b/tests/subdomain_gateway_ipfs_test.go index 9a29b0f57..ff1ee0992 100644 --- a/tests/subdomain_gateway_ipfs_test.go +++ b/tests/subdomain_gateway_ipfs_test.go @@ -348,14 +348,16 @@ func TestGatewaySubdomains(t *testing.T) { // ## Test support for X-Forwarded-Host // ## ============================================================================ { - Name: "request for http://fake.domain.com/ipfs/{CID} doesn't match the example.com gateway", - Request: Request().URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1), + Name: "request for http://fake.domain.com/ipfs/{CID} doesn't match the example.com gateway", + Request: Request(). + URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1), Response: Expect(). Status(200), }, { Name: "request for http://fake.domain.com/ipfs/{CID} with X-Forwarded-Host: example.com match the example.com gateway", - Request: Request().URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). + Request: Request(). + URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). Header("X-Forwarded-Host", u.Host), Response: Expect(). Status(301). @@ -365,7 +367,8 @@ func TestGatewaySubdomains(t *testing.T) { }, { Name: "request for http://fake.domain.com/ipfs/{CID} with X-Forwarded-Host: example.com and X-Forwarded-Proto: https match the example.com gateway, redirect with https", - Request: Request().URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). + Request: Request(). + URL("{{scheme}}://{{domain}}/ipfs/{{cid}}", u.Scheme, "fake.domain.com", CIDv1). Header("X-Forwarded-Host", u.Host). Header("X-Forwarded-Proto", "https"), Response: Expect(). From 0893f3fcbccb6d25d90638c4c0743f8c3fd03001 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 17:26:05 +0200 Subject: [PATCH 07/24] t0114: clear (d) --- fixtures/subdomain_gateway/README.md | 10 +-- fixtures/t0114/README.md | 111 --------------------------- fixtures/t0114/fixtures.car | Bin 1518 -> 0 bytes tests/subdomain_gateway_ipns_test.go | 3 +- 4 files changed, 6 insertions(+), 118 deletions(-) delete mode 100644 fixtures/t0114/README.md delete mode 100644 fixtures/t0114/fixtures.car diff --git a/fixtures/subdomain_gateway/README.md b/fixtures/subdomain_gateway/README.md index 746ed7db8..d6d5f6aed 100644 --- a/fixtures/subdomain_gateway/README.md +++ b/fixtures/subdomain_gateway/README.md @@ -39,11 +39,11 @@ DIR_CID=$(ipfs add -Qr --cid-version 1 testdirlisting) echo DIR_CID=${DIR_CID} # ./testdirlisting ipfs files mkdir /t0114/ -ipfs files cp /ipfs/${CIDv1} /t0114/ -ipfs files cp /ipfs/${CIDv0} /t0114/ -ipfs files cp /ipfs/${CIDv0to1} /t0114/ -ipfs files cp /ipfs/${DIR_CID} /t0114/ -ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/ +ipfs files cp /ipfs/${CIDv1} /t0114/hello-CIDv1 +ipfs files cp /ipfs/${CIDv0} /t0114/hello-CIDv0 +ipfs files cp /ipfs/${CIDv0to1} /t0114/hello-CIDv0to1 +ipfs files cp /ipfs/${DIR_CID} /t0114/testdirlisting +ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/hello-CIDv1_TOO_LONG ROOT=`ipfs files stat /t0114/ --hash` diff --git a/fixtures/t0114/README.md b/fixtures/t0114/README.md deleted file mode 100644 index 005a7f0c5..000000000 --- a/fixtures/t0114/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# Dataset description/sources - -- fixtures.car - - raw CARv1 - -- QmUKd....ipns-record - - ipns record, encoded with protocol buffer - -- 12D3K....ipns-record - - ipns record, encoded with protocol buffer - -Generated with: - -```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) - -# CIDv0to1 is necessary because raw-leaves are enabled by default during -# "ipfs add" with CIDv1 and disabled with CIDv0 -CID_VAL="hello" -CIDv1=$(echo $CID_VAL | ipfs add --cid-version 1 -Q) -CIDv0=$(echo $CID_VAL | ipfs add --cid-version 0 -Q) -CIDv0to1=$(echo "$CIDv0" | ipfs cid base32) -# sha512 will be over 63char limit, even when represented in Base36 -CIDv1_TOO_LONG=$(echo $CID_VAL | ipfs add --cid-version 1 --hash sha2-512 -Q) - -echo CID_VAL=${CID_VAL} -echo CIDv1=${CIDv1} -echo CIDv0=${CIDv0} -echo CIDv0to1=${CIDv0to1} -echo CIDv1_TOO_LONG=${CIDv1_TOO_LONG} - -# Directory tree crafted to test for edge cases like "/ipfs/ipfs/ipns/bar" -mkdir -p testdirlisting/ipfs/ipns && -echo "hello" > testdirlisting/hello && -echo "text-file-content" > testdirlisting/ipfs/ipns/bar && -mkdir -p testdirlisting/api && -mkdir -p testdirlisting/ipfs && -echo "I am a txt file" > testdirlisting/api/file.txt && -echo "I am a txt file" > testdirlisting/ipfs/file.txt && -DIR_CID=$(ipfs add -Qr --cid-version 1 testdirlisting) - -echo DIR_CID=${DIR_CID} # ./testdirlisting - -ipfs files mkdir /t0114/ -ipfs files cp /ipfs/${CIDv1} /t0114/ -ipfs files cp /ipfs/${CIDv0} /t0114/ -ipfs files cp /ipfs/${CIDv0to1} /t0114/ -ipfs files cp /ipfs/${DIR_CID} /t0114/ -ipfs files cp /ipfs/${CIDv1_TOO_LONG} /t0114/ - -ROOT=`ipfs files stat /t0114/ --hash` - -ipfs dag export ${ROOT} > ./fixtures.car - -# Then the keys - -KEY_NAME=test_key_rsa_$RANDOM -RSA_KEY=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 ${KEY_NAME} | head -n1 | tr -d "\n") -RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0) -RSA_IPNS_IDv1=$(echo "$RSA_KEY" | ipfs cid format -v 1 --mc libp2p-key -b base36) -RSA_IPNS_IDv1_DAGPB=$(echo "$RSA_IPNS_IDv0" | ipfs cid format -v 1 -b base36) - -# publish a record valid for a 100 years -ipfs name publish --key ${KEY_NAME} --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$CIDv1" -ipfs routing get /ipns/${RSA_KEY} > ${RSA_KEY}.ipns-record - -echo RSA_KEY=${RSA_KEY} -echo RSA_IPNS_IDv0=${RSA_IPNS_IDv0} -echo RSA_IPNS_IDv1=${RSA_IPNS_IDv1} -echo RSA_IPNS_IDv1_DAGPB=${RSA_IPNS_IDv1_DAGPB} - -KEY_NAME=test_key_ed25519_$RANDOM -ED25519_KEY=$(ipfs key gen --ipns-base=b58mh --type=ed25519 ${KEY_NAME} | head -n1 | tr -d "\n") -ED25519_IPNS_IDv0=$ED25519_KEY -ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=base36 | grep ${KEY_NAME} | cut -d " " -f1 | tr -d "\n") -ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --mc dag-pb) - -# ed25519 fits under 63 char limit when represented in base36 -IPNS_ED25519_B58MH=$(ipfs key list -l --ipns-base b58mh | grep $KEY_NAME | cut -d" " -f1 | tr -d "\n") -IPNS_ED25519_B36CID=$(ipfs key list -l --ipns-base base36 | grep $KEY_NAME | cut -d" " -f1 | tr -d "\n") - -# publish a record valid for a 100 years -ipfs name publish --key ${KEY_NAME} --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$CIDv1" -ipfs routing get /ipns/${ED25519_KEY} > ${ED25519_KEY}.ipns-record - -echo ED25519_KEY=${ED25519_KEY} -echo ED25519_IPNS_IDv0=${ED25519_IPNS_IDv0} -echo ED25519_IPNS_IDv1=${ED25519_IPNS_IDv1} -echo ED25519_IPNS_IDv1_DAGPB=${ED25519_IPNS_IDv1_DAGPB} -echo IPNS_ED25519_B58MH=${IPNS_ED25519_B58MH} -echo IPNS_ED25519_B36CID=${IPNS_ED25519_B36CID} - -# CID_VAL=hello -# CIDv1=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am -# CIDv0=QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN -# CIDv0to1=bafybeiffndsajwhk3lwjewwdxqntmjm4b5wxaaanokonsggenkbw6slwk4 -# CIDv1_TOO_LONG=bafkrgqhhyivzstcz3hhswshfjgy6ertgmnqeleynhwt4dlfsthi4hn7zgh4uvlsb5xncykzapi3ocd4lzogukir6ksdy6wzrnz6ohnv4aglcs -# DIR_CID=bafybeiht6dtwk3les7vqm6ibpvz6qpohidvlshsfyr7l5mpysdw2vmbbhe # ./testdirlisting - -# RSA_KEY=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3 -# RSA_IPNS_IDv0=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3 -# RSA_IPNS_IDv1=k2k4r8m7xvggw5pxxk3abrkwyer625hg01hfyggrai7lk1m63fuihi7w -# RSA_IPNS_IDv1_DAGPB=k2jmtxu61bnhrtj301lw7zizknztocdbeqhxgv76l2q9t36fn9jbzipo - -# ED25519_KEY=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d -# ED25519_IPNS_IDv0=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d -# ED25519_IPNS_IDv1=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam -# ED25519_IPNS_IDv1_DAGPB=k50rm9yjlt0jey4fqg6wafvqprktgbkpgkqdg27tpqje6iimzxewnhvtin9hhq -# IPNS_ED25519_B58MH=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d -# IPNS_ED25519_B36CID=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam -``` diff --git a/fixtures/t0114/fixtures.car b/fixtures/t0114/fixtures.car deleted file mode 100644 index bc7b913dfa27573c76673744a7d15df6a885e891..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1518 zcmb`GeQXnD9LKqJF0;ypXM$%)qznuxqXXLO6<<(B>E0+~lC3KP)VtnuFTJ<6&-Jc% zAZ8emC~AekvSdRu6%$2pDmVyKbW4oUh*Ouak!YMEFO$(kV@4F?-TIe*wK4wxe1E_1 z_w)Tds|P?zQB>G{VOezX9MmN~(GT9Z{qdnmvbArh-#syZWbfg+Tan$T4@h55eY@f; ztAP~c6&blvUi>i{an_)&H@Tn7FI=1Wb${3JnFYlCebrK8&fHYrI5rZ0MrqbM(YnW^ zu8yz}42300@JCyjAlohnjRv+pl3BNTUDR0L)Y!N&qJ$g5d^FUGRiVJS1nEFs(N|8K zs2TgAQmW1m&iixxn*|^Km5d$7zuvuP;7Y?EIS2X>MKVGP@G%3jUZ240nhyu8mkuO# zz$Y@g0%^sYFmRF9aIZ{}X*MmUf$Y}^Qo<_GA;h^J>9~9C_)FH>jS%Uy6m6hZq5P>0cx{A{x167X4IXPgm9G=!hNcl5z z%n(d6!TXdLjfVQ>ldKqnmUWv@q6GFfA%g-u!^kuw<2on! zL_H34oz5g>Rf_#$dF}$EKoWDMP0zHBACLO-}0A%ME6Wp7|2ub%9_vC zUORPPXk=Gza3*{G?e`WvFk6JZhEoYz)vX->2DGF^@Ki!GiDW|Ic-o4|LB>c0M8A|U zAgy~fiJ~}wz2-oNnG5tU7n~W9Hr?-NQS^b33-9l?*R}IyIwW^X%ccU0^X$ zvx}5mq{|YyY_)UWEX<-I{(~j7t^mm0H@&Is{G{{mu_pNH>0R@m?J@7lwGC|;xu>Q5 zokxEewE@Wx3)vAmZ9YW>cC%L0g@>Q_W*sNTZUpY|gtsF3{I*8<`0M+oyE~6==;=-O cqYjEpVW>TqDCNBhGOEXh;)yA;3S`y!570JmG5`Po diff --git a/tests/subdomain_gateway_ipns_test.go b/tests/subdomain_gateway_ipns_test.go index 8669a86f3..e3c82d89c 100644 --- a/tests/subdomain_gateway_ipns_test.go +++ b/tests/subdomain_gateway_ipns_test.go @@ -21,8 +21,7 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { ed25519Fixture := ipns.MustOpenIPNSRecordWithKey("subdomain_gateway/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record") car := car.MustOpenUnixfsCar("subdomain_gateway/fixtures.car") - helloCID := "bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am" - payload := string(car.MustGetRawData(helloCID)) + payload := string(car.MustGetRawData("hello-CIDv1")) // We're going to run the same test against multiple gateways (localhost, and a subdomain gateway) gatewayURLs := []string{ From cbf2bd228d102fd2ae987762b239478f39d8891d Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 17:36:28 +0200 Subject: [PATCH 08/24] t0115: clear --- fixtures/{t0115 => dir_listing}/README.md | 9 ++-- fixtures/{t0115 => dir_listing}/dnslink.yml | 0 fixtures/{t0115 => dir_listing}/fixtures.car | Bin tests/dnslink_gateway_test.go | 51 ++----------------- tests/path_gateway_unixfs_test.go | 36 +------------ tests/subdomain_gateway_ipfs_test.go | 37 +------------- 6 files changed, 10 insertions(+), 123 deletions(-) rename fixtures/{t0115 => dir_listing}/README.md (90%) rename fixtures/{t0115 => dir_listing}/dnslink.yml (100%) rename fixtures/{t0115 => dir_listing}/fixtures.car (100%) diff --git a/fixtures/t0115/README.md b/fixtures/dir_listing/README.md similarity index 90% rename from fixtures/t0115/README.md rename to fixtures/dir_listing/README.md index 937438bcd..5dc035540 100644 --- a/fixtures/t0115/README.md +++ b/fixtures/dir_listing/README.md @@ -1,9 +1,10 @@ -# Dataset description/sources +# Directory Listing Fixtures -- fixtures.car - - raw CARv1 +## Recipes -generated with: +### [fixtures.car](./fixtures.car) + +Raw CARv1, generated with: ```sh # using ipfs version 0.18.1 diff --git a/fixtures/t0115/dnslink.yml b/fixtures/dir_listing/dnslink.yml similarity index 100% rename from fixtures/t0115/dnslink.yml rename to fixtures/dir_listing/dnslink.yml diff --git a/fixtures/t0115/fixtures.car b/fixtures/dir_listing/fixtures.car similarity index 100% rename from fixtures/t0115/fixtures.car rename to fixtures/dir_listing/fixtures.car diff --git a/tests/dnslink_gateway_test.go b/tests/dnslink_gateway_test.go index 4cd0e26e7..c6eee1d99 100644 --- a/tests/dnslink_gateway_test.go +++ b/tests/dnslink_gateway_test.go @@ -134,13 +134,11 @@ func TestDNSLinkGateway(t *testing.T) { RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.DNSLinkGateway) } -// TODO(laurent): this was in t0115_gateway_dir_listing_test.go - func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0115/fixtures.car") + fixture := car.MustOpenUnixfsCar("dir_listing/fixtures.car") file := fixture.MustGetNode("ą", "ę", "file-źł.txt") - dnsLinks := dnslink.MustOpenDNSLink("t0115/dnslink.yml") + dnsLinks := dnslink.MustOpenDNSLink("dir_listing/dnslink.yml") dnsLink := dnsLinks.MustGet("website") gatewayURL := SubdomainGatewayURL @@ -154,26 +152,7 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { dnsLinkHostname := tmpl.Fmt("{{dnslink}}.{{host}}", dnsLink, u.Host) - // ## ============================================================================ - // ## Test dir listing on DNSLink gateway (eg. example.com) - // ## ============================================================================ tests = append(tests, SugarTests{ - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // test_kill_ipfs_daemon - // DNSLINK_HOSTNAME="website.example.com" - // export IPFS_NS_MAP="$DNSLINK_HOSTNAME:/ipfs/$DIR_CID" - // test_launch_ipfs_daemon - - // # Note that: - // # - this type of gateway is also tested in gateway_test.go#TestIPNSHostnameBacklinks - // # (go tests and sharness tests should be kept in sync) - // # - we skip DNS lookup by running curl with --resolve $DNSLINK_HOSTNAME:127.0.0.1 - - // test_expect_success "dnslink gw: backlink on root CID should be hidden" ' - // curl -v -sD - --resolve $DNSLINK_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DNSLINK_HOSTNAME:$GWAY_PORT/ > list_response && - // test_should_contain "Index of" list_response && - // test_should_not_contain ".." list_response - // ' { Name: "Backlink on root CID should be hidden (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -186,11 +165,6 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { ), ), }, - // test_expect_success "dnslink gw: redirect dir listing to URL with trailing slash" ' - // curl -sD - --resolve $DNSLINK_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DNSLINK_HOSTNAME:$GWAY_PORT/ą/ę > list_response && - // test_should_contain "HTTP/1.1 301 Moved Permanently" list_response && - // test_should_contain "Location: /%c4%85/%c4%99/" list_response - // ' { Name: "Redirect dir listing to URL with trailing slash", Request: Request(). @@ -201,25 +175,6 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { Header("Location").Equals(`/%c4%85/%c4%99/`), ), }, - // test_expect_success "dnslink gw: Etag should be present" ' - // curl -sD - --resolve $DNSLINK_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DNSLINK_HOSTNAME:$GWAY_PORT/ą/ę/ > list_response && - // test_should_contain "Index of" list_response && - // test_should_contain "Etag: \"DirIndex-" list_response - // ' - // test_expect_success "dnslink gw: backlink on subdirectory should point at parent directory" ' - // test_should_contain ".." list_response - // ' - // test_expect_success "dnslink gw: breadcrumbs should point at content root mounted at dnslink origin" ' - // test_should_contain "/ipns/website.example.com/ą/ę" list_response - // ' - // test_expect_success "dnslink gw: name column should be a link to content root mounted at dnslink origin" ' - // test_should_contain "file-źł.txt" list_response - // ' - // # DNSLink websites don't have public gateway mounted by default - // # See: https://github.com/ipfs/dir-index-html/issues/42 - // test_expect_success "dnslink gw: hash column should be a CID link to cid.ipfs.tech" ' - // test_should_contain "" list_response - // ' { Name: "Regular dir listing (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -234,7 +189,7 @@ func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { - name column should be a link to content root mounted at dnslink origin - hash column should be a CID link to cid.ipfs.tech DNSLink websites don't have public gateway mounted by default - See: https://github.com/ipfs/dir-index-html/issues/42 (TODO: class and other attrs are kubo-specific) + See: https://github.com/ipfs/dir-index-html/issues/42 (TODO: class and other attrs are kubo-specific) `, And( Contains("Index of"), diff --git a/tests/path_gateway_unixfs_test.go b/tests/path_gateway_unixfs_test.go index ed6c25790..2cea59cfc 100644 --- a/tests/path_gateway_unixfs_test.go +++ b/tests/path_gateway_unixfs_test.go @@ -12,24 +12,12 @@ import ( . "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this was in t0115_gateway_dir_listing_test.go - func TestUnixFSDirectoryListing(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0115/fixtures.car") + fixture := car.MustOpenUnixfsCar("dir_listing/fixtures.car") root := fixture.MustGetNode() file := fixture.MustGetNode("ą", "ę", "file-źł.txt") tests := SugarTests{ - // ## ============================================================================ - // ## Test dir listing on path gateway (eg. 127.0.0.1:8080/ipfs/) - // ## ============================================================================ - // test_expect_success "path gw: backlink on root CID should be hidden" ' - // - // curl -sD - http://127.0.0.1:$GWAY_PORT/ipfs/${DIR_CID}/ > list_response && - // test_should_contain "Index of" list_response && - // test_should_not_contain ".." list_response, - // - // ' { Name: "path gw: backlink on root CID should be hidden (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -41,11 +29,6 @@ func TestUnixFSDirectoryListing(t *testing.T) { Not(Contains(`..`, root.Cid())), )), }, - // test_expect_success "path gw: redirect dir listing to URL with trailing slash" ' - // curl -sD - http://127.0.0.1:$GWAY_PORT/ipfs/${DIR_CID}/ą/ę > list_response && - // test_should_contain "HTTP/1.1 301 Moved Permanently" list_response && - // test_should_contain "Location: /ipfs/${DIR_CID}/%c4%85/%c4%99/" list_response - // ' { Name: "path gw: redirect dir listing to URL with trailing slash", Request: Request(). @@ -56,23 +39,6 @@ func TestUnixFSDirectoryListing(t *testing.T) { Header("Location", `/ipfs/{{cid}}/%c4%85/%c4%99/`, root.Cid()), ), }, - // test_expect_success "path gw: Etag should be present" ' - // curl -sD - http://127.0.0.1:$GWAY_PORT/ipfs/${DIR_CID}/ą/ę/ > list_response && - // test_should_contain "Index of" list_response && - // test_should_contain "Etag: \"DirIndex-" list_response - // ' - // test_expect_success "path gw: breadcrumbs should point at /ipfs namespace mounted at Origin root" ' - // test_should_contain "/ipfs/$DIR_CID/ą/ę" list_response - // ' - // test_expect_success "path gw: backlink on subdirectory should point at parent directory" ' - // test_should_contain ".." list_response - // ' - // test_expect_success "path gw: name column should be a link to its content path" ' - // test_should_contain "file-źł.txt" list_response - // ' - // test_expect_success "path gw: hash column should be a CID link with filename param" ' - // test_should_contain "" list_response - // ' { Name: "path gw: dir listing HTML response (TODO: cleanup Kubo-specifics)", Request: Request(). diff --git a/tests/subdomain_gateway_ipfs_test.go b/tests/subdomain_gateway_ipfs_test.go index ff1ee0992..216e2e33d 100644 --- a/tests/subdomain_gateway_ipfs_test.go +++ b/tests/subdomain_gateway_ipfs_test.go @@ -14,7 +14,7 @@ import ( // TODO(laurent): this was in t0115_gateway_dir_listing_test.go func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0115/fixtures.car") + fixture := car.MustOpenUnixfsCar("dir_listing/fixtures.car") root := fixture.MustGetNode() file := fixture.MustGetNode("ą", "ę", "file-źł.txt") @@ -32,18 +32,7 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { t.Fatal(err) } - // ## ============================================================================ - // ## Test dir listing on subdomain gateway (eg. .ipfs.localhost:8080) - // ## ============================================================================ tests = append(tests, SugarTests{ - // DIR_HOSTNAME="${DIR_CID}.ipfs.localhost" - // # note: we skip DNS lookup by running curl with --resolve $DIR_HOSTNAME:127.0.0.1 - - // test_expect_success "subdomain gw: backlink on root CID should be hidden" ' - // curl -sD - --resolve $DIR_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DIR_HOSTNAME:$GWAY_PORT/ > list_response && - // test_should_contain "Index of" list_response && - // test_should_not_contain ".." list_response - // ' { Name: "backlink on root CID should be hidden (TODO: cleanup Kubo-specifics)", Request: Request(). @@ -60,11 +49,6 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { Not(Contains(`..`)), )), }, - // test_expect_success "subdomain gw: redirect dir listing to URL with trailing slash" ' - // curl -sD - --resolve $DIR_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DIR_HOSTNAME:$GWAY_PORT/ą/ę > list_response && - // test_should_contain "HTTP/1.1 301 Moved Permanently" list_response && - // test_should_contain "Location: /%c4%85/%c4%99/" list_response - // ' { Name: "redirect dir listing to URL with trailing slash", Request: Request(). @@ -80,23 +64,6 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { Header("Location").Equals(`/%c4%85/%c4%99/`), ), }, - // test_expect_success "subdomain gw: Etag should be present" ' - // curl -sD - --resolve $DIR_HOSTNAME:$GWAY_PORT:127.0.0.1 http://$DIR_HOSTNAME:$GWAY_PORT/ą/ę/ > list_response && - // test_should_contain "Index of" list_response && - // test_should_contain "Etag: \"DirIndex-" list_response - // ' - // test_expect_success "subdomain gw: backlink on subdirectory should point at parent directory" ' - // test_should_contain ".." list_response - // ' - // test_expect_success "subdomain gw: breadcrumbs should leverage path-based router mounted on the parent domain" ' - // test_should_contain "/ipfs/$DIR_CID/ą/ę" list_response - // ' - // test_expect_success "subdomain gw: name column should be a link to content root mounted at subdomain origin" ' - // test_should_contain "file-źł.txt" list_response - // ' - // test_expect_success "subdomain gw: hash column should be a CID link to path router with filename param" ' - // test_should_contain "" list_response - // ' { Name: "Regular dir listing HTML (TODO: cleanup Kubo-specifics)", Request: Request().URL( @@ -136,8 +103,6 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { }...) } - // Body expect to find substring '', - RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGatewayIPFS) } From bfaca864a04a24c8bd51f91475d582e7666e93f2 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 17:45:04 +0200 Subject: [PATCH 09/24] t0122: clear --- fixtures/path_gateway_tar/README.md | 40 ++++++++ .../{t0122 => path_gateway_tar}/fixtures.car | Bin .../inside-root.car | Bin .../outside-root.car | Bin tests/path_gateway_tar_test.go | 87 +----------------- 5 files changed, 44 insertions(+), 83 deletions(-) create mode 100644 fixtures/path_gateway_tar/README.md rename fixtures/{t0122 => path_gateway_tar}/fixtures.car (100%) rename fixtures/{t0122 => path_gateway_tar}/inside-root.car (100%) rename fixtures/{t0122 => path_gateway_tar}/outside-root.car (100%) diff --git a/fixtures/path_gateway_tar/README.md b/fixtures/path_gateway_tar/README.md new file mode 100644 index 000000000..ccf287b75 --- /dev/null +++ b/fixtures/path_gateway_tar/README.md @@ -0,0 +1,40 @@ +# Path Gateway Tar Fixtures + +## Recipes + +### [inside-roots.car](./inside-root.car) and [outside-roots.car](./outside-root.car) + +Legacy fixtures from Kubo Sharness. + +See the [PR](https://github.com/ipfs/kubo/pull/9029) that introduced them for more details + +### [fixtures.car](./fixtures.car) + +Generated with: + +```sh +# 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/fixtures/t0122/fixtures.car b/fixtures/path_gateway_tar/fixtures.car similarity index 100% rename from fixtures/t0122/fixtures.car rename to fixtures/path_gateway_tar/fixtures.car diff --git a/fixtures/t0122/inside-root.car b/fixtures/path_gateway_tar/inside-root.car similarity index 100% rename from fixtures/t0122/inside-root.car rename to fixtures/path_gateway_tar/inside-root.car diff --git a/fixtures/t0122/outside-root.car b/fixtures/path_gateway_tar/outside-root.car similarity index 100% rename from fixtures/t0122/outside-root.car rename to fixtures/path_gateway_tar/outside-root.car diff --git a/tests/path_gateway_tar_test.go b/tests/path_gateway_tar_test.go index 3425343e2..df7145bb0 100644 --- a/tests/path_gateway_tar_test.go +++ b/tests/path_gateway_tar_test.go @@ -10,57 +10,18 @@ import ( "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this was t0122_gateway_tar_test.go - -// "Test HTTP Gateway TAR (application/x-tar) Support" func TestTar(t *testing.T) { - /** - test_expect_success "Add CARs with relative paths to test with" ' - ipfs dag import ../t0122-gateway-tar/outside-root.car > import_output && - test_should_contain $OUTSIDE_ROOT_CID import_output && - ipfs dag import ../t0122-gateway-tar/inside-root.car > import_output && - test_should_contain $INSIDE_ROOT_CID import_output - ' - */ - fixtureOutside := car.MustOpenUnixfsCar("t0122/outside-root.car") - fixtureInside := car.MustOpenUnixfsCar("t0122/inside-root.car") + fixtureOutside := car.MustOpenUnixfsCar("path_gateway_tar/outside-root.car") + fixtureInside := car.MustOpenUnixfsCar("path_gateway_tar/inside-root.car") outsideRootCID := fixtureOutside.MustGetCid() insideRootCID := fixtureInside.MustGetCid() - // OUTSIDE_ROOT_CID="bafybeicaj7kvxpcv4neaqzwhrqqmdstu4dhrwfpknrgebq6nzcecfucvyu" - // INSIDE_ROOT_CID="bafybeibfevfxlvxp5vxobr5oapczpf7resxnleb7tkqmdorc4gl5cdva3y" - // - // test_expect_success "Add the test directory" ' - // ipfs dag import ../t0122-gateway-tar/fixtures.car - // ' - // DIR_CID=bafybeig6ka5mlwkl4subqhaiatalkcleo4jgnr3hqwvpmsqfca27cijp3i # ./rootDir - // FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt - // FILE_SIZE=34 - - fixture := car.MustOpenUnixfsCar("t0122/fixtures.car") + fixture := car.MustOpenUnixfsCar("path_gateway_tar/fixtures.car") dirCID := fixture.MustGetCid() // root dir fileCID := fixture.MustGetCid("ą", "ę", "file-źł.txt") tests := SugarTests{ - /** - test_expect_success "GET TAR with format=tar and extract" ' - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=tar" | tar -x - ' - test_expect_success "GET TAR with format=tar has expected Content-Type" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=tar" > curl_output_filename 2>&1 && - test_should_contain "Content-Disposition: attachment;" curl_output_filename && - test_should_contain "Etag: W/\"$FILE_CID.x-tar" curl_output_filename && - test_should_contain "Content-Type: application/x-tar" curl_output_filename - ' - test_expect_success "GET TAR has expected root file" ' - rm -rf outputDir && mkdir outputDir && - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=tar" | tar -x -C outputDir && - test -f "outputDir/$FILE_CID" && - echo "I am a txt file on path with utf8" > expected && - test_cmp expected outputDir/$FILE_CID - ' - */ { Name: "GET TAR with format=tar and extract", Request: Request(). @@ -80,17 +41,6 @@ func TestTar(t *testing.T) { ), ), }, - /** - test_expect_success "GET TAR with 'Accept: application/x-tar' and extract" ' - curl -H "Accept: application/x-tar" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" | tar -x - ' - test_expect_success "GET TAR with 'Accept: application/x-tar' has expected Content-Type" ' - curl -sD - -H "Accept: application/x-tar" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output_filename 2>&1 && - test_should_contain "Content-Disposition: attachment;" curl_output_filename && - test_should_contain "Etag: W/\"$FILE_CID.x-tar" curl_output_filename && - test_should_contain "Content-Type: application/x-tar" curl_output_filename - ' - */ { Name: "GET TAR with 'Accept: application/x-tar' and extract", Request: Request(). @@ -106,15 +56,6 @@ func TestTar(t *testing.T) { IsTarFile(), ), }, - /** - test_expect_success "GET TAR has expected root directory" ' - rm -rf outputDir && mkdir outputDir && - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=tar" | tar -x -C outputDir && - test -d "outputDir/$DIR_CID" && - echo "I am a txt file on path with utf8" > expected && - test_cmp expected outputDir/$DIR_CID/ą/ę/file-źł.txt - ' - */ { Name: "GET TAR has expected root directory", Request: Request(). @@ -130,12 +71,6 @@ func TestTar(t *testing.T) { ), ), }, - /** - test_expect_success "GET TAR with explicit ?filename= succeeds with modified Content-Disposition header" " - curl -fo actual -D actual_headers 'http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?filename=testтест.tar&format=tar' && - grep -F 'Content-Disposition: attachment; filename=\"test____.tar\"; filename*=UTF-8'\'\''test%D1%82%D0%B5%D1%81%D1%82.tar' actual_headers - " - */ { Name: "GET TAR with explicit ?filename= succeeds with modified Content-Disposition header", Request: Request(). @@ -145,16 +80,9 @@ func TestTar(t *testing.T) { Response: Expect(). Status(200). Headers( - // Note: golang's compiler assumes the "weird" string is a format string, we use `"{{x}}"` to move it out of the way. - Header("Content-Disposition").Contains("{{x}}", `attachment; filename="test____.tar"; filename*=UTF-8''test%D1%82%D0%B5%D1%81%D1%82.tar`), + Header("Content-Disposition").Contains(`attachment; filename="test____.tar"; filename*=UTF-8''test%D1%82%D0%B5%D1%81%D1%82.tar`), ), }, - /** - test_expect_success "GET TAR with relative paths outside root fails" ' - curl -o - "http://127.0.0.1:$GWAY_PORT/ipfs/$OUTSIDE_ROOT_CID?format=tar" > curl_output_filename && - test_should_contain "relative UnixFS paths outside the root are now allowed" curl_output_filename - ' - */ { Name: "GET TAR with relative paths outside root fails", Request: Request(). @@ -165,13 +93,6 @@ func TestTar(t *testing.T) { Contains("relative UnixFS paths outside the root are now allowed"), ), }, - /** - test_expect_success "GET TAR with relative paths inside root works" ' - rm -rf outputDir && mkdir outputDir && - curl "http://127.0.0.1:$GWAY_PORT/ipfs/$INSIDE_ROOT_CID?format=tar" | tar -x -C outputDir && - test -f outputDir/$INSIDE_ROOT_CID/foobar/file - ' - */ { Name: "GET TAR with relative paths inside root works", Request: Request(). From 8621a52f2cb5f82d6dd6cc306ca443705fee1069 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 27 Jun 2023 17:54:56 +0200 Subject: [PATCH 10/24] t0123: clear (a) --- fixtures/path_gateway_dag/README.md | 66 ++++++++++++++++++ .../dag-cbor-traversal.car | Bin .../dag-json-traversal.car | Bin .../{t0123 => path_gateway_dag}/dag-pb.car | Bin .../{t0123 => path_gateway_dag}/dag-pb.json | 0 .../gateway-json-cbor.car} | Bin ...xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record | Bin ...e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record | Bin .../plain-that-can-be-dag.cbor.car | Bin .../plain-that-can-be-dag.json.car | Bin .../plain.cbor.car | Bin .../plain.json.car | Bin tests/path_gateway_dag_test.go | 20 +++--- 13 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 fixtures/path_gateway_dag/README.md rename fixtures/{t0123 => path_gateway_dag}/dag-cbor-traversal.car (100%) rename fixtures/{t0123 => path_gateway_dag}/dag-json-traversal.car (100%) rename fixtures/{t0123 => path_gateway_dag}/dag-pb.car (100%) rename fixtures/{t0123 => path_gateway_dag}/dag-pb.json (100%) rename fixtures/{t0123-gateway-json-cbor.car => path_gateway_dag/gateway-json-cbor.car} (100%) rename fixtures/{t0123 => path_gateway_dag}/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record (100%) rename fixtures/{t0123 => path_gateway_dag}/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record (100%) rename fixtures/{t0123 => path_gateway_dag}/plain-that-can-be-dag.cbor.car (100%) rename fixtures/{t0123 => path_gateway_dag}/plain-that-can-be-dag.json.car (100%) rename fixtures/{t0123 => path_gateway_dag}/plain.cbor.car (100%) rename fixtures/{t0123 => path_gateway_dag}/plain.json.car (100%) diff --git a/fixtures/path_gateway_dag/README.md b/fixtures/path_gateway_dag/README.md new file mode 100644 index 000000000..810ff6bc3 --- /dev/null +++ b/fixtures/path_gateway_dag/README.md @@ -0,0 +1,66 @@ +# Path Gateway Dag Fixtures + +## Recipes + +### Legacy fixtures from Kubo + +- dag-cbor-traversal.car +- dag-json-traversal.car +- dag-pb.car +- dag-pb.json + +### [gateway-json-cbor.car](./gateway-json-cbor.car) and ipns-records + +Generated with: + +```sh +# using 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} > gateway-json-cbor.car + +DAG_CBOR_TRAVERSAL_CID="bafyreibs4utpgbn7uqegmd2goqz4bkyflre2ek2iwv743fhvylwi4zeeim" +DAG_JSON_TRAVERSAL_CID="baguqeeram5ujjqrwheyaty3w5gdsmoz6vittchvhk723jjqxk7hakxkd47xq" +DAG_PB_CID="bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke" + +test_native_dag() { + NAME=$1 + CID=$2 + + IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 ${NAME}_test_key | head -n1 | tr -d "\n") + ipfs name publish --key ${NAME}_test_key --allow-offline --ttl=876600h --lifetime=876600h -Q "/ipfs/${CID}" > name_publish_out + + ipfs routing get /ipns/${IPNS_ID} > ${IPNS_ID}.ipns-record + + echo "IPNS_ID_${NAME}=${IPNS_ID}" +} + +test_native_dag "DAG_JSON" "$DAG_JSON_TRAVERSAL_CID" +test_native_dag "DAG_CBOR" "$DAG_CBOR_TRAVERSAL_CID" + +# DIR_CID=bafybeiafyvqlazbbbtjnn6how5d6h6l6rxbqc4qgpbmteaiskjrffmyy4a # ./rootDir +# FILE_JSON_CID=bafkreibrppizs3g7axs2jdlnjua6vgpmltv7k72l7v7sa6mmht6mne3qqe # ./rootDir/ą/ę/t.json +# FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt +# FILE_SIZE=34 +# IPNS_ID_DAG_JSON=k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2 +# IPNS_ID_DAG_CBOR=k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l +``` diff --git a/fixtures/t0123/dag-cbor-traversal.car b/fixtures/path_gateway_dag/dag-cbor-traversal.car similarity index 100% rename from fixtures/t0123/dag-cbor-traversal.car rename to fixtures/path_gateway_dag/dag-cbor-traversal.car diff --git a/fixtures/t0123/dag-json-traversal.car b/fixtures/path_gateway_dag/dag-json-traversal.car similarity index 100% rename from fixtures/t0123/dag-json-traversal.car rename to fixtures/path_gateway_dag/dag-json-traversal.car diff --git a/fixtures/t0123/dag-pb.car b/fixtures/path_gateway_dag/dag-pb.car similarity index 100% rename from fixtures/t0123/dag-pb.car rename to fixtures/path_gateway_dag/dag-pb.car diff --git a/fixtures/t0123/dag-pb.json b/fixtures/path_gateway_dag/dag-pb.json similarity index 100% rename from fixtures/t0123/dag-pb.json rename to fixtures/path_gateway_dag/dag-pb.json diff --git a/fixtures/t0123-gateway-json-cbor.car b/fixtures/path_gateway_dag/gateway-json-cbor.car similarity index 100% rename from fixtures/t0123-gateway-json-cbor.car rename to fixtures/path_gateway_dag/gateway-json-cbor.car diff --git a/fixtures/t0123/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record b/fixtures/path_gateway_dag/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record similarity index 100% rename from fixtures/t0123/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record rename to fixtures/path_gateway_dag/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record diff --git a/fixtures/t0123/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record b/fixtures/path_gateway_dag/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record similarity index 100% rename from fixtures/t0123/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record rename to fixtures/path_gateway_dag/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record diff --git a/fixtures/t0123/plain-that-can-be-dag.cbor.car b/fixtures/path_gateway_dag/plain-that-can-be-dag.cbor.car similarity index 100% rename from fixtures/t0123/plain-that-can-be-dag.cbor.car rename to fixtures/path_gateway_dag/plain-that-can-be-dag.cbor.car diff --git a/fixtures/t0123/plain-that-can-be-dag.json.car b/fixtures/path_gateway_dag/plain-that-can-be-dag.json.car similarity index 100% rename from fixtures/t0123/plain-that-can-be-dag.json.car rename to fixtures/path_gateway_dag/plain-that-can-be-dag.json.car diff --git a/fixtures/t0123/plain.cbor.car b/fixtures/path_gateway_dag/plain.cbor.car similarity index 100% rename from fixtures/t0123/plain.cbor.car rename to fixtures/path_gateway_dag/plain.cbor.car diff --git a/fixtures/t0123/plain.json.car b/fixtures/path_gateway_dag/plain.json.car similarity index 100% rename from fixtures/t0123/plain.json.car rename to fixtures/path_gateway_dag/plain.json.car diff --git a/tests/path_gateway_dag_test.go b/tests/path_gateway_dag_test.go index 8bccaf180..e956ed2bd 100644 --- a/tests/path_gateway_dag_test.go +++ b/tests/path_gateway_dag_test.go @@ -14,7 +14,7 @@ import ( // TODO(laurent): this was t0123_gateway_json_cbor_test func TestGatewayJsonCbor(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0123-gateway-json-cbor.car") + fixture := car.MustOpenUnixfsCar("path_gateway_dag/gateway-json-cbor.car") fileJSON := fixture.MustGetNode("ą", "ę", "t.json") fileJSONCID := fileJSON.Cid() @@ -71,7 +71,7 @@ func TestGatewayJsonCbor(t *testing.T) { // ## Reading UnixFS (data encoded with dag-pb codec) as DAG-CBOR and DAG-JSON // ## (returns representation defined in https://ipld.io/specs/codecs/dag-pb/spec/#logical-format) func TestDAgPbConversion(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0123-gateway-json-cbor.car") + fixture := car.MustOpenUnixfsCar("path_gateway_dag/gateway-json-cbor.car") dir := fixture.MustGetRoot() file := fixture.MustGetNode("ą", "ę", "file-źł.txt") @@ -275,8 +275,8 @@ func TestPlainCodec(t *testing.T) { } for _, row := range table { - plain := car.MustOpenUnixfsCar(Fmt("t0123/plain.{{format}}.car", row.Format)).MustGetRoot() - plainOrDag := car.MustOpenUnixfsCar(Fmt("t0123/plain-that-can-be-dag.{{format}}.car", row.Format)).MustGetRoot() + plain := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain.{{format}}.car", row.Format)).MustGetRoot() + plainOrDag := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain-that-can-be-dag.{{format}}.car", row.Format)).MustGetRoot() formatted := plainOrDag.Formatted("dag-" + row.Format) plainCID := plain.Cid() @@ -414,8 +414,8 @@ func TestPlainCodec(t *testing.T) { // ## Pathing, traversal over DAG-JSON and DAG-CBOR func TestPathing(t *testing.T) { - dagJSONTraversal := car.MustOpenUnixfsCar("t0123/dag-json-traversal.car").MustGetRoot() - dagCBORTraversal := car.MustOpenUnixfsCar("t0123/dag-cbor-traversal.car").MustGetRoot() + dagJSONTraversal := car.MustOpenUnixfsCar("path_gateway_dag/dag-json-traversal.car").MustGetRoot() + dagCBORTraversal := car.MustOpenUnixfsCar("path_gateway_dag/dag-cbor-traversal.car").MustGetRoot() dagJSONTraversalCID := dagJSONTraversal.Cid() dagCBORTraversalCID := dagCBORTraversal.Cid() @@ -516,7 +516,7 @@ func TestNativeDag(t *testing.T) { } for _, row := range table { - dagTraversal := car.MustOpenUnixfsCar(Fmt("t0123/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() + dagTraversal := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() dagTraversalCID := dagTraversal.Cid() formatted := dagTraversal.Formatted("dag-" + row.Format) @@ -825,8 +825,8 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { ipnsIdDagJSON := "k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2" ipnsIdDagCBOR := "k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l" - ipnsDagJSON := ipns.MustOpenIPNSRecordWithKey(Fmt("t0123/{{id}}.ipns-record", ipnsIdDagJSON)) - ipnsDagCBOR := ipns.MustOpenIPNSRecordWithKey(Fmt("t0123/{{id}}.ipns-record", ipnsIdDagCBOR)) + ipnsDagJSON := ipns.MustOpenIPNSRecordWithKey(Fmt("path_gateway_dag/{{id}}.ipns-record", ipnsIdDagJSON)) + ipnsDagCBOR := ipns.MustOpenIPNSRecordWithKey(Fmt("path_gateway_dag/{{id}}.ipns-record", ipnsIdDagCBOR)) table := []struct { Name string @@ -840,7 +840,7 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { tests := SugarTests{} for _, row := range table { - plain := car.MustOpenUnixfsCar(Fmt("t0123/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() + plain := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/dag-{{format}}-traversal.car", row.Format)).MustGetRoot() plainCID := plain.Cid() // # IPNS behavior (should be same as immutable /ipfs, but with different caching headers) From d4e294ce00c4b596c6e618b8c9bc001ad7ad4059 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 09:41:24 +0200 Subject: [PATCH 11/24] t0123: clear (b) --- tests/path_gateway_dag_test.go | 292 --------------------------------- 1 file changed, 292 deletions(-) diff --git a/tests/path_gateway_dag_test.go b/tests/path_gateway_dag_test.go index e956ed2bd..f7f89a60e 100644 --- a/tests/path_gateway_dag_test.go +++ b/tests/path_gateway_dag_test.go @@ -95,16 +95,6 @@ func TestDAgPbConversion(t *testing.T) { formatedDir := dir.Formatted("dag-" + row.Format) tests := SugarTests{ - /** - test_expect_success "GET UnixFS file as $name with format=dag-$format converts to the expected Content-Type" ' - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 && - ipfs dag get --output-codec dag-$format $FILE_CID > ipfs_dag_get_output 2>&1 && - test_cmp ipfs_dag_get_output curl_output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" headers && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${FILE_CID}.${format}\"" headers && - test_should_not_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET UnixFS file as {{name}} with format=dag-{{format}} converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -123,16 +113,6 @@ func TestDAgPbConversion(t *testing.T) { formatedFile, ), }, - /** - test_expect_success "GET UnixFS directory as $name with format=dag-$format converts to the expected Content-Type" ' - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output 2>&1 && - ipfs dag get --output-codec dag-$format $DIR_CID > ipfs_dag_get_output 2>&1 && - test_cmp ipfs_dag_get_output curl_output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" headers && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${DIR_CID}.${format}\"" headers && - test_should_not_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET UnixFS directory as {{name}} with format=dag-{{format}} converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -150,14 +130,6 @@ func TestDAgPbConversion(t *testing.T) { formatedDir, ), }, - /** - test_expect_success "GET UnixFS as $name with 'Accept: application/vnd.ipld.dag-$format' converts to the expected Content-Type" ' - curl -sD - -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${FILE_CID}.${format}\"" curl_output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output && - test_should_not_contain "Content-Type: application/$format" curl_output - ' - */ { Name: Fmt("GET UnixFS as {{name}} with 'Accept: application/vnd.ipld.dag-{{format}}' converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -176,12 +148,6 @@ func TestDAgPbConversion(t *testing.T) { Not().Contains("application/{{format}}", row.Format), ), }, - /** - test_expect_success "GET UnixFS as $name with 'Accept: foo, application/vnd.ipld.dag-$format,bar' converts to the expected Content-Type" ' - curl -sD - -H "Accept: foo, application/vnd.ipld.dag-$format,text/plain" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output - ' - */ { Name: Fmt("GET UnixFS as {{name}} with 'Accept: foo, application/vnd.ipld.dag-{{format}},bar' converts to the expected Content-Type", row.Name, row.Format), Request: Request(). @@ -196,16 +162,6 @@ func TestDAgPbConversion(t *testing.T) { Equals("application/vnd.ipld.dag-{{format}}", row.Format), ), }, - /** - test_expect_success "GET UnixFS with format=$format (not dag-$format) is no-op (no conversion)" ' - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=$format" > curl_output 2>&1 && - ipfs cat $FILE_CID > cat_output && - test_cmp cat_output curl_output && - test_should_contain "Content-Type: text/plain" headers && - test_should_not_contain "Content-Type: application/$format" headers && - test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" headers - ' - */ { Name: Fmt("GET UnixFS with format={{format}} (not dag-{{format}}) is no-op (no conversion)", row.Format), Request: Request(). @@ -224,16 +180,6 @@ func TestDAgPbConversion(t *testing.T) { fileData, ), }, - /** - test_expect_success "GET UnixFS with 'Accept: application/$format' (not dag-$format) is no-op (no conversion)" ' - curl -sD headers -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && - ipfs cat $FILE_CID > cat_output && - test_cmp cat_output curl_output && - test_should_contain "Content-Type: text/plain" headers && - test_should_not_contain "Content-Type: application/$format" headers && - test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" headers - ' - */ { Name: Fmt("GET UnixFS with 'Accept: application/{{format}}' (not dag-{{format}}) is no-op (no conversion)", row.Format), Request: Request(). @@ -283,17 +229,6 @@ func TestPlainCodec(t *testing.T) { plainOrDagCID := plainOrDag.Cid() tests := SugarTests{ - /** - # no explicit format, just codec in CID - test_expect_success "GET $name without Accept or format= has expected $format Content-Type and body as-is" ' - CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output 2>&1 && - ipfs block get $CID > ipfs_block_output 2>&1 && - test_cmp ipfs_block_output curl_output && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt(`GET {{name}} without Accept or format= has expected "{{format}}" Content-Type and body as-is`, row.Name, row.Format), Hint: ` @@ -312,17 +247,6 @@ func TestPlainCodec(t *testing.T) { plain.RawData(), ), }, - /** - # explicit format still gives correct output, just codec in CID - test_expect_success "GET $name with ?format= has expected $format Content-Type and body as-is" ' - CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=$format" > curl_output 2>&1 && - ipfs block get $CID > ipfs_block_output 2>&1 && - test_cmp ipfs_block_output curl_output && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET {{name}} with ?format= has expected {{format}} Content-Type and body as-is", row.Name, row.Format), Hint: ` @@ -342,17 +266,6 @@ func TestPlainCodec(t *testing.T) { plain.RawData(), ), }, - /** - # explicit format still gives correct output, just codec in CID - test_expect_success "GET $name with Accept has expected $format Content-Type and body as-is" ' - CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output 2>&1 && - ipfs block get $CID > ipfs_block_output 2>&1 && - test_cmp ipfs_block_output curl_output && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/$format" headers - ' - */ { Name: Fmt("GET {{name}} with Accept has expected {{format}} Content-Type and body as-is", row.Name, row.Format), Hint: ` @@ -372,20 +285,6 @@ func TestPlainCodec(t *testing.T) { plain.RawData(), ), }, - /** - # explicit dag-* format passed, attempt to parse as dag* variant - ## Note: this works only for simple JSON that can be upgraded to DAG-JSON. - test_expect_success "GET $name with format=dag-$format interprets $format as dag-* variant and produces expected Content-Type and body" ' - CID=$(echo "{ \"test\": \"plain-json-that-can-also-be-dag-json\" }" | ipfs dag put --input-codec json --store-codec $format) && - curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" > curl_output_param 2>&1 && - ipfs dag get --output-codec dag-$format $CID > ipfs_dag_get_output 2>&1 && - test_cmp ipfs_dag_get_output curl_output_param && - test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" headers && - curl -s -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output_accept 2>&1 && - test_cmp curl_output_param curl_output_accept - ' - */ { Name: Fmt("GET {{name}} with format=dag-{{format}} interprets {{format}} as dag-* variant and produces expected Content-Type and body", row.Name, row.Format), Hint: ` @@ -421,13 +320,6 @@ func TestPathing(t *testing.T) { dagCBORTraversalCID := dagCBORTraversal.Cid() tests := SugarTests{ - /** - test_expect_success "GET DAG-JSON traversal returns 501 if there is path remainder" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID/foo?format=dag-json" > curl_output 2>&1 && - test_should_contain "501 Not Implemented" curl_output && - test_should_contain "reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented" curl_output - ' - */ { Name: "GET DAG-JSON traversal returns 501 if there is path remainder", Request: Request(). @@ -437,14 +329,6 @@ func TestPathing(t *testing.T) { Status(501). Body(Contains("reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented")), }, - /** - test_expect_success "GET DAG-JSON traverses multiple links" ' - curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID/foo/link/bar?format=dag-json" > curl_output 2>&1 && - jq --sort-keys . curl_output > actual && - echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected && - test_cmp expected actual - ' - */ { Name: "GET DAG-JSON traverses multiple links", Request: Request(). @@ -458,13 +342,6 @@ func TestPathing(t *testing.T) { IsJSONEqual([]byte(`{"hello": "this is not a link"}`)), ), }, - /** - test_expect_success "GET DAG-CBOR traversal returns 501 if there is path remainder" ' - curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo?format=dag-cbor" > curl_output 2>&1 && - test_should_contain "501 Not Implemented" curl_output && - test_should_contain "reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented" curl_output - ' - */ { Name: "GET DAG-CBOR traversal returns 501 if there is path remainder", Request: Request(). @@ -474,14 +351,6 @@ func TestPathing(t *testing.T) { Status(501). Body(Contains("reading IPLD Kinds other than Links (CBOR Tag 42) is not implemented")), }, - /** - test_expect_success "GET DAG-CBOR traverses multiple links" ' - curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/link/bar?format=dag-json" > curl_output 2>&1 && - jq --sort-keys . curl_output > actual && - echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected && - test_cmp expected actual - ' - */ { Name: "GET DAG-CBOR traverses multiple links", Request: Request(). @@ -521,15 +390,6 @@ func TestNativeDag(t *testing.T) { formatted := dagTraversal.Formatted("dag-" + row.Format) tests := SugarTests{ - /** - # GET without explicit format and Accept: text/html returns raw block - - test_expect_success "GET $name from /ipfs without explicit format returns the same payload as the raw block" ' - ipfs block get "/ipfs/$CID" > expected && - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o curl_output && - test_cmp expected curl_output - ' - */ { Name: Fmt("GET {{name}} from /ipfs without explicit format returns the same payload as the raw block", row.Name), Hint: `GET without explicit format and Accept: text/html returns raw block`, @@ -541,15 +401,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - # GET dag-cbor block via Accept and ?format and ensure both are the same as `ipfs block get` output - - test_expect_success "GET $name from /ipfs with format=dag-$format returns the same payload as the raw block" ' - ipfs block get "/ipfs/$CID" > expected && - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o curl_ipfs_dag_param_output && - test_cmp expected curl_ipfs_dag_param_output - ' - */ { Name: Fmt("GET {{name}} from /ipfs with format=dag-{{format}} returns the same payload as the raw block", row.Name, row.Format), Hint: `GET dag-cbor block via Accept and ?format and ensure both are the same as ipfs block get output`, @@ -562,21 +413,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - test_expect_success "GET $name from /ipfs for application/$format returns the same payload as format=dag-$format" ' - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o expected && - curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=$format" -o plain_output && - test_cmp expected plain_output - ' - Note: we skip this test since we compare responses bytes to bytes above. - */ - /** - test_expect_success "GET $name from /ipfs with application/vnd.ipld.dag-$format returns the same payload as the raw block" ' - ipfs block get "/ipfs/$CID" > expected_block && - curl -sX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o curl_ipfs_dag_block_accept_output && - test_cmp expected_block curl_ipfs_dag_block_accept_output - ' - */ { Name: Fmt("GET {{name}} from /ipfs with application/vnd.ipld.dag-{{format}} returns the same payload as the raw block", row.Name, row.Format), Request: Request(). @@ -588,16 +424,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - # Make sure DAG-* can be requested as plain JSON or CBOR and response has plain Content-Type for interop purposes - - test_expect_success "GET $name with format=$format returns same payload as format=dag-$format but with plain Content-Type" ' - curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o expected && - curl -sD plain_headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=$format" -o plain_output && - test_should_contain "Content-Type: application/$format" plain_headers && - test_cmp expected plain_output - ' - */ { Name: Fmt("GET {{name}} with format={{format}} returns same payload as format=dag-{{format}} but with plain Content-Type", row.Name, row.Format), Hint: `Make sure DAG-* can be requested as plain JSON or CBOR and response has plain Content-Type for interop purposes`, @@ -611,14 +437,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - test_expect_success "GET $name with Accept: application/$format returns same payload as application/vnd.ipld.dag-$format but with plain Content-Type" ' - curl -s -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > expected && - curl -sD plain_headers -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > plain_output && - test_should_contain "Content-Type: application/$format" plain_headers && - test_cmp expected plain_output - ' - */ { Name: Fmt("GET {{name}} with Accept: application/{{format}} returns same payload as application/vnd.ipld.dag-{{format}} but with plain Content-Type", row.Name, row.Format), Request: Request(). @@ -631,24 +449,6 @@ func TestNativeDag(t *testing.T) { row.Checker(formatted), ), }, - /** - # Make sure expected HTTP headers are returned with the dag- block - - test_expect_success "GET response for application/vnd.ipld.dag-$format has expected Content-Type" ' - curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" >/dev/null 2>curl_output && - test_should_contain "< Content-Type: application/vnd.ipld.dag-$format" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Content-Length" ' - BYTES=$(ipfs block get $CID | wc --bytes) - test_should_contain "< Content-Length: $BYTES" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Content-Disposition" ' - test_should_contain "< Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes nosniff hint" ' - test_should_contain "< X-Content-Type-Options: nosniff" curl_output - ' - */ { Name: Fmt("GET response for application/vnd.ipld.dag-{{format}} has expected Content-Type", row.Format), Hint: `Make sure expected HTTP headers are returned with the dag- block`, @@ -663,12 +463,6 @@ func TestNativeDag(t *testing.T) { Header("X-Content-Type-Options").Hint("includes nosniff hint").Contains("nosniff"), ), }, - /** - test_expect_success "GET for application/vnd.ipld.dag-$format with query filename includes Content-Disposition with custom filename" ' - curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?filename=foobar.$format" >/dev/null 2>curl_output_filename && - test_should_contain "< Content-Disposition: ${disposition}\; filename=\"foobar.$format\"" curl_output_filename - ' - */ { Name: Fmt("GET for application/vnd.ipld.dag-{{format}} with query filename includes Content-Disposition with custom filename", row.Format), Request: Request(). @@ -682,12 +476,6 @@ func TestNativeDag(t *testing.T) { Contains(`{{disposition}}; filename="foobar.{{format}}"`, row.Disposition, row.Format), ), }, - /** - test_expect_success "GET for application/vnd.ipld.dag-$format with ?download=true forces Content-Disposition: attachment" ' - curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?filename=foobar.$format&download=true" >/dev/null 2>curl_output_filename && - test_should_contain "< Content-Disposition: attachment" curl_output_filename - ' - */ { Name: Fmt("GET for application/vnd.ipld.dag-{{format}} with ?download=true forces Content-Disposition: attachment", row.Format), Request: Request(). @@ -702,21 +490,6 @@ func TestNativeDag(t *testing.T) { Contains(`attachment; filename="foobar.{{format}}"`, row.Format), ), }, - /** - # Cache control HTTP headers - # (basic checks, detailed behavior is tested in t0116-gateway-cache.sh) - - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Etag" ' - test_should_contain "< Etag: \"${CID}.dag-$format\"" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes X-Ipfs-Path and X-Ipfs-Roots" ' - test_should_contain "< X-Ipfs-Path" curl_output && - test_should_contain "< X-Ipfs-Roots" curl_output - ' - test_expect_success "GET response for application/vnd.ipld.dag-$format includes Cache-Control" ' - test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_output - ' - */ { Name: Fmt("Cache control HTTP headers ({{format}})", row.Format), Hint: `(basic checks, detailed behavior is tested in t0116-gateway-cache.sh)`, @@ -731,15 +504,6 @@ func TestNativeDag(t *testing.T) { Header("Cache-Control").Hint("includes Cache-Control").Contains("public, max-age=29030400, immutable"), ), }, - /** - # HTTP HEAD behavior - test_expect_success "HEAD $name with no explicit format returns HTTP 200" ' - curl -I "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o output && - test_should_contain "HTTP/1.1 200 OK" output && - test_should_contain "Content-Type: application/vnd.ipld.dag-$format" output && - test_should_contain "Content-Length: " output - ' - */ { Name: Fmt("HEAD {{name}} with no explicit format returns HTTP 200", row.Name), Request: Request(). @@ -752,15 +516,6 @@ func TestNativeDag(t *testing.T) { Header("Content-Length").Hint("includes Content-Length").Exists(), ), }, - /** - test_expect_success "HEAD $name with an explicit DAG-JSON format returns HTTP 200" ' - curl -I "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-json" -o output && - test_should_contain "HTTP/1.1 200 OK" output && - test_should_contain "Etag: \"$CID.dag-json\"" output && - test_should_contain "Content-Type: application/vnd.ipld.dag-json" output && - test_should_contain "Content-Length: " output - ' - */ { Name: Fmt("HEAD {{name}} with an explicit DAG-JSON format returns HTTP 200", row.Name), Request: Request(). @@ -775,14 +530,6 @@ func TestNativeDag(t *testing.T) { Header("Content-Length").Hint("includes Content-Length").Exists(), ), }, - /** - test_expect_success "HEAD $name with only-if-cached for missing block returns HTTP 412 Precondition Failed" ' - MISSING_CID=$(echo "{\"t\": \"$(date +{{}})\"}" | ipfs dag put --store-codec=dag-${format}) && - ipfs block rm -f -q $MISSING_CID && - curl -I -H "Cache-Control: only-if-cached" "http://127.0.0.1:$GWAY_PORT/ipfs/$MISSING_CID" -o output && - test_should_contain "HTTP/1.1 412 Precondition Failed" output - ' - */ { Name: Fmt("HEAD {{name}} with only-if-cached for missing block returns HTTP 412 Precondition Failed", row.Name), Request: Request(). @@ -792,14 +539,6 @@ func TestNativeDag(t *testing.T) { Response: Expect(). Status(412), }, - // test_expect_success "GET $name on /ipfs with Accept: text/html returns HTML (dag-index-html)" ' - // curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output 2>&1 && - // test_should_not_contain "Content-Disposition" curl_output && - // test_should_not_contain "Cache-Control" curl_output && - // test_should_contain "Etag: \"DagIndex-" curl_output && - // test_should_contain "Content-Type: text/html" curl_output && - // test_should_contain "" curl_output - // ' { Name: Fmt("GET {{name}} on /ipfs with Accept: text/html returns HTML (dag-index-html)", row.Name), Request: Request(). @@ -846,11 +585,6 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { // # IPNS behavior (should be same as immutable /ipfs, but with different caching headers) // # To keep tests small we only confirm payload is the same, and then only test delta around caching headers. tests = append(tests, SugarTests{ - // test_expect_success "GET $name from /ipns without explicit format returns the same payload as /ipfs" ' - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o ipfs_output && - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID" -o ipns_output && - // test_cmp ipfs_output ipns_output - // ' { Name: Fmt("GET {{name}} from /ipns without explicit format returns the same payload as /ipfs", row.Name), Requests: Requests( @@ -862,11 +596,6 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { Responses: Responses(). HaveTheSamePayload(), }, - // test_expect_success "GET $name from /ipns without explicit format returns the same payload as /ipfs" ' - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" -o ipfs_output && - // curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID?format=dag-$format" -o ipns_output && - // test_cmp ipfs_output ipns_output - // ' { Name: Fmt("GET {{name}} from /ipns with explicit format returns the same payload as /ipfs", row.Name), Requests: Requests( @@ -880,15 +609,6 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { Responses: Responses(). HaveTheSamePayload(), }, - - // test_expect_success "GET $name from /ipns with explicit application/vnd.ipld.dag-$format has expected headers" ' - // curl -svX GET -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID" >/dev/null 2>curl_output && - // test_should_not_contain "Cache-Control" curl_output && - // test_should_contain "< Content-Type: application/vnd.ipld.dag-$format" curl_output && - // test_should_contain "< Etag: \"${CID}.dag-$format\"" curl_output && - // test_should_contain "< X-Ipfs-Path" curl_output && - // test_should_contain "< X-Ipfs-Roots" curl_output - // ' { Name: Fmt("GET {{name}} from /ipns with explicit application/vnd.ipld.dag-{{format}} has expected headers", row.Name, row.Format), Request: Request(). @@ -902,18 +622,6 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) { Header("X-Ipfs-Roots").Not().IsEmpty(), ), }, - // # When Accept header includes text/html and no explicit format is requested for DAG-(CBOR|JSON) - // # The gateway returns generated HTML index (see dag-index-html) for web browsers (similar to dir-index-html returned for unixfs dirs) - // # As this is generated, we don't return immutable Cache-Control, even on /ipfs (same as for dir-index-html) - - // test_expect_success "GET $name on /ipns with Accept: text/html returns HTML (dag-index-html)" ' - // curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID" > curl_output 2>&1 && - // test_should_not_contain "Content-Disposition" curl_output && - // test_should_not_contain "Cache-Control" curl_output && - // test_should_contain "Etag: \"DagIndex-" curl_output && - // test_should_contain "Content-Type: text/html" curl_output && - // test_should_contain "" curl_output - // ' { Name: Fmt("GET {{name}} on /ipns with Accept: text/html returns HTML (dag-index-html)", row.Name), Request: Request(). From ada783a1faa30edae6af47c7d3a9e0376c57d078 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 09:56:50 +0200 Subject: [PATCH 12/24] t0117: clear --- fixtures/README.md | 43 +++++++----------- ...ateway-block.car => gateway-raw-block.car} | Bin tests/path_gateway_raw_test.go | 3 +- tests/trustless_gateway_raw_test.go | 2 +- 4 files changed, 19 insertions(+), 29 deletions(-) rename fixtures/{t0117-gateway-block.car => gateway-raw-block.car} (100%) diff --git a/fixtures/README.md b/fixtures/README.md index f9df5d6b7..d5dbb1e90 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -1,33 +1,22 @@ -# ipfs add --recursive --raw-leaves --cid-version=1 --wrap-with-directory fixtures/dir +# Fixtures -added bafkreibyniihaqnhs536mbvc3wx66vbfttisc6zrvea6kzeku3w4as6lum dir/ascii.txt -added bafybeiaxmpwa4nz2mekiiosayvkfgfpbubm7pch7tspx5syhzzsvkoewc4 dir -added bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy +This folder contains all the fixtures using during the tests, with +the recipes to re-create them. -# ipfs dag export bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy > fixtures/dir.car +## Recipes -# go install github.com/ipld/go-car/cmd/car@latest +### [gateway-raw-block.car](./gateway-raw-block.car) -# car list fixtures/dir.car +Generated with: -bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy -bafybeiaxmpwa4nz2mekiiosayvkfgfpbubm7pch7tspx5syhzzsvkoewc4 -bafkreibyniihaqnhs536mbvc3wx66vbfttisc6zrvea6kzeku3w4as6lum +```sh +# using 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 > gateway-raw-block.car -# car extract --file fixtures/dir.car --verbose - -.../gateway-conformance/dir -.../gateway-conformance/dir/ascii.txt - -# go run extract.go fixtures/dir.car - -path: / - cid: bafybeie7u7bbgvdqbur6inl6fpl4yw3xcg34bjjmnnzkmpwb5v6x3xz3hy - raw: [18 45 10 36 1 112 18 32 23 99 236 14 55 58 97 20 132 58 64 197 84 83 21 225 160 89 247 136 255 156 159 126 203 7 206 101 85 56 150 23 18 3 100 105 114 24 90 10 2 8 1] -path: /dir - cid: bafybeiaxmpwa4nz2mekiiosayvkfgfpbubm7pch7tspx5syhzzsvkoewc4 - raw: [18 51 10 36 1 85 18 32 56 106 16 112 65 167 151 119 230 6 162 221 175 239 84 37 156 209 33 123 49 169 1 229 100 138 166 237 192 75 203 163 18 9 97 115 99 105 105 46 116 120 116 24 33 10 2 8 1] -path: /dir/ascii.txt - cid: bafkreibyniihaqnhs536mbvc3wx66vbfttisc6zrvea6kzeku3w4as6lum - raw: [103 111 111 100 98 121 101 32 97 112 112 108 105 99 97 116 105 111 110 47 118 110 100 46 105 112 108 100 46 114 97 119 10] - str: goodbye application/vnd.ipld.raw +echo ROOT_DIR_CID=${ROOT_DIR_CID} # ./ +echo FILE_CID=${FILE_CID} # ./dir/ascii.txt +``` \ No newline at end of file diff --git a/fixtures/t0117-gateway-block.car b/fixtures/gateway-raw-block.car similarity index 100% rename from fixtures/t0117-gateway-block.car rename to fixtures/gateway-raw-block.car diff --git a/tests/path_gateway_raw_test.go b/tests/path_gateway_raw_test.go index b0aac353c..0dc071a99 100644 --- a/tests/path_gateway_raw_test.go +++ b/tests/path_gateway_raw_test.go @@ -12,7 +12,7 @@ import ( ) func TestGatewayBlock(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0117-gateway-block.car") + fixture := car.MustOpenUnixfsCar("gateway-raw-block.car") tests := SugarTests{ { @@ -121,6 +121,7 @@ func TestGatewayBlock(t *testing.T) { Header("Cache-Control"). Hint("It should be public, immutable and have max-age of at least 31536000."). Checks(func(v string) bool { + // TODO: port this to a regular check. directives := strings.Split(strings.ReplaceAll(v, " ", ""), ",") dir := make(map[string]string) for _, directive := range directives { diff --git a/tests/trustless_gateway_raw_test.go b/tests/trustless_gateway_raw_test.go index afa492b94..8f5962885 100644 --- a/tests/trustless_gateway_raw_test.go +++ b/tests/trustless_gateway_raw_test.go @@ -11,7 +11,7 @@ import ( ) func TestTrustlessRaw(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0117-gateway-block.car") + fixture := car.MustOpenUnixfsCar("gateway-raw-block.car") tests := SugarTests{ { From 846a38ee43e1e2582bfce1a8620f5279e40d2e67 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 09:59:29 +0200 Subject: [PATCH 13/24] refactor: move test fixture in _fixtures --- ...4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record | Bin 0 -> 392 bytes tooling/ipns/ipns_test.go | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 tooling/ipns/_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record diff --git a/tooling/ipns/_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record b/tooling/ipns/_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record new file mode 100644 index 0000000000000000000000000000000000000000..ec13ec550162b81f44b35a6ab54b4dd9cdd11707 GIT binary patch literal 392 zcmd;b)XywPE7ng+Ov^4x%}hy4Day%CEi}nBsmQA+t*kK1OiVR5OH0W$DNoNaO);sc zDo!#t&#cI(EG#e0&8RXmF%fe3WvzU>SFJ04j^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 literal 0 HcmV?d00001 diff --git a/tooling/ipns/ipns_test.go b/tooling/ipns/ipns_test.go index f84265d8b..53bdb80bd 100644 --- a/tooling/ipns/ipns_test.go +++ b/tooling/ipns/ipns_test.go @@ -36,7 +36,7 @@ func TestExtractPath(t *testing.T) { } func TestLoadIPNSRecord(t *testing.T) { - path := "../../fixtures/t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record" + path := "./_fixtures/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record" ipns, err := OpenIPNSRecordWithKey(path) assert.Nil(t, err) From 20ae610a11549fc2d3c60b2281b475313df12cc3 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 10:02:48 +0200 Subject: [PATCH 14/24] t0124: clear (a) --- fixtures/ipns_records/README.md | 23 ++++++++++++++++++ fixtures/{t0124 => ipns_records}/fixtures.car | Bin ...i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record | Bin tests/trustless_gateway_ipns_test.go | 4 +-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 fixtures/ipns_records/README.md rename fixtures/{t0124 => ipns_records}/fixtures.car (100%) rename fixtures/{t0124 => ipns_records}/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record (100%) diff --git a/fixtures/ipns_records/README.md b/fixtures/ipns_records/README.md new file mode 100644 index 000000000..83cc7da63 --- /dev/null +++ b/fixtures/ipns_records/README.md @@ -0,0 +1,23 @@ +# IPNS Records Fixtures + +## Recipes + +### Fixtures and ipns-record + +```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/fixtures/t0124/fixtures.car b/fixtures/ipns_records/fixtures.car similarity index 100% rename from fixtures/t0124/fixtures.car rename to fixtures/ipns_records/fixtures.car diff --git a/fixtures/t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record b/fixtures/ipns_records/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record similarity index 100% rename from fixtures/t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record rename to fixtures/ipns_records/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record diff --git a/tests/trustless_gateway_ipns_test.go b/tests/trustless_gateway_ipns_test.go index c53a15943..e99449fbf 100644 --- a/tests/trustless_gateway_ipns_test.go +++ b/tests/trustless_gateway_ipns_test.go @@ -10,11 +10,11 @@ import ( ) func TestGatewayIPNSRecord(t *testing.T) { - fixture := car.MustOpenUnixfsCar("t0124/fixtures.car") + fixture := car.MustOpenUnixfsCar("ipns_records/fixtures.car") file := fixture.MustGetRoot() fileCID := file.Cid() - ipns := MustOpenIPNSRecordWithKey("t0124/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record") + ipns := MustOpenIPNSRecordWithKey("ipns_records/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record") ipnsName := ipns.Key() tests := SugarTests{ From 228fee714e04cec581be6531371643504cae239f Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 10:34:51 +0200 Subject: [PATCH 15/24] t0124: clear (b) --- tests/subdomain_gateway_ipfs_test.go | 6 +++--- tests/subdomain_gateway_ipns_test.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/subdomain_gateway_ipfs_test.go b/tests/subdomain_gateway_ipfs_test.go index 216e2e33d..1424e504f 100644 --- a/tests/subdomain_gateway_ipfs_test.go +++ b/tests/subdomain_gateway_ipfs_test.go @@ -219,7 +219,7 @@ func TestGatewaySubdomains(t *testing.T) { )), }, { - Name: "request for deep path resource at {cid}.ipfs.localhost/sub/dir/file", + Name: "request for deep path resource at {cid}.ipfs.example.com/sub/dir/file", Request: Request().URL("{{scheme}}://{{cid}}.ipfs.{{host}}/ipfs/ipns/bar", u.Scheme, DirCID, u.Host), Response: Expect(). Status(200). @@ -294,7 +294,7 @@ func TestGatewaySubdomains(t *testing.T) { ), }, { - Name: "request for a too long CID at localhost/ipfs/{CIDv1} returns human readable error", + Name: "request for a too long CID at example.com/ipfs/{CIDv1} returns human readable error", Hint: "router should not redirect to hostnames that could fail due to DNS limits", Request: Request().URL("{{url}}/ipfs/{{cid}}", gatewayURL, CIDv1_TOO_LONG), Response: Expect(). @@ -302,7 +302,7 @@ func TestGatewaySubdomains(t *testing.T) { Body(Contains("CID incompatible with DNS label length limit of 63")), }, { - Name: "request for a too long CID at {CIDv1}.ipfs.localhost returns expected payload", + Name: "request for a too long CID at {CIDv1}.ipfs.example.com returns expected payload", Hint: "direct request should also fail (provides the same UX as router and avoids confusion)", Request: Request().URL("{{scheme}}://{{cid}}.ipfs.{{host}}/", u.Scheme, CIDv1_TOO_LONG, u.Host), Response: Expect(). diff --git a/tests/subdomain_gateway_ipns_test.go b/tests/subdomain_gateway_ipns_test.go index e3c82d89c..d99d8b5e0 100644 --- a/tests/subdomain_gateway_ipns_test.go +++ b/tests/subdomain_gateway_ipns_test.go @@ -214,6 +214,7 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { Name: `request for example.com/ipns/?uri=ipns%3A%2F%2F.. produces redirect to /ipns/.. content path`, Hint: "Support ipns:// in https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler", Request: Request(). + // TODO: use Query or future QueryRaw here URL(`{{url}}/ipns/?uri=ipns%3A%2F%2F{{dnslink}}`, gatewayURL, wikipedia), Response: Expect(). Headers( From 0ab59b144a3225f03494773283cd93eaece1dd93 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 10:59:01 +0200 Subject: [PATCH 16/24] t0114: clear (e) --- tests/dnslink_gateway_test.go | 121 ---------------------------------- 1 file changed, 121 deletions(-) diff --git a/tests/dnslink_gateway_test.go b/tests/dnslink_gateway_test.go index c6eee1d99..0a18a23b2 100644 --- a/tests/dnslink_gateway_test.go +++ b/tests/dnslink_gateway_test.go @@ -13,127 +13,6 @@ import ( "github.com/ipfs/gateway-conformance/tooling/tmpl" ) -// TODO(laurent): this were in t0114_gateway_subdomains_test.go - -func TestDNSLinkGateway(t *testing.T) { - tests := SugarTests{ - // ## ============================================================================ - // ## Test DNSLink requests with a custom PublicGateway (hostname config) - // ## (DNSLink site at http://dnslink-test.example.com) - // ## ============================================================================ - // # disable wildcard DNSLink gateway - // # and enable it on specific NSLink hostname - // ipfs config --json Gateway.NoDNSLink true && \ - // ipfs config --json Gateway.PublicGateways '{ - // "dnslink-enabled-on-fqdn.example.org": { - // "NoDNSLink": false, - // "UseSubdomains": false, - // "Paths": ["/ipfs"] - // }, - // "only-dnslink-enabled-on-fqdn.example.org": { - // "NoDNSLink": false, - // "UseSubdomains": false, - // "Paths": [] - // }, - // "dnslink-disabled-on-fqdn.example.com": { - // "NoDNSLink": true, - // "UseSubdomains": false, - // "Paths": [] - // } - // }' || exit 1 - - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // DNSLINK_FQDN="dnslink-enabled-on-fqdn.example.org" - // ONLY_DNSLINK_FQDN="only-dnslink-enabled-on-fqdn.example.org" - // NO_DNSLINK_FQDN="dnslink-disabled-on-fqdn.example.com" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1,$ONLY_DNSLINK_FQDN:/ipfs/$DIR_CID" - - // # DNSLink enabled - - // test_hostname_gateway_response_should_contain \ - // "request for http://{dnslink-fqdn}/ PublicGateway returns expected payload" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/" \ - // "$CID_VAL" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipfs/{cid} returns expected payload when /ipfs is on Paths whitelist" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv1" \ - // "$CID_VAL" - - // # Test for a fun edge case: DNSLink-only gateway without /ipfs/ namespace - // # mounted, and with subdirectory named "ipfs" ¯\_(ツ)_/¯ - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipfs/file.txt returns data from content root when /ipfs in not on Paths whitelist" \ - // "$ONLY_DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipfs/file.txt" \ - // "I am a txt file" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipns/{peerid} returns 404 when path is not whitelisted" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \ - // "404 Not Found" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipns/{peerid} returns 404 when path is not whitelisted" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \ - // "404 Not Found" - - // # DNSLink disabled - - // test_hostname_gateway_response_should_contain \ - // "request for http://{dnslink-fqdn}/ returns 404 when NoDNSLink=true" \ - // "$NO_DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/" \ - // "404 Not Found" - - // test_hostname_gateway_response_should_contain \ - // "request for {dnslink-fqdn}/ipfs/{cid} returns 404 when path is not whitelisted" \ - // "$NO_DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/ipfs/$CIDv0" \ - // "404 Not Found" - - // ## ============================================================================ - // ## Test wildcard DNSLink (any hostname, with default config) - // ## ============================================================================ - - // test_kill_ipfs_daemon - - // # enable wildcard DNSLink gateway (any value in Host header) - // # and remove custom PublicGateways - // ipfs config --json Gateway.NoDNSLink false && \ - // ipfs config --json Gateway.PublicGateways '{}' || exit 1 - - // # DNSLink test requires a daemon in online mode with precached /ipns/ mapping - // DNSLINK_FQDN="wildcard-dnslink-not-in-config.example.com" - // export IPFS_NS_MAP="$DNSLINK_FQDN:/ipfs/$CIDv1" - - // # restart daemon to apply config changes - // test_launch_ipfs_daemon - - // # make sure test setup is valid (fail if CoreAPI is unable to resolve) - // test_expect_success "spoofed DNSLink record resolves in cli" " - // ipfs resolve /ipns/$DNSLINK_FQDN > result && - // test_should_contain \"$CIDv1\" result && - // ipfs cat /ipns/$DNSLINK_FQDN > result && - // test_should_contain \"$CID_VAL\" result - // " - - // # gateway test - // - // test_hostname_gateway_response_should_contain \ - // "request for http://{dnslink-fqdn}/ (wildcard) returns expected payload" \ - // "$DNSLINK_FQDN" \ - // "http://127.0.0.1:$GWAY_PORT/" \ - // "$CID_VAL" - } - - RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.DNSLinkGateway) -} - func TestDNSLinkGatewayUnixFSDirectoryListing(t *testing.T) { fixture := car.MustOpenUnixfsCar("dir_listing/fixtures.car") file := fixture.MustGetNode("ą", "ę", "file-źł.txt") From ad08a29fe422b92972045aac96fe8deacb451e4a Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 11:17:20 +0200 Subject: [PATCH 17/24] t0112: clear (b) --- tests/redirects_file_test.go | 68 +++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/tests/redirects_file_test.go b/tests/redirects_file_test.go index 18cbd2000..af1c85c9a 100644 --- a/tests/redirects_file_test.go +++ b/tests/redirects_file_test.go @@ -142,17 +142,6 @@ func TestRedirectsFileSupport(t *testing.T) { Status(200). Body(Contains("my index")), }, - // # This test ensures _redirects is supported only on Web Gateways that use Host header (DNSLink, Subdomain) - // test_expect_success "request for http://127.0.0.1:$GWAY_PORT/ipfs/$REDIRECTS_DIR_CID/301-redirect-one returns generic 404 (no custom 404 from _redirects since no origin isolation)" ' - // - // curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$REDIRECTS_DIR_CID/301-redirect-one" > response && - // test_should_contain "404 Not Found" response && - // test_should_not_contain "my 404" response - // - // ' - // TODO(lidel): Do we want to explicitly test something like "if the spec `redirect` is not enabled, then test this case"? - // Recommendation: don't (because you might disable a spec just because it's not fully implemented yet, which is different from not supporting it) - // and keep the test in kubo sharness. }...) // # Invalid file, containing forced redirect @@ -192,6 +181,54 @@ func TestRedirectsFileSupport(t *testing.T) { ), }, }...) + + // # With CRLF line terminator + newlineRedirectsDirCID := fixture.MustGetNode("newlines").Base32Cid() + newlineBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, newlineRedirectsDirCID, u.Host) + + // # Good codes + goodRedirectDirCID := fixture.MustGetNode("good-codes").Base32Cid() + goodRedirectDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, goodRedirectDirCID, u.Host) + + // # Bad codes + badRedirectDirCID := fixture.MustGetNode("bad-codes").Base32Cid() + badRedirectDirBaseURL := Fmt("{{scheme}}://{{cid}}.ipfs.{{host}}", u.Scheme, badRedirectDirCID, u.Host) + + tests = append(tests, SugarTests{ + { + Name: "newline: request for $NEWLINE_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file", + Request: Request(). + URL("{{url}}/redirect-one", newlineBaseURL), + Response: Expect(). + Status(301). + Headers( + Header("Location").Equals("/one.html"), + ), + }, + { + Name: "good codes: request for $GOOD_REDIRECTS_DIR_HOSTNAME/redirect-one redirects with default of 301, per _redirects file", + Request: Request(). + URL("{{url}}/a301", goodRedirectDirBaseURL), + Response: Expect(). + Status(301). + Headers( + Header("Location").Equals("/b301"), + ), + }, + { + Name: "bad codes: request for $BAD_REDIRECTS_DIR_HOSTNAME/found.html doesn't return error about bad code", + Request: Request(). + URL("{{url}}/found.html", badRedirectDirBaseURL), + Response: Expect(). + Status(200). + Body( + And( + Contains("my found"), + Not(Contains("unsupported redirect status")), + ), + ), + }, + }...) } RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGatewayIPFS, specs.RedirectsFile) @@ -237,15 +274,6 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) { Contains("my 404"), ), }, - // test_expect_success "request for $NO_DNSLINK_FQDN/redirect-one does not redirect, since DNSLink is disabled" ' - // curl -sD - --resolve $NO_DNSLINK_FQDN:$GWAY_PORT:127.0.0.1 "http://$NO_DNSLINK_FQDN:$GWAY_PORT/redirect-one" > response && - // test_should_not_contain "one.html" response && - // test_should_not_contain "301 Moved Permanently" response && - // test_should_not_contain "Location:" response - // ' - // TODO(lidel): Do we want to explicitly test something like "if the spec is not enabled, then test this case"? - // Recommendation: don't (because you might disable a spec just because it's not fully implemented yet, which is different from not supporting it) - // and keep the test in kubo sharness. } RunWithSpecs(t, helpers.UnwrapSubdomainTests(t, tests), specs.DNSLinkGateway, specs.RedirectsFile) From 496bf97093caa149013af83676c2d30d687eedb8 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 28 Jun 2023 15:21:14 +0200 Subject: [PATCH 18/24] t0112: update --- tests/path_gateway_unixfs_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/path_gateway_unixfs_test.go b/tests/path_gateway_unixfs_test.go index 2cea59cfc..980bf9a05 100644 --- a/tests/path_gateway_unixfs_test.go +++ b/tests/path_gateway_unixfs_test.go @@ -446,13 +446,15 @@ func TestCors(t *testing.T) { Response: Expect(). Headers( Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET"), - Header("Access-Control-Allow-Headers").Has("Range"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), Header("Access-Control-Expose-Headers").Has( "Content-Range", "Content-Length", "X-Ipfs-Path", "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", ), ), }, @@ -464,13 +466,15 @@ func TestCors(t *testing.T) { Response: Expect(). Headers( Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET"), - Header("Access-Control-Allow-Headers").Has("Range"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), Header("Access-Control-Expose-Headers").Has( "Content-Range", "Content-Length", "X-Ipfs-Path", "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", ), ), }, From afb870443ab76d26d42364f55189825a9eb8faac Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Thu, 29 Jun 2023 09:57:16 +0200 Subject: [PATCH 19/24] fixes: doc Co-authored-by: Marcin Rataj --- fixtures/README.md | 2 +- fixtures/dir_listing/README.md | 2 +- fixtures/gateway-cache/README.md | 2 +- fixtures/ipns_records/README.md | 2 +- fixtures/path_gateway_dag/README.md | 2 +- fixtures/path_gateway_tar/README.md | 2 +- fixtures/path_gateway_unixfs/README.md | 2 +- fixtures/redirects_file/README.md | 2 +- fixtures/t0123/README.md | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fixtures/README.md b/fixtures/README.md index d5dbb1e90..beff1066d 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -10,7 +10,7 @@ the recipes to re-create them. Generated with: ```sh -# using ipfs version 0.18.1 +# using Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/) mkdir -p dir && echo "hello application/vnd.ipld.raw" > dir/ascii.txt && ROOT_DIR_CID=$(ipfs add -Qrw --cid-version 1 dir) && diff --git a/fixtures/dir_listing/README.md b/fixtures/dir_listing/README.md index 5dc035540..8b74a7327 100644 --- a/fixtures/dir_listing/README.md +++ b/fixtures/dir_listing/README.md @@ -7,7 +7,7 @@ Raw CARv1, generated with: ```sh -# using ipfs version 0.18.1 +# using Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/) mkdir -p rootDir/ipfs && mkdir -p rootDir/ipns && mkdir -p rootDir/api && diff --git a/fixtures/gateway-cache/README.md b/fixtures/gateway-cache/README.md index 56f244caa..41ad5f4e4 100644 --- a/fixtures/gateway-cache/README.md +++ b/fixtures/gateway-cache/README.md @@ -10,7 +10,7 @@ generated with: ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) mkdir -p root2/root3/root4 && echo "hello" > root2/root3/root4/index.html && diff --git a/fixtures/ipns_records/README.md b/fixtures/ipns_records/README.md index 83cc7da63..772712820 100644 --- a/fixtures/ipns_records/README.md +++ b/fixtures/ipns_records/README.md @@ -5,7 +5,7 @@ ### Fixtures and ipns-record ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-rc3 (https://dist.ipfs.tech/kubo/v0.21.0-rc3/) FILE_CID=$(echo "Hello IPFS" | ipfs add --cid-version 1 -q) IPNS_KEY=$(ipfs key gen ipns-record) diff --git a/fixtures/path_gateway_dag/README.md b/fixtures/path_gateway_dag/README.md index 810ff6bc3..3caeaa2b3 100644 --- a/fixtures/path_gateway_dag/README.md +++ b/fixtures/path_gateway_dag/README.md @@ -14,7 +14,7 @@ Generated with: ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-rc3 (https://dist.ipfs.tech/kubo/v0.21.0-rc3/) mkdir -p rootDir/ipfs && mkdir -p rootDir/ipns && diff --git a/fixtures/path_gateway_tar/README.md b/fixtures/path_gateway_tar/README.md index ccf287b75..ff8790088 100644 --- a/fixtures/path_gateway_tar/README.md +++ b/fixtures/path_gateway_tar/README.md @@ -13,7 +13,7 @@ See the [PR](https://github.com/ipfs/kubo/pull/9029) that introduced them for mo Generated with: ```sh -# ipfs version 0.18.1 +# Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/) mkdir -p rootDir/ipfs && mkdir -p rootDir/ipns && diff --git a/fixtures/path_gateway_unixfs/README.md b/fixtures/path_gateway_unixfs/README.md index 5593db3a9..1c5186623 100644 --- a/fixtures/path_gateway_unixfs/README.md +++ b/fixtures/path_gateway_unixfs/README.md @@ -5,7 +5,7 @@ ### [symlink.car](./symlink.car) ```sh -# using ipfs version 0.18.1 +# using Kubo CLI version 0.18.1 (https://dist.ipfs.tech/kubo/v0.18.1/ mkdir testfiles && echo "content" > testfiles/foo && ln -s foo testfiles/bar && diff --git a/fixtures/redirects_file/README.md b/fixtures/redirects_file/README.md index 482f90e33..9d56fb5cf 100644 --- a/fixtures/redirects_file/README.md +++ b/fixtures/redirects_file/README.md @@ -9,4 +9,4 @@ See comments in the yml file. ### [redirects.car](./redirects.car) -Fixtures was provided in [specs.ipfs.tech](https://specs.ipfs.tech/http-gateways/web-redirects-file/#test-fixtures) \ No newline at end of file +Fixtures based on [specs.ipfs.tech/http-gateways/web-redirects-file/#test-fixtures](https://specs.ipfs.tech/http-gateways/web-redirects-file/#test-fixtures) and [IPIP-0002](https://specs.ipfs.tech/ipips/ipip-0002/) \ No newline at end of file diff --git a/fixtures/t0123/README.md b/fixtures/t0123/README.md index 5a63b192a..de670caa5 100644 --- a/fixtures/t0123/README.md +++ b/fixtures/t0123/README.md @@ -14,7 +14,7 @@ generated with: ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) mkdir -p rootDir/ipfs && mkdir -p rootDir/ipns && From 49a9354fef2d82b5333f47897e9a62b3ee113a0b Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Thu, 29 Jun 2023 10:05:51 +0200 Subject: [PATCH 20/24] fix: rename fixture --- ...cbor.car => plain-cbor-that-can-be-dag-cbor.car} | Bin ...json.car => plain-cbor-that-can-be-dag-json.car} | Bin .../{plain.cbor.car => plain-cbor.car} | Bin .../{plain.json.car => plain-json.car} | Bin tests/path_gateway_dag_test.go | 4 ++-- 5 files changed, 2 insertions(+), 2 deletions(-) rename fixtures/path_gateway_dag/{plain-that-can-be-dag.cbor.car => plain-cbor-that-can-be-dag-cbor.car} (100%) rename fixtures/path_gateway_dag/{plain-that-can-be-dag.json.car => plain-cbor-that-can-be-dag-json.car} (100%) rename fixtures/path_gateway_dag/{plain.cbor.car => plain-cbor.car} (100%) rename fixtures/path_gateway_dag/{plain.json.car => plain-json.car} (100%) diff --git a/fixtures/path_gateway_dag/plain-that-can-be-dag.cbor.car b/fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-cbor.car similarity index 100% rename from fixtures/path_gateway_dag/plain-that-can-be-dag.cbor.car rename to fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-cbor.car diff --git a/fixtures/path_gateway_dag/plain-that-can-be-dag.json.car b/fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-json.car similarity index 100% rename from fixtures/path_gateway_dag/plain-that-can-be-dag.json.car rename to fixtures/path_gateway_dag/plain-cbor-that-can-be-dag-json.car diff --git a/fixtures/path_gateway_dag/plain.cbor.car b/fixtures/path_gateway_dag/plain-cbor.car similarity index 100% rename from fixtures/path_gateway_dag/plain.cbor.car rename to fixtures/path_gateway_dag/plain-cbor.car diff --git a/fixtures/path_gateway_dag/plain.json.car b/fixtures/path_gateway_dag/plain-json.car similarity index 100% rename from fixtures/path_gateway_dag/plain.json.car rename to fixtures/path_gateway_dag/plain-json.car diff --git a/tests/path_gateway_dag_test.go b/tests/path_gateway_dag_test.go index f7f89a60e..ac3d9d897 100644 --- a/tests/path_gateway_dag_test.go +++ b/tests/path_gateway_dag_test.go @@ -221,8 +221,8 @@ func TestPlainCodec(t *testing.T) { } for _, row := range table { - plain := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain.{{format}}.car", row.Format)).MustGetRoot() - plainOrDag := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain-that-can-be-dag.{{format}}.car", row.Format)).MustGetRoot() + plain := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain-{{format}}.car", row.Format)).MustGetRoot() + plainOrDag := car.MustOpenUnixfsCar(Fmt("path_gateway_dag/plain-cbor-that-can-be-dag-{{format}}.car", row.Format)).MustGetRoot() formatted := plainOrDag.Formatted("dag-" + row.Format) plainCID := plain.Cid() From fc12109e0dee6d9b830cc2d3a49df32b65985583 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Thu, 29 Jun 2023 10:07:37 +0200 Subject: [PATCH 21/24] fix: readme --- fixtures/subdomain_gateway/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fixtures/subdomain_gateway/README.md b/fixtures/subdomain_gateway/README.md index d6d5f6aed..ea300eb34 100644 --- a/fixtures/subdomain_gateway/README.md +++ b/fixtures/subdomain_gateway/README.md @@ -9,7 +9,7 @@ See comments in the yml file. ### [fixtures.car](./fixtures.car) ```sh -# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867) +# using Kubo CLI version 0.21.0-rc3 (https://dist.ipfs.tech/kubo/v0.21.0-rc3/) # CIDv0to1 is necessary because raw-leaves are enabled by default during # "ipfs add" with CIDv1 and disabled with CIDv0 From a886c558a109cb2ed7414c1d12c4174ba8171499 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Thu, 29 Jun 2023 10:09:39 +0200 Subject: [PATCH 22/24] fix: split back the cors --- tests/path_gateway_cors_test.go | 56 +++++++++++++++++++++++++++++++ tests/path_gateway_unixfs_test.go | 48 -------------------------- 2 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 tests/path_gateway_cors_test.go diff --git a/tests/path_gateway_cors_test.go b/tests/path_gateway_cors_test.go new file mode 100644 index 000000000..563a2a71a --- /dev/null +++ b/tests/path_gateway_cors_test.go @@ -0,0 +1,56 @@ +package tests + +import ( + "testing" + + "github.com/ipfs/gateway-conformance/tooling/specs" + . "github.com/ipfs/gateway-conformance/tooling/test" +) + +func TestCors(t *testing.T) { + cidHello := "bafkqabtimvwgy3yk" // hello + + tests := SugarTests{ + { + Name: "GET Responses from Gateway should include CORS headers allowing JS from other origins to read the data cross-origin.", + Request: Request(). + Path("/ipfs/{{CID}}/", cidHello), + Response: Expect(). + Headers( + Header("Access-Control-Allow-Origin").Equals("*"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), + Header("Access-Control-Expose-Headers").Has( + "Content-Range", + "Content-Length", + "X-Ipfs-Path", + "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", + ), + ), + }, + { + Name: "OPTIONS to Gateway succeeds", + Request: Request(). + Method("OPTIONS"). + Path("/ipfs/{{CID}}/", cidHello), + Response: Expect(). + Headers( + Header("Access-Control-Allow-Origin").Equals("*"), + Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), + Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), + Header("Access-Control-Expose-Headers").Has( + "Content-Range", + "Content-Length", + "X-Ipfs-Path", + "X-Ipfs-Roots", + "X-Chunked-Output", + "X-Stream-Output", + ), + ), + }, + } + + RunWithSpecs(t, tests, specs.PathGatewayUnixFS) +} diff --git a/tests/path_gateway_unixfs_test.go b/tests/path_gateway_unixfs_test.go index 980bf9a05..e0250809f 100644 --- a/tests/path_gateway_unixfs_test.go +++ b/tests/path_gateway_unixfs_test.go @@ -434,51 +434,3 @@ func TestGatewaySymlink(t *testing.T) { RunWithSpecs(t, tests, specs.PathGatewayUnixFS) } - -func TestCors(t *testing.T) { - cidHello := "bafkqabtimvwgy3yk" // hello - - tests := SugarTests{ - { - Name: "GET Responses from Gateway should include CORS headers allowing JS from other origins to read the data cross-origin.", - Request: Request(). - Path("/ipfs/{{CID}}/", cidHello), - Response: Expect(). - Headers( - Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), - Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), - Header("Access-Control-Expose-Headers").Has( - "Content-Range", - "Content-Length", - "X-Ipfs-Path", - "X-Ipfs-Roots", - "X-Chunked-Output", - "X-Stream-Output", - ), - ), - }, - { - Name: "OPTIONS to Gateway succeeds", - Request: Request(). - Method("OPTIONS"). - Path("/ipfs/{{CID}}/", cidHello), - Response: Expect(). - Headers( - Header("Access-Control-Allow-Origin").Equals("*"), - Header("Access-Control-Allow-Methods").Has("GET", "HEAD", "OPTIONS"), - Header("Access-Control-Allow-Headers").Has("Content-Type", "Range", "User-Agent", "X-Requested-With"), - Header("Access-Control-Expose-Headers").Has( - "Content-Range", - "Content-Length", - "X-Ipfs-Path", - "X-Ipfs-Roots", - "X-Chunked-Output", - "X-Stream-Output", - ), - ), - }, - } - - RunWithSpecs(t, tests, specs.PathGatewayUnixFS) -} From 7a2a26d64bff2df1bd81847f3c2ebe713971ae53 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Thu, 29 Jun 2023 10:50:23 +0200 Subject: [PATCH 23/24] fix: t0123 headers --- tests/path_gateway_dag_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/path_gateway_dag_test.go b/tests/path_gateway_dag_test.go index ac3d9d897..d0b0aec1b 100644 --- a/tests/path_gateway_dag_test.go +++ b/tests/path_gateway_dag_test.go @@ -22,7 +22,7 @@ func TestGatewayJsonCbor(t *testing.T) { tests := SugarTests{ { - Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type (1)", + Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type - without headers", Hint: ` ## Quick regression check for JSON stored on UnixFS: ## it has nothing to do with DAG-JSON and JSON codecs, @@ -30,10 +30,7 @@ func TestGatewayJsonCbor(t *testing.T) { ## and we want to avoid surprises like https://github.com/protocol/bifrost-infra/issues/2290 `, Request: Request(). - Path("/ipfs/{{cid}}", fileJSONCID). - Headers( - Header("Accept", "application/json"), - ), + Path("/ipfs/{{cid}}", fileJSONCID), Response: Expect(). Status(200). Headers( @@ -43,7 +40,7 @@ func TestGatewayJsonCbor(t *testing.T) { Body(fileJSONData), }, { - Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type (2)", + Name: "GET UnixFS file with JSON bytes is returned with application/json Content-Type - with headers", Hint: ` ## Quick regression check for JSON stored on UnixFS: ## it has nothing to do with DAG-JSON and JSON codecs, From 439156e3909156bc5d065e59c0f222feab5b58b9 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Fri, 30 Jun 2023 13:11:49 +0200 Subject: [PATCH 24/24] CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ce9c799f..18df60519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `--verbose` flag displays all the output to the console +### Changed +- finalized port of Kubo's sharness tests. [PR](https://github.com/ipfs/gateway-conformance/pull/92) + ## [0.2.0] - 2023-06-26 ### Added - `carFixture.MustGetChildren`