Skip to content

Commit

Permalink
client/object: Prohibit empty filter attributes in SearchV2
Browse files Browse the repository at this point in the history
They are invalid according to the protocol, so no sense to pass them.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
  • Loading branch information
cthulhu-rider committed Feb 24, 2025
1 parent caa1acb commit 66489a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/object_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ func (c *Client) SearchObjects(ctx context.Context, cnr cid.ID, filters object.S

func verifySearchFilter(f object.SearchFilter) error {
switch attr := f.Header(); attr {
case "":
return errors.New("missing attribute")
case object.FilterContainerID, object.FilterID:
return fmt.Errorf("prohibited attribute %s", attr)
}
Expand Down
7 changes: 7 additions & 0 deletions client/object_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,13 @@ func TestClient_SearchObjects(t *testing.T) {
_, _, err = okConn.SearchObjects(ctx, anyCID, fs, []string{"attr"}, anyRequestCursor, anyValidSigner, anyValidOpts)
require.EqualError(t, err, "invalid filter #1: prohibited attribute $Object:objectID")
})
t.Run("empty", func(t *testing.T) {
var fs object.SearchFilters
fs.AddFilter("attr", "val", object.MatchStringEqual)
fs.AddFilter("", "val", object.SearchMatchType(rand.Int31()))
_, _, err := okConn.SearchObjects(ctx, anyCID, fs, []string{"attr"}, anyRequestCursor, anyValidSigner, anyValidOpts)
require.EqualError(t, err, "invalid filter #1: missing attribute")
})
})
t.Run("attributes", func(t *testing.T) {
for _, tc := range []struct {
Expand Down

0 comments on commit 66489a1

Please sign in to comment.