Merge pull request #11516 from 2403905/issue/OCISDEV-176

fix: [full-ci][OCISDEV-176] Tolerate the empty request body for WebDAV operations
This commit is contained in:
Roman Perekhod authored and GitHub committed 2025-07-14 15:27:19 +02:00
commit 90acfc4943
9 files changed
+34 -15

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
Bugfix: Tolerating the empty request body for WebDAV
Tolerating the empty request body for WebDAV operations like MKCOL, DELETE, MOVE, COPY.
https://github.com/owncloud/ocis/pull/11516
https://github.com/owncloud/ocis/issues/10809
+1 -1
View File
@@ -66,7 +66,7 @@ require (
github.com/open-policy-agent/opa v1.6.0
github.com/orcaman/concurrent-map v1.0.0
github.com/owncloud/libre-graph-api-go v1.0.5-0.20250217093259-fa3804be6c27
github.com/owncloud/reva/v2 v2.0.0-20250714075639-4eba70f12b9f
github.com/owncloud/reva/v2 v2.0.0-20250714122755-7cec7b87d4f9
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.12
github.com/prometheus/client_golang v1.22.0
+2 -2
View File
@@ -871,8 +871,8 @@ github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CF
github.com/ovh/go-ovh v1.1.0/go.mod h1:AxitLZ5HBRPyUd+Zl60Ajaag+rNTdVXWIkzfrVuTXWA=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20250217093259-fa3804be6c27 h1:ID8s5lGBntmrlI6TbDAjTzRyHucn3bVM2wlW+HBplv4=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20250217093259-fa3804be6c27/go.mod h1:+gT+x62AS9u2Farh9wE2uYmgdvTg0MQgsSI62D+xoRg=
github.com/owncloud/reva/v2 v2.0.0-20250714075639-4eba70f12b9f h1:i/oR0jU6a0NNkiKhTmVhEYo2XqV9DuCoYzc1dJa6GjE=
github.com/owncloud/reva/v2 v2.0.0-20250714075639-4eba70f12b9f/go.mod h1:hbank0QHAsLCaK2KKbnmhkgbCA1d8GLAWDAZEV09/Uk=
github.com/owncloud/reva/v2 v2.0.0-20250714122755-7cec7b87d4f9 h1:YiIMNov8f/gY9mfVkfb9RUN1iTo7DPjLxW/4XN1vcN4=
github.com/owncloud/reva/v2 v2.0.0-20250714122755-7cec7b87d4f9/go.mod h1:hbank0QHAsLCaK2KKbnmhkgbCA1d8GLAWDAZEV09/Uk=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pablodz/inotifywaitgo v0.0.7 h1:1ii49dGBnRn0t1Sz7RGZS6/NberPEDQprwKHN49Bv6U=
@@ -56,7 +56,7 @@ func (s *svc) handlePathCopy(w http.ResponseWriter, r *http.Request, ns string)
ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(r.Context(), "copy")
defer span.End()
if r.Body != http.NoBody {
if !isBodyEmpty(r) {
w.WriteHeader(http.StatusUnsupportedMediaType)
b, err := errors.Marshal(http.StatusUnsupportedMediaType, "body must be empty", "", "")
errors.HandleWebdavError(appctx.GetLogger(ctx), w, b, err)
@@ -331,7 +331,7 @@ func (s *svc) handleSpacesCopy(w http.ResponseWriter, r *http.Request, spaceID s
ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(r.Context(), "spaces_copy")
defer span.End()
if r.Body != http.NoBody {
if !isBodyEmpty(r) {
w.WriteHeader(http.StatusUnsupportedMediaType)
b, err := errors.Marshal(http.StatusUnsupportedMediaType, "body must be empty", "", "")
errors.HandleWebdavError(appctx.GetLogger(ctx), w, b, err)
@@ -39,7 +39,7 @@ func (s *svc) handlePathDelete(w http.ResponseWriter, r *http.Request, ns string
ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(ctx, "path_delete")
defer span.End()
if r.Body != http.NoBody {
if !isBodyEmpty(r) {
return http.StatusUnsupportedMediaType, errors.New("body must be empty")
}
@@ -126,7 +126,7 @@ func (s *svc) handleSpacesDelete(w http.ResponseWriter, r *http.Request, spaceID
ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(ctx, "spaces_delete")
defer span.End()
if r.Body != http.NoBody {
if !isBodyEmpty(r) {
return http.StatusUnsupportedMediaType, errors.New("body must be empty")
}
@@ -107,9 +107,7 @@ func (s *svc) handleSpacesMkCol(w http.ResponseWriter, r *http.Request, spaceID
}
func (s *svc) handleMkcol(ctx context.Context, w http.ResponseWriter, r *http.Request, parentRef, childRef *provider.Reference, log zerolog.Logger) (status int, err error) {
if r.Body != http.NoBody {
// We currently do not support extended mkcol https://datatracker.ietf.org/doc/rfc5689/
// TODO let clients send a body with properties to set on the new resource
if !isBodyEmpty(r) {
return http.StatusUnsupportedMediaType, fmt.Errorf("extended-mkcol not supported")
}
@@ -42,7 +42,7 @@ func (s *svc) handlePathMove(w http.ResponseWriter, r *http.Request, ns string)
ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(r.Context(), "move")
defer span.End()
if r.Body != http.NoBody {
if !isBodyEmpty(r) {
w.WriteHeader(http.StatusUnsupportedMediaType)
b, err := errors.Marshal(http.StatusUnsupportedMediaType, "body must be empty", "", "")
errors.HandleWebdavError(appctx.GetLogger(ctx), w, b, err)
@@ -106,7 +106,7 @@ func (s *svc) handleSpacesMove(w http.ResponseWriter, r *http.Request, srcSpaceI
ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(r.Context(), "spaces_move")
defer span.End()
if r.Body != http.NoBody {
if !isBodyEmpty(r) {
w.WriteHeader(http.StatusUnsupportedMediaType)
b, err := errors.Marshal(http.StatusUnsupportedMediaType, "body must be empty", "", "")
errors.HandleWebdavError(appctx.GetLogger(ctx), w, b, err)
@@ -20,6 +20,7 @@ package ocdav
import (
"context"
"io"
"net/http"
"path"
"strings"
@@ -29,6 +30,8 @@ import (
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/jellydator/ttlcache/v2"
"github.com/mitchellh/mapstructure"
"github.com/owncloud/reva/v2/internal/http/services/owncloud/ocdav/config"
"github.com/owncloud/reva/v2/internal/http/services/owncloud/ocdav/net"
"github.com/owncloud/reva/v2/pkg/appctx"
@@ -42,8 +45,6 @@ import (
"github.com/owncloud/reva/v2/pkg/storage/favorite/registry"
"github.com/owncloud/reva/v2/pkg/storage/utils/templates"
"github.com/owncloud/reva/v2/pkg/utils"
"github.com/jellydator/ttlcache/v2"
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
@@ -399,3 +400,17 @@ func (s *svc) referenceIsChildOf(ctx context.Context, selector pool.Selectable[g
func filename(p string) string {
return strings.Trim(path.Base(p), "/")
}
// isBodyEmpty checks if the request body is empty.
// Tolerate the EOF error when reading the body, which is expected when the body is empty.
// The extended mkcol https://datatracker.ietf.org/doc/rfc5689/ is not supported.
func isBodyEmpty(r *http.Request) bool {
if r.Body != nil && r.Body != http.NoBody {
buf := make([]byte, 0)
_, err := r.Body.Read(buf)
if err != io.EOF {
return false
}
}
return true
}
+1 -1
View File
@@ -1205,7 +1205,7 @@ github.com/orcaman/concurrent-map
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20250217093259-fa3804be6c27
## explicit; go 1.18
github.com/owncloud/libre-graph-api-go
# github.com/owncloud/reva/v2 v2.0.0-20250714075639-4eba70f12b9f
# github.com/owncloud/reva/v2 v2.0.0-20250714122755-7cec7b87d4f9
## explicit; go 1.24
github.com/owncloud/reva/v2/cmd/revad/internal/grace
github.com/owncloud/reva/v2/cmd/revad/runtime