Skip to content

Commit

Permalink
further mkcol unit tests (#3454)
Browse files Browse the repository at this point in the history
* further mkcol unit tests

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>

* Update internal/http/services/owncloud/ocdav/ocdav_blackbox_test.go

Co-authored-by: Michael Barz <[email protected]>

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
Co-authored-by: Michael Barz <[email protected]>
  • Loading branch information
butonic and micbar authored Nov 14, 2022
1 parent 6e34bf7 commit cd24894
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/dav-unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ https://github.com/cs3org/reva/pull/3441
https://github.com/cs3org/reva/pull/3443
https://github.com/cs3org/reva/pull/3445
https://github.com/cs3org/reva/pull/3447
https://github.com/cs3org/reva/pull/3454
14 changes: 11 additions & 3 deletions internal/http/services/owncloud/ocdav/mkcol.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package ocdav

import (
"context"
"errors"
"fmt"
"net/http"
"path"
Expand Down Expand Up @@ -117,6 +118,11 @@ func (s *svc) handleMkcol(ctx context.Context, w http.ResponseWriter, r *http.Re
case res.Status.Code == rpc.Code_CODE_OK:
w.WriteHeader(http.StatusCreated)
return 0, nil
case res.Status.Code == rpc.Code_CODE_NOT_FOUND:
// This should never happen because if the parent collection does not exist we should
// get a Code_CODE_FAILED_PRECONDITION. We play stupid and return what the response gave us
//lint:ignore ST1005 mimic the exact oc10 error message
return http.StatusNotFound, errors.New("Resource not found")
case res.Status.Code == rpc.Code_CODE_PERMISSION_DENIED:
// check if user has access to parent
sRes, err := s.gwClient.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{
Expand All @@ -130,9 +136,10 @@ func (s *svc) handleMkcol(ctx context.Context, w http.ResponseWriter, r *http.Re
// return not found error so we do not leak existence of a file
// TODO hide permission failed for users without access in every kind of request
// TODO should this be done in the driver?
return http.StatusNotFound, fmt.Errorf("Resource not found")
//lint:ignore ST1005 mimic the exact oc10 error message
return http.StatusNotFound, errors.New("Resource not found")
}
return http.StatusForbidden, fmt.Errorf(sRes.Status.Message)
return http.StatusForbidden, errors.New(sRes.Status.Message)
case res.Status.Code == rpc.Code_CODE_ABORTED:
return http.StatusPreconditionFailed, fmt.Errorf(res.Status.Message)
case res.Status.Code == rpc.Code_CODE_FAILED_PRECONDITION:
Expand All @@ -144,7 +151,8 @@ func (s *svc) handleMkcol(ctx context.Context, w http.ResponseWriter, r *http.Re
case res.Status.Code == rpc.Code_CODE_ALREADY_EXISTS:
// https://www.rfc-editor.org/rfc/rfc4918#section-9.3.1:
// 405 (Method Not Allowed) - MKCOL can only be executed on an unmapped URL.
return http.StatusMethodNotAllowed, fmt.Errorf("The resource you tried to create already exists")
//lint:ignore ST1005 mimic the exact oc10 error message
return http.StatusMethodNotAllowed, errors.New("The resource you tried to create already exists")
}
return rstatus.HTTPStatusFromCode(res.Status.Code), errtypes.NewErrtypeFromStatus(res.Status)
}
Loading

0 comments on commit cd24894

Please sign in to comment.