From 153502189d993ce48a2a11b19e08fc2e31dc0ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Thu, 19 Sep 2024 10:51:28 +0200 Subject: [PATCH 1/2] fix: return 404 code if file isn't found on CheckFileInfo request --- .../collaboration/pkg/connector/fileconnector.go | 4 ++++ .../pkg/connector/fileconnector_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index a934fb5f2e5..ab4121956ed 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -1058,6 +1058,10 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse, Str("StatusCode", statRes.GetStatus().GetCode().String()). Str("StatusMsg", statRes.GetStatus().GetMessage()). Msg("CheckFileInfo: stat failed with unexpected status") + + if statRes.GetStatus().GetCode() == rpcv1beta1.Code_CODE_NOT_FOUND { + return NewResponse(404), nil + } return NewResponse(500), nil } diff --git a/services/collaboration/pkg/connector/fileconnector_test.go b/services/collaboration/pkg/connector/fileconnector_test.go index 8dfa4961f57..e676ea17421 100644 --- a/services/collaboration/pkg/connector/fileconnector_test.go +++ b/services/collaboration/pkg/connector/fileconnector_test.go @@ -1634,6 +1634,19 @@ var _ = Describe("FileConnector", func() { Expect(response.Body).To(BeNil()) }) + It("Stat fails status not found", func() { + ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx) + + gatewayClient.On("Stat", mock.Anything, mock.Anything).Times(1).Return(&providerv1beta1.StatResponse{ + Status: status.NewNotFound(ctx, "something not found"), + }, nil) + + response, err := fc.CheckFileInfo(ctx) + Expect(err).ToNot(HaveOccurred()) + Expect(response.Status).To(Equal(404)) + Expect(response.Body).To(BeNil()) + }) + It("Stat success", func() { ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx) u := &userv1beta1.User{ From 2bcc769168de70f2c008d3f85eab8414d840f2d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Thu, 19 Sep 2024 13:41:33 +0200 Subject: [PATCH 2/2] chore: add changelog entry --- changelog/unreleased/collaboration-fileinfo-error-code.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/collaboration-fileinfo-error-code.md diff --git a/changelog/unreleased/collaboration-fileinfo-error-code.md b/changelog/unreleased/collaboration-fileinfo-error-code.md new file mode 100644 index 00000000000..f76ac0b1605 --- /dev/null +++ b/changelog/unreleased/collaboration-fileinfo-error-code.md @@ -0,0 +1,5 @@ +Bugfix: CheckFileInfo will return a 404 error if the target file isn't found + +Previously, the request failed with a 500 error code, but it it will fail with a 404 error code + +https://github.com/owncloud/ocis/pull/10112