Skip to content

Commit

Permalink
Change invalid move detection to cover corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Oct 26, 2023
1 parent 3849686 commit fe4384d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,6 @@ func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provide
Interface("destination", req.Destination).
Msg("sharesstorageprovider: Got Move request")

if !utils.ResourceIDEqual(req.Source.ResourceId, req.Destination.ResourceId) {
return &provider.MoveResponse{
Status: status.NewUnimplemented(ctx, nil, "sharesstorageprovider: can not move between shares"),
}, nil
}

// TODO moving inside a shared tree should just be a forward of the move
// but when do we rename a mounted share? Does that request even hit us?
// - the registry needs to invalidate the alias
Expand Down Expand Up @@ -650,6 +644,12 @@ func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provide
}, nil
}

if dstReceivedShare.Share.Id.OpaqueId != srcReceivedShare.Share.Id.OpaqueId {
return &provider.MoveResponse{
Status: status.NewUnimplemented(ctx, nil, "sharesstorageprovider: can not move between shares"),
}, nil
}

gatewayClient, err := s.gatewaySelector.Next()
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ var _ = Describe("Sharesstorageprovider", func() {
OpaqueId: "shareid",
},
ResourceId: &sprovider.ResourceId{
StorageId: "share1-storageid",
SpaceId: "share1-storageid",
StorageId: "storageid",
SpaceId: "storageid",
OpaqueId: "shareddir",
},
Permissions: &collaboration.SharePermissions{
Expand All @@ -102,20 +102,20 @@ var _ = Describe("Sharesstorageprovider", func() {
},
},
MountPoint: &sprovider.Reference{
Path: "oldname",
Path: "share1-shareddir",
},
}

BaseShareTwo = &collaboration.ReceivedShare{
State: collaboration.ShareState_SHARE_STATE_ACCEPTED,
Share: &collaboration.Share{
Id: &collaboration.ShareId{
OpaqueId: "shareidtwo",
OpaqueId: "shareid2",
},
ResourceId: &sprovider.ResourceId{
StorageId: "share1-storageid",
SpaceId: "share1-storageid",
OpaqueId: "shareddir",
StorageId: "storageid",
SpaceId: "storageid",
OpaqueId: "shareddir2",
},
Permissions: &collaboration.SharePermissions{
Permissions: &sprovider.ResourcePermissions{
Expand All @@ -126,7 +126,7 @@ var _ = Describe("Sharesstorageprovider", func() {
},
},
MountPoint: &sprovider.Reference{
Path: "share1-shareddir",
Path: "share2-shareddir2",
},
}

Expand Down Expand Up @@ -298,6 +298,12 @@ var _ = Describe("Sharesstorageprovider", func() {
})
}
return resp
case utils.ResourceIDEqual(req.Ref.ResourceId, BaseShareTwo.Share.ResourceId):
resp := &sprovider.ListContainerResponse{
Status: status.NewOK(context.Background()),
Infos: []*sprovider.ResourceInfo{},
}
return resp
case utils.ResourceIDEqual(req.Ref.ResourceId, BaseShareTwo.Share.ResourceId):
return &sprovider.ListContainerResponse{
Status: status.NewOK(context.Background()),
Expand Down Expand Up @@ -772,11 +778,11 @@ var _ = Describe("Sharesstorageprovider", func() {
req := &sprovider.MoveRequest{
Source: &sprovider.Reference{
ResourceId: ShareJail,
Path: "./oldname",
Path: "./share1-shareddir",
},
Destination: &sprovider.Reference{
ResourceId: ShareJail,
Path: "./newname",
Path: "./share1-shareddir-renamed",
},
}
res, err := s.Move(ctx, req)
Expand All @@ -790,17 +796,37 @@ var _ = Describe("Sharesstorageprovider", func() {
It("refuses to move a file between shares", func() {
req := &sprovider.MoveRequest{
Source: &sprovider.Reference{
Path: "/shares/share1-shareddir/share1-shareddir-file",
ResourceId: ShareJail,
Path: "./share1-shareddir/share1-shareddir-file",
},
Destination: &sprovider.Reference{
Path: "/shares/share2-shareddir/share2-shareddir-file",
ResourceId: ShareJail,
Path: "./share2-shareddir2/share1-shareddir-file",
},
}
res, err := s.Move(ctx, req)
gatewayClient.AssertNotCalled(GinkgoT(), "Move", mock.Anything, mock.Anything)
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(res.Status.Code).To(Equal(rpc.Code_CODE_INVALID_ARGUMENT))
Expect(res.Status.Code).To(Equal(rpc.Code_CODE_UNIMPLEMENTED))
})

It("refuses to move a file between shares resolving to the same space", func() {
req := &sprovider.MoveRequest{
Source: &sprovider.Reference{
ResourceId: ShareJail,
Path: "./share1-shareddir/share1-shareddir-file",
},
Destination: &sprovider.Reference{
ResourceId: ShareJail,
Path: "./share2-shareddir2/share1-shareddir-file",
},
}
res, err := s.Move(ctx, req)
gatewayClient.AssertNotCalled(GinkgoT(), "Move", mock.Anything, mock.Anything)
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(res.Status.Code).To(Equal(rpc.Code_CODE_UNIMPLEMENTED))
})

It("moves a file", func() {
Expand Down

0 comments on commit fe4384d

Please sign in to comment.