Skip to content

Commit

Permalink
feat: loosen tests for /ipns paths and Cache-Control HTTP header (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias authored Oct 10, 2023
1 parent c038078 commit f158662
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 51 deletions.
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

0 comments on commit f158662

Please sign in to comment.