Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for /ipns paths and Cache-Control HTTP header #173

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Loosened the `Cache-Control` and `Last-Modified` checks for IPNS paths, as they are now allowed. [PR](https://github.com/ipfs/gateway-conformance/pull/173)

## [0.4.0] - 2023-10-02
### Added
- Added tests for HTTP Range requests, as well as some basic helpers for `AnyOf` and `AllOf`. [PR](https://github.com/ipfs/gateway-conformance/pull/162)
Expand Down
21 changes: 13 additions & 8 deletions tests/path_gateway_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,14 +803,19 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) {
Request: Request().
Path("/ipns/{{id}}/", row.fixture.Key()).
Header("Accept", "text/html"),
Response: Expect().
Headers(
Header("Etag").Contains("DagIndex-"),
Header("Content-Type").Contains("text/html"),
Header("Content-Disposition").IsEmpty(),
Header("Cache-Control").IsEmpty(),
).Body(
Contains("</html>"),
Response: AllOf(
Expect().
Headers(
Header("Etag").Contains("DagIndex-"),
Header("Content-Type").Contains("text/html"),
Header("Content-Disposition").IsEmpty(),
).Body(
Contains("</html>"),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
}...)
Expand Down
102 changes: 59 additions & 43 deletions tests/path_gateway_unixfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,76 +328,92 @@ func TestGatewayCacheWithIPNS(t *testing.T) {
Name: "GET for /ipns/ unixfs dir listing succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/", ipnsKey),
Response: Expect().
Status(200).
Headers(
Header("Cache-Control").
IsEmpty(),
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3")),
Header("Etag").
Matches("DirIndex-.*_CID-{{CID}}", fixture.MustGetCid("root2", "root3")),
Response: AllOf(
Expect().
Status(200).
Headers(
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3")),
Header("Etag").
Matches("DirIndex-.*_CID-{{CID}}", fixture.MustGetCid("root2", "root3")),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs dir with index.html succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey),
Response: Expect().
Status(200).
Headers(
Header("Cache-Control").
IsEmpty(),
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4")),
Header("Etag").
Matches(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4")),
Response: AllOf(
Expect().
Status(200).
Headers(
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4")),
Header("Etag").
Matches(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4")),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs file succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/index.html", ipnsKey),
Response: Expect().
Status(200).
Headers(
Header("Cache-Control").
IsEmpty(),
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/index.html", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}},{{CID5}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4"), fixture.MustGetCid("root2", "root3", "root4", "index.html")),
Header("Etag").
Equals(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4", "index.html")),
Response: AllOf(
Expect().
Status(200).
Headers(
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/index.html", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}},{{CID5}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4"), fixture.MustGetCid("root2", "root3", "root4", "index.html")),
Header("Etag").
Equals(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4", "index.html")),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs dir as DAG-JSON succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey).
Query("format", "dag-json"),
Response: Expect().
Status(200).
Headers(
Header("Cache-Control").
IsEmpty(),
Response: AllOf(
Expect().
Status(200),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs dir as JSON succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey).
Query("format", "json"),
Response: Expect().
Status(200).
Headers(
Header("Cache-Control").
IsEmpty(),
Response: AllOf(
Expect().
Status(200),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ file with matching Etag in If-None-Match returns 304 Not Modified",
Expand Down
Loading