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

test/cli: content blocking tests for CARs #10359

Closed
wants to merge 1 commit into from
Closed

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Feb 29, 2024

No description provided.

@hacdias hacdias added the skip/changelog This change does NOT require a changelog entry label Feb 29, 2024
Comment on lines +196 to +211
for _, format := range []string{"", "raw", "car"} { // CARs should also fail immediately since we access the file directly.
// Confirm that denylist is active for every content path in 'testCases' with different formats
gwTestName := fmt.Sprintf("Gateway denies %s with format %s", testCase.name, format)
t.Run(gwTestName, func(t *testing.T) {
resp := client.Get(testCase.path + "?format=" + format)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})
}
Copy link
Member Author

@hacdias hacdias Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CAR times out on both 0.26 and current PR in some tests, such as Double hash (blake3) Path block under blake3 root CID. This is because we don't have the data locally, and it seems that the node tries to fetch it.

This test returns 500 for the Libp2p gateway since it is an offline gateway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like some tests fail due to the same bug as #10361

Comment on lines 104 to 124
// Does the gateway deny indirectly blocked CID?
t.Run("Gateway Denies indirectly blocked CID", func(t *testing.T) {
t.Parallel()
resp := client.Get("/ipfs/" + blockedCIDInParentDirCID)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
assert.NotEqual(t, "directly blocked file content", resp.Body)
assert.Contains(t, resp.Body, blockedMsg, bodyExpl)
})

// Does the gateway return CAR
t.Run("Gateway returns parent path CAR without blocked CID", func(t *testing.T) {
resp := client.Get("/ipfs/" + parentDirCID + "?format=car")
require.Equal(t, http.StatusOK, resp.StatusCode)

bs, err := cbs.NewReadOnly(strings.NewReader(resp.Body), nil)
require.NoError(t, err)

has, err := bs.Has(context.Background(), cid.MustParse(blockedCIDInParentDirCID))
require.NoError(t, err)
require.False(t, has)
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fail on both 0.26 and master.

Copy link
Member

@lidel lidel Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filled #10361, let's continue there

Comment on lines +328 to +345
t.Run("Denies Blocked CID (CAR)", func(t *testing.T) {
t.Parallel()
resp, err := libp2pClient.Get(fmt.Sprintf("/ipfs/%s?format=car", blockedCID))
require.NoError(t, err)
defer resp.Body.Close()
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")
assert.Contains(t, string(body), blockedMsg, bodyExpl)
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes on both 0.26 and master.

@hacdias
Copy link
Member Author

hacdias commented Feb 29, 2024

@lidel I don't think any behaviour is different since 0.26. Could you double check?

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also was not able to find a case which looks like a regression since 0.26.

Bit late on my end, but iiuc the bug described in #10361 was always present.

I propose we:

  1. proceed with Release 0.27 #10306 (RC2)
  2. close this PR draft – it served its purpose (comparing with 0.26 to identify regressions)
  3. merge cleanup from test: cleanup content blocking tests #10360 instead
  4. fix denylist: ?format=car does not skip directly blocked CIDs #10361 in next iteration (Kubo 0.28)

t.Parallel()
resp := client.Get("/ipfs/" + blockedCIDInParentDirCID)
assert.Equal(t, http.StatusGone, resp.StatusCode, statusExpl)
assert.NotEqual(t, "directly blocked file content", resp.Body)
Copy link
Member

@lidel lidel Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does not matter much but this is a dir, not a file, so body will never match :-)

Suggested change
assert.NotEqual(t, "directly blocked file content", resp.Body)

@@ -36,6 +38,7 @@ func TestContentBlocking(t *testing.T) {
// Create CIDs we use in test
h.WriteFile("blocked-dir/subdir/indirectly-blocked-file.txt", "indirectly blocked file content")
parentDirCID := node.IPFS("add", "--raw-leaves", "-Q", "-r", filepath.Join(h.Dir, "blocked-dir")).Stdout.Trimmed()
blockedCIDInParentDirCID := node.IPFS("add", "--raw-leaves", "-Q", "-r", filepath.Join(h.Dir, "blocked-dir", "subdir")).Stdout.Trimmed()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 During review, I've realized some things changed in refactors and dir names are confusing: blocked-dir is not blocked 🙃 and subdir is directly blocked, I fixed names in #10360 so its easier to reason about test file in the future.

Comment on lines +113 to +124
// Does the gateway return CAR
t.Run("Gateway returns parent path CAR without blocked CID", func(t *testing.T) {
resp := client.Get("/ipfs/" + parentDirCID + "?format=car")
assert.Equal(t, http.StatusOK, resp.StatusCode)

bs, err := cbs.NewReadOnly(strings.NewReader(resp.Body), nil)
assert.NoError(t, err)

has, err := bs.Has(context.Background(), cid.MustParse(blockedCIDInParentDirCID))
assert.NoError(t, err)
assert.False(t, has)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 iiuc this does not pass because /ipfs/parentDirCID/subdir here is blocked by a subpath rule, and not by a CID rule (blockedCIDInParentDirCID). It was this way since the beginning, so not a regression blocking 0.27, but a bug which we should fix in future release.

I've added a version of this test that uses path and commented out one which does not pass yet to #10360

@hacdias hacdias closed this Mar 1, 2024
@hacdias hacdias deleted the tests-blocking branch March 1, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip/changelog This change does NOT require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants