Skip to content

Commit

Permalink
fix(gw): blocked content produces http error 410
Browse files Browse the repository at this point in the history
requires ipfs/boxo#497
  • Loading branch information
lidel committed Oct 28, 2023
1 parent da2dc47 commit 6d22e32
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/examples/kubo-as-a-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.20
replace github.com/ipfs/kubo => ./../../..

require (
github.com/ipfs/boxo v0.13.2-0.20231019090647-a7e134e54ff9
github.com/ipfs/boxo v0.13.2-0.20231028015436-72da286aaa8d
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
github.com/libp2p/go-libp2p v0.31.0
github.com/multiformats/go-multiaddr v0.11.0
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/kubo-as-a-library/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.13.2-0.20231019090647-a7e134e54ff9 h1:dmjRJU0cMxrGIcd9gBgrRATl2DL0xrmJM/jedPKhQbQ=
github.com/ipfs/boxo v0.13.2-0.20231019090647-a7e134e54ff9/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/boxo v0.13.2-0.20231028015436-72da286aaa8d h1:ejcu6pCKKKtump4iKXaNFPkJl6/bly7cUSl9MwW6pl4=
github.com/ipfs/boxo v0.13.2-0.20231028015436-72da286aaa8d/go.mod h1:pu8HsZvuyYeYJsqtLDCoYSvy8rHj6vI3dlh8P0f83Zs=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs-shipyard/nopfs v0.0.12-0.20231027223058-cde3b5ba964c
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c
github.com/ipfs/boxo v0.13.2-0.20231019090647-a7e134e54ff9
github.com/ipfs/boxo v0.13.2-0.20231028015436-72da286aaa8d
github.com/ipfs/go-block-format v0.2.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-cidutil v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.13.2-0.20231019090647-a7e134e54ff9 h1:dmjRJU0cMxrGIcd9gBgrRATl2DL0xrmJM/jedPKhQbQ=
github.com/ipfs/boxo v0.13.2-0.20231019090647-a7e134e54ff9/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/boxo v0.13.2-0.20231028015436-72da286aaa8d h1:ejcu6pCKKKtump4iKXaNFPkJl6/bly7cUSl9MwW6pl4=
github.com/ipfs/boxo v0.13.2-0.20231028015436-72da286aaa8d/go.mod h1:pu8HsZvuyYeYJsqtLDCoYSvy8rHj6vI3dlh8P0f83Zs=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=
Expand Down
16 changes: 8 additions & 8 deletions test/cli/content_blocking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestContentBlocking(t *testing.T) {
// and running in parallel could impact other tests

const blockedMsg = "blocked and cannot be provided"
const statusExpl = "HTTP error code is expected"
const statusExpl = "specific HTTP error code is expected"
const bodyExpl = "Error message informing about content block is expected"

h := harness.NewT(t)
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestContentBlocking(t *testing.T) {
t.Run("Gateway Denies directly blocked CID", func(t *testing.T) {
t.Parallel()
resp := client.Get("/ipfs/" + blockedCID)
assert.NotEqual(t, http.StatusOK, resp.StatusCode, statusExpl)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
assert.NotEqual(t, "directly blocked file content", resp.Body)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestContentBlocking(t *testing.T) {
t.Run(gwTestName, func(t *testing.T) {
resp := client.Get(testCase.path)
// TODO we should require HTTP 410, not 5XX: assert.Equal(t, http.StatusGone, resp.StatusCode)
assert.NotEqual(t, http.StatusOK, resp.StatusCode, statusExpl)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})

Expand All @@ -191,7 +191,7 @@ func TestContentBlocking(t *testing.T) {
r.Host = "localhost:" + gwURL.Port()
})

assert.NotEqual(t, http.StatusOK, resp.StatusCode, statusExpl)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
// TODO assert.Equal(t, http.StatusGone, resp.StatusCode)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})
Expand All @@ -204,7 +204,7 @@ func TestContentBlocking(t *testing.T) {
r.Host = "blocked-dnslink.example.com.ipns.localhost:" + gwURL.Port()
})

assert.NotEqual(t, http.StatusOK, resp.StatusCode, statusExpl)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
// TODO assert.Equal(t, http.StatusGone, resp.StatusCode)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})
Expand All @@ -219,7 +219,7 @@ func TestContentBlocking(t *testing.T) {
r.Host = "blocked--dnslink-example-com.ipns.localhost:" + gwURL.Port()
})

assert.NotEqual(t, http.StatusOK, resp.StatusCode, statusExpl)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
// TODO assert.Equal(t, http.StatusGone, resp.StatusCode)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestContentBlocking(t *testing.T) {
// Then, does the most basic blocking case work?
t.Run("Denies directly blocked CID", func(t *testing.T) {
resp := client.Get("/ipfs/" + blockedCID)
assert.NotEqual(t, http.StatusOK, resp.StatusCode, statusExpl)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
assert.NotEqual(t, "directly blocked file content", resp.Body)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestContentBlocking(t *testing.T) {
resp, err := libp2pClient.Get(fmt.Sprintf("/ipfs/%s?format=raw", blockedCID))
require.NoError(t, err)
defer resp.Body.Close()
assert.NotEqual(t, http.StatusOK, resp.StatusCode, statusExpl)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
assert.NotEqual(t, string(body), "directly blocked file content")
Expand Down

0 comments on commit 6d22e32

Please sign in to comment.