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

Fix cs3 share manager filter #2853

Merged
merged 1 commit into from
May 11, 2022
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
5 changes: 5 additions & 0 deletions changelog/unreleased/filter-cs3-share-manager-listing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Filter CS3 share manager listing

The cs3 share manager driver now correctly filters user and group queries

https://github.com/cs3org/reva/pull/2853
9 changes: 6 additions & 3 deletions pkg/share/manager/cs3/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,14 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
}

for _, id := range receivedIds {
share, err := m.getShareByID(ctx, id)
s, err := m.getShareByID(ctx, id)
if err != nil {
return nil, err
}
metadata, err := m.downloadMetadata(ctx, share)
if !share.MatchesFilters(s, filters) {
continue
}
metadata, err := m.downloadMetadata(ctx, s)
if err != nil {
if _, ok := err.(errtypes.NotFound); !ok {
return nil, err
Expand All @@ -419,7 +422,7 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
}
}
result = append(result, &collaboration.ReceivedShare{
Share: share,
Share: s,
State: metadata.State,
MountPoint: metadata.MountPoint,
})
Expand Down
87 changes: 87 additions & 0 deletions pkg/share/manager/cs3/cs3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var _ = Describe("Manager", func() {
grantee *userpb.User
share *collaboration.Share
share2 *collaboration.Share
groupShare *collaboration.Share
grant *collaboration.ShareGrant
ctx context.Context
granteeCtx context.Context
Expand Down Expand Up @@ -134,6 +135,27 @@ var _ = Describe("Manager", func() {
},
},
}
groupShare = &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: "3"},
ResourceId: &provider.ResourceId{OpaqueId: "ijkl"},
Owner: user.GetId(),
Grantee: &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_GROUP,
Id: &provider.Grantee_GroupId{GroupId: &groupv1beta1.GroupId{
Idp: "localhost:1111",
OpaqueId: "users",
}},
},
Permissions: &collaboration.SharePermissions{
Permissions: &provider.ResourcePermissions{
GetPath: true,
InitiateFileDownload: true,
ListFileVersions: true,
ListContainer: true,
Stat: true,
},
},
}
ctx = ctxpkg.ContextSetUser(context.Background(), user)
granteeCtx = ctxpkg.ContextSetUser(context.Background(), grantee)
})
Expand Down Expand Up @@ -171,6 +193,9 @@ var _ = Describe("Manager", func() {
data, err = json.Marshal(share2)
Expect(err).ToNot(HaveOccurred())
storage.On("SimpleDownload", mock.Anything, path.Join("shares", share2.Id.OpaqueId)).Return(data, nil)
data, err = json.Marshal(groupShare)
Expect(err).ToNot(HaveOccurred())
storage.On("SimpleDownload", mock.Anything, path.Join("shares", groupShare.Id.OpaqueId)).Return(data, nil)
data, err = json.Marshal(&cs3.ReceivedShareMetadata{
State: collaboration.ShareState_SHARE_STATE_PENDING,
MountPoint: &provider.Reference{
Expand Down Expand Up @@ -448,6 +473,68 @@ var _ = Describe("Manager", func() {
Expect(rshare.MountPoint.Path).To(Equal("path"))
})
})

Context("with a received user and group share", func() {
BeforeEach(func() {
indexer.On("FindBy", mock.Anything,
mock.MatchedBy(func(input indexerpkg.Field) bool {
return input.Name == "GranteeId" && input.Value == granteeFn
}),
).
Return([]string{share.Id.OpaqueId}, nil)

indexer.On("FindBy", mock.Anything,
mock.MatchedBy(func(input indexerpkg.Field) bool {
return input.Name == "GranteeId" && input.Value == groupFn
}),
).
Return([]string{groupShare.Id.OpaqueId}, nil)

indexer.On("FindBy", mock.Anything,
mock.MatchedBy(func(input indexerpkg.Field) bool {
return input.Name == "GranteeId"
}),
).
Return([]string{}, nil)
})

It("list the user and shares", func() {
rshares, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{})
Expect(err).ToNot(HaveOccurred())
Expect(rshares).ToNot(BeNil())
Expect(len(rshares)).To(Equal(2))
})

It("list only the user when user filter is given ", func() {
rshares, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{
{
Type: collaboration.Filter_TYPE_GRANTEE_TYPE,
Term: &collaboration.Filter_GranteeType{
GranteeType: provider.GranteeType_GRANTEE_TYPE_USER,
},
},
})
Expect(err).ToNot(HaveOccurred())
Expect(rshares).ToNot(BeNil())
Expect(len(rshares)).To(Equal(1))
Expect(rshares[0].Share.Grantee.Type).To(Equal(provider.GranteeType_GRANTEE_TYPE_USER))
})

It("list only the group when group filter is given ", func() {
rshares, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{
{
Type: collaboration.Filter_TYPE_GRANTEE_TYPE,
Term: &collaboration.Filter_GranteeType{
GranteeType: provider.GranteeType_GRANTEE_TYPE_GROUP,
},
},
})
Expect(err).ToNot(HaveOccurred())
Expect(rshares).ToNot(BeNil())
Expect(len(rshares)).To(Equal(1))
Expect(rshares[0].Share.Grantee.Type).To(Equal(provider.GranteeType_GRANTEE_TYPE_GROUP))
})
})
})

Describe("GetReceivedShare", func() {
Expand Down