diff --git a/changelog/unreleased/fix-share-jail.md b/changelog/unreleased/fix-share-jail.md new file mode 100644 index 00000000000..ea49cdc46ee --- /dev/null +++ b/changelog/unreleased/fix-share-jail.md @@ -0,0 +1,5 @@ +Bugfix: fix share jail + +Make matching mountpoints deterministic by comparing whole path segments of mountpoints + +https://github.com/cs3org/reva/pull/4134 diff --git a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go index 4b1a12f8baf..dd71e0c4f5a 100644 --- a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go +++ b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go @@ -1059,7 +1059,8 @@ func (s *service) resolveAcceptedShare(ctx context.Context, ref *provider.Refere if receivedShare.State != collaboration.ShareState_SHARE_STATE_ACCEPTED { continue } - if strings.HasPrefix(strings.TrimPrefix(ref.Path, "./"), receivedShare.MountPoint.Path) { + //if strings.HasPrefix(strings.TrimPrefix(ref.Path, "./"), receivedShare.MountPoint.Path) { + if isMountPointForPath(receivedShare.MountPoint.Path, ref.Path) { return receivedShare, lsRes.Status, nil } } @@ -1069,6 +1070,17 @@ func (s *service) resolveAcceptedShare(ctx context.Context, ref *provider.Refere return nil, status.NewNotFound(ctx, "sharesstorageprovider: not found "+ref.String()), nil } +func isMountPointForPath(mountpoint, path string) bool { + requiredSegments := strings.Split(strings.TrimPrefix(mountpoint, "./"), "/") + pathSegments := strings.Split(strings.TrimPrefix(path, "./"), "/") + for i := range requiredSegments { + if pathSegments[i] != requiredSegments[i] { + return false + } + } + return true +} + func (s *service) rejectReceivedShare(ctx context.Context, receivedShare *collaboration.ReceivedShare) error { receivedShare.State = collaboration.ShareState_SHARE_STATE_REJECTED receivedShare.MountPoint = nil diff --git a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider_test.go b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider_test.go index eccb91b47f9..98db8349075 100644 --- a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider_test.go +++ b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider_test.go @@ -126,7 +126,7 @@ var _ = Describe("Sharesstorageprovider", func() { }, }, MountPoint: &sprovider.Reference{ - Path: "", + Path: "share1-shareddir", }, } @@ -188,7 +188,7 @@ var _ = Describe("Sharesstorageprovider", func() { gatewayClient.On("Stat", mock.Anything, mock.AnythingOfType("*providerv1beta1.StatRequest")).Return( func(_ context.Context, req *sprovider.StatRequest, _ ...grpc.CallOption) *sprovider.StatResponse { switch req.Ref.GetPath() { - case "./share1-shareddir": + case "./share1-shareddir", "./share1-shareddir (1)": return &sprovider.StatResponse{ Status: status.NewOK(context.Background()), Info: &sprovider.ResourceInfo{ @@ -435,6 +435,21 @@ var _ = Describe("Sharesstorageprovider", func() { Expect(res.Info.Size).To(Equal(uint64(100))) }) + It("stats the correct share in the share jail", func() { + BaseShare.MountPoint.Path = "share1-shareddir" + BaseShareTwo.MountPoint.Path = "share1-shareddir (1)" + statReq := ShareJailStatRequest + statReq.Ref.Path = "./share1-shareddir (1)" + res, err := s.Stat(ctx, statReq) + Expect(err).ToNot(HaveOccurred()) + Expect(res).ToNot(BeNil()) + Expect(res.Status.Code).To(Equal(rpc.Code_CODE_OK)) + Expect(res.Info).ToNot(BeNil()) + Expect(res.Info.Type).To(Equal(sprovider.ResourceType_RESOURCE_TYPE_CONTAINER)) + Expect(res.Info.Path).To(Equal("share1-shareddir")) + Expect(res.Info.Size).To(Equal(uint64(100))) + }) + It("stats a shares folder", func() { statReq := BaseStatRequest res, err := s.Stat(ctx, statReq)