Skip to content

Commit

Permalink
fix: correct status code when move is denied (#4439)
Browse files Browse the repository at this point in the history
* fix: correct status code when move is denied

* test: fix unit tests

* Update changelog/unreleased/fix-statuscode-move-denied.md

Co-authored-by: Phil Davis <[email protected]>

---------

Co-authored-by: Phil Davis <[email protected]>
  • Loading branch information
micbar and phil-davis authored Dec 28, 2023
1 parent a725b31 commit 8e51f9a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-statuscode-move-denied.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fixed wrong status code when moving a file to a denied path

We fixed a bug when the status code 502 was returned when moving a file to a denied path. Status code 403 (forbidden) is now returned to be compatible with oc10.

https://github.com/cs3org/reva/pull/4439
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ func (s *service) Move(ctx context.Context, req *provider.MoveRequest) (*provide

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ var _ = Describe("Sharesstorageprovider", func() {
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))
Expect(res.Status.Code).To(Equal(rpc.Code_CODE_PERMISSION_DENIED))
})

It("refuses to move a file between shares resolving to the same space", func() {
Expand All @@ -826,7 +826,7 @@ var _ = Describe("Sharesstorageprovider", func() {
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))
Expect(res.Status.Code).To(Equal(rpc.Code_CODE_PERMISSION_DENIED))
})

It("moves a file", func() {
Expand Down
4 changes: 4 additions & 0 deletions internal/http/services/owncloud/ocdav/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ func (s *svc) handleMove(ctx context.Context, w http.ResponseWriter, r *http.Req
switch mRes.Status.Code {
case rpc.Code_CODE_ABORTED:
status = http.StatusPreconditionFailed
case rpc.Code_CODE_PERMISSION_DENIED:
status = http.StatusForbidden
// create oc10 compatible error message
m = "Destination directory is not writable"
case rpc.Code_CODE_UNIMPLEMENTED:
// We translate this into a Bad Gateway error as per https://www.rfc-editor.org/rfc/rfc4918#section-9.9.4
// > 502 (Bad Gateway) - This may occur when the destination is on another
Expand Down

0 comments on commit 8e51f9a

Please sign in to comment.