From dd9414ba7ccc50ae2e9646e9393cff9f5fade8e8 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Mon, 19 Jul 2021 18:30:14 +0200 Subject: [PATCH] properly handle upload to non existent folders --- changelog/unreleased/upload-nonexistent-parent.md | 5 +++++ internal/http/services/owncloud/ocdav/put.go | 8 ++++++-- internal/http/services/owncloud/ocdav/tus.go | 4 ++++ tests/acceptance/expected-failures-on-OCIS-storage.md | 10 ---------- tests/acceptance/expected-failures-on-S3NG-storage.md | 10 ---------- 5 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 changelog/unreleased/upload-nonexistent-parent.md diff --git a/changelog/unreleased/upload-nonexistent-parent.md b/changelog/unreleased/upload-nonexistent-parent.md new file mode 100644 index 0000000000..9d24d8f2b1 --- /dev/null +++ b/changelog/unreleased/upload-nonexistent-parent.md @@ -0,0 +1,5 @@ +Bugfix: Fix response code when folder doesnt exist on upload + +When a new file was uploaded to a non existent folder the response code was incorrect. + +https://github.com/cs3org/reva/pull/1901 diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index 3873f74826..ed2b539db9 100644 --- a/internal/http/services/owncloud/ocdav/put.go +++ b/internal/http/services/owncloud/ocdav/put.go @@ -224,15 +224,19 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ } if uRes.Status.Code != rpc.Code_CODE_OK { - if uRes.Status.Code == rpc.Code_CODE_PERMISSION_DENIED { + switch uRes.Status.Code { + case rpc.Code_CODE_PERMISSION_DENIED: w.WriteHeader(http.StatusForbidden) b, err := Marshal(exception{ code: SabredavPermissionDenied, message: "permission denied: you have no permission to upload content", }) HandleWebdavError(&log, w, b, err) + case rpc.Code_CODE_NOT_FOUND: + w.WriteHeader(http.StatusConflict) + default: + HandleErrorStatus(&log, w, uRes.Status) } - HandleErrorStatus(&log, w, uRes.Status) return } diff --git a/internal/http/services/owncloud/ocdav/tus.go b/internal/http/services/owncloud/ocdav/tus.go index 91c07e7bec..454878c24c 100644 --- a/internal/http/services/owncloud/ocdav/tus.go +++ b/internal/http/services/owncloud/ocdav/tus.go @@ -155,6 +155,10 @@ func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http. } if uRes.Status.Code != rpc.Code_CODE_OK { + if uRes.Status.Code == rpc.Code_CODE_NOT_FOUND { + w.WriteHeader(http.StatusPreconditionFailed) + return + } HandleErrorStatus(&log, w, uRes.Status) return } diff --git a/tests/acceptance/expected-failures-on-OCIS-storage.md b/tests/acceptance/expected-failures-on-OCIS-storage.md index a47390e80f..8fab03e8cd 100644 --- a/tests/acceptance/expected-failures-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-on-OCIS-storage.md @@ -50,18 +50,12 @@ Basic file management like up and download, move, copy, properties, quota, trash - [apiWebdavUpload2/uploadFileUsingNewChunking.feature:169](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload2/uploadFileUsingNewChunking.feature#L169) - [apiWebdavUpload2/uploadFileUsingNewChunking.feature:170](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload2/uploadFileUsingNewChunking.feature#L170) -#### [PUT request with missing parent must return status code 409](https://github.com/owncloud/ocis/issues/824) -- [apiWebdavUpload1/uploadFile.feature:112](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L112) -- [apiWebdavUpload1/uploadFile.feature:113](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L113) - #### [invalid file-names should not be created using the TUS protocol](https://github.com/owncloud/ocis/issues/1001) - [apiWebdavUploadTUS/uploadFile.feature:143](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L143) - [apiWebdavUploadTUS/uploadFile.feature:144](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L144) -- [apiWebdavUploadTUS/uploadFile.feature:145](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L145) - [apiWebdavUploadTUS/uploadFile.feature:146](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L146) - [apiWebdavUploadTUS/uploadFile.feature:147](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L147) - [apiWebdavUploadTUS/uploadFile.feature:148](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L148) -- [apiWebdavUploadTUS/uploadFile.feature:149](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L149) - [apiWebdavUploadTUS/uploadFile.feature:150](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L150) #### [upload a file using TUS resource URL as an other user should not work](https://github.com/owncloud/ocis/issues/1141) @@ -1229,10 +1223,6 @@ _ocdav: api compatibility, return correct status code_ _ocdav: api compatibility, return correct status code_ - [apiAuthWebDav/webDavPOSTAuth.feature:40](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPOSTAuth.feature#L40) Scenario: send POST requests to another user's webDav endpoints as normal user -#### [PUT request with missing parent must return status code 409](https://github.com/owncloud/ocis/issues/824) -_ocdav: api compatibility, return correct status code_ -- [apiAuthWebDav/webDavPUTAuth.feature:40](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPUTAuth.feature#L40) Scenario: send PUT requests to another user's webDav endpoints as normal user - #### [Using double slash in URL to access a folder gives 501 and other status codes](https://github.com/owncloud/ocis/issues/1667) - [apiAuthWebDav/webDavSpecialURLs.feature:24](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavSpecialURLs.feature#L24) - [apiAuthWebDav/webDavSpecialURLs.feature:69](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavSpecialURLs.feature#L69) diff --git a/tests/acceptance/expected-failures-on-S3NG-storage.md b/tests/acceptance/expected-failures-on-S3NG-storage.md index 24379de835..2451e4a632 100644 --- a/tests/acceptance/expected-failures-on-S3NG-storage.md +++ b/tests/acceptance/expected-failures-on-S3NG-storage.md @@ -55,18 +55,12 @@ Basic file management like up and download, move, copy, properties, quota, trash - [apiWebdavUpload2/uploadFileUsingNewChunking.feature:169](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload2/uploadFileUsingNewChunking.feature#L169) - [apiWebdavUpload2/uploadFileUsingNewChunking.feature:170](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload2/uploadFileUsingNewChunking.feature#L170) -#### [PUT request with missing parent must return status code 409](https://github.com/owncloud/ocis/issues/824) -- [apiWebdavUpload1/uploadFile.feature:112](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L112) -- [apiWebdavUpload1/uploadFile.feature:113](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L113) - #### [invalid file-names should not be created using the TUS protocol](https://github.com/owncloud/ocis/issues/1001) - [apiWebdavUploadTUS/uploadFile.feature:143](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L135) - [apiWebdavUploadTUS/uploadFile.feature:144](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L136) -- [apiWebdavUploadTUS/uploadFile.feature:145](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L137) - [apiWebdavUploadTUS/uploadFile.feature:146](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L138) - [apiWebdavUploadTUS/uploadFile.feature:147](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L139) - [apiWebdavUploadTUS/uploadFile.feature:148](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L140) -- [apiWebdavUploadTUS/uploadFile.feature:149](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L141) - [apiWebdavUploadTUS/uploadFile.feature:150](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L142) #### [upload a file using TUS resource URL as an other user should not work](https://github.com/owncloud/ocis/issues/1141) @@ -1232,10 +1226,6 @@ _ocdav: api compatibility, return correct status code_ _ocdav: api compatibility, return correct status code_ - [apiAuthWebDav/webDavPOSTAuth.feature:40](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPOSTAuth.feature#L40) Scenario: send POST requests to another user's webDav endpoints as normal user -#### [PUT request with missing parent must return status code 409](https://github.com/owncloud/ocis/issues/824) -_ocdav: api compatibility, return correct status code_ -- [apiAuthWebDav/webDavPUTAuth.feature:40](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavPUTAuth.feature#L40) Scenario: send PUT requests to another user's webDav endpoints as normal user - #### [Using double slash in URL to access a folder gives 501 and other status codes](https://github.com/owncloud/ocis/issues/1667) - [apiAuthWebDav/webDavSpecialURLs.feature:24](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavSpecialURLs.feature#L24) - [apiAuthWebDav/webDavSpecialURLs.feature:69](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiAuthWebDav/webDavSpecialURLs.feature#L69)