Skip to content

Commit

Permalink
t0116: feature complete
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Jun 28, 2023
1 parent bba50f3 commit 09b5687
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
43 changes: 43 additions & 0 deletions fixtures/gateway_cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Gateway Cache Fixtures

## Recipes

### fixtures & ipns-record

- fixtures.car
- raw CARv1

generated with:

```sh
# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867)

mkdir -p root2/root3/root4 &&
echo "hello" > root2/root3/root4/index.html &&
ROOT1_CID=$(ipfs add -Qrw --cid-version 1 root2)
ROOT2_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2 | cut -d "/" -f3)
ROOT3_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3 | cut -d "/" -f3)
ROOT4_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3/root4 | cut -d "/" -f3)
FILE_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3/root4/index.html | cut -d "/" -f3)

TEST_IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 cache_test_key | head -n1 | tr -d "\n")
# publish a record valid for a 100 years
ipfs name publish --key cache_test_key --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$ROOT1_CID"
ipfs routing get /ipns/${TEST_IPNS_ID} > ${TEST_IPNS_ID}.ipns-record

echo ROOT1_CID=${ROOT1_CID} # ./
echo ROOT2_CID=${ROOT2_CID} # ./root2
echo ROOT3_CID=${ROOT3_CID} # ./root2/root3
echo ROOT4_CID=${ROOT4_CID} # ./root2/root3/root4
echo FILE_CID=${FILE_CID} # ./root2/root3/root4/index.html
echo TEST_IPNS_ID=${TEST_IPNS_ID}

ipfs dag export ${ROOT1_CID} > ./fixtures.car

# ROOT1_CID=bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui # ./
# ROOT2_CID=bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii # ./root2
# ROOT3_CID=bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja # ./root2/root3
# ROOT4_CID=bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q # ./root2/root3/root4
# FILE_CID=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am # ./root2/root3/root4/index.html
# TEST_IPNS_ID=k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe
```
File renamed without changes.
26 changes: 12 additions & 14 deletions tests/path_gateway_unixfs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"strings"
"testing"

"github.com/ipfs/gateway-conformance/tooling/car"
Expand Down Expand Up @@ -101,14 +102,8 @@ func TestUnixFSDirectoryListing(t *testing.T) {
RunWithSpecs(t, tests, specs.PathGatewayUnixFS)
}

// TODO(laurent): below were in t0116_gateway_cache_test

func TestGatewayCache(t *testing.T) {
fixture := car.MustOpenUnixfsCar("t0116/gateway-cache.car")

// TODO: Add request chaining support to the test framework and enable the etag tests
// https://specs.ipfs.tech/http-gateways/path-gateway/#etag-response-header
// var etag string
fixture := car.MustOpenUnixfsCar("gateway-cache/fixtures.car")

tests := SugarTests{
{
Expand Down Expand Up @@ -226,6 +221,9 @@ func TestGatewayCache(t *testing.T) {
Response: Expect().
Status(412),
},
// ==========
// # If-None-Match (return 304 Not Modified when client sends matching Etag they already have)
// ==========
{
Name: "GET for /ipfs/ file with matching Etag in If-None-Match returns 304 Not Modified",
Request: Request().
Expand Down Expand Up @@ -290,8 +288,8 @@ func TestGatewayCache(t *testing.T) {

RunWithSpecs(t, tests, specs.PathGatewayUnixFS)

// DirIndex etag is based on xxhash(./assets/dir-index-html), so we need to fetch it dynamically
var etag string
// DirIndex etagDir is based on xxhash(./assets/dir-index-html), so we need to fetch it dynamically
var etagDir string

testsA := SugarTests{
{
Expand All @@ -303,7 +301,7 @@ func TestGatewayCache(t *testing.T) {
Headers(
Header("Etag").
Checks(func(v string) bool {
etag = strings.Trim(v, `"`)
etagDir = strings.Trim(v, `"`)
return v != ""
}),
),
Expand All @@ -317,7 +315,7 @@ func TestGatewayCache(t *testing.T) {
Request: Request().
Path("/ipfs/{{cid}}/root2/root3/", fixture.MustGetCid()).
Headers(
Header("If-None-Match", `"{{etag}}"`, etag),
Header("If-None-Match", `"{{etag}}"`, etagDir),
),
Response: Expect().
Status(304),
Expand All @@ -327,7 +325,7 @@ func TestGatewayCache(t *testing.T) {
Request: Request().
Path("/ipfs/{{cid}}/root2/root3/", fixture.MustGetCid()).
Headers(
Header("If-None-Match", `W/"{{etag}}"`, etag),
Header("If-None-Match", `W/"{{etag}}"`, etagDir),
),
Response: Expect().
Status(304),
Expand All @@ -337,8 +335,8 @@ func TestGatewayCache(t *testing.T) {
}

func TestGatewayCacheWithIPNS(t *testing.T) {
fixture := car.MustOpenUnixfsCar("t0116/gateway-cache.car")
ipns := ipns.MustOpenIPNSRecordWithKey("t0116/k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe.ipns-record")
fixture := car.MustOpenUnixfsCar("gateway-cache/fixtures.car")
ipns := ipns.MustOpenIPNSRecordWithKey("gateway-cache/k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe.ipns-record")
ipnsKey := ipns.Key()

tests := SugarTests{
Expand Down

0 comments on commit 09b5687

Please sign in to comment.