Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52f292c79d | ||
|
|
6d1d0590e2 | ||
|
|
6adfdf52e1 | ||
|
|
2f03cc7521 | ||
|
|
a9d040f438 | ||
|
|
56449b60c5 | ||
|
|
2e86d35ab4 | ||
|
|
084c971e08 | ||
|
|
6fb37a591e | ||
|
|
7c57cb63bd |
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -1,4 +1,4 @@
|
||||
Bugfix: Do not disable personal space on inconclusive permission check
|
||||
Bugfix: Keep personal space when Drives.Create permission check is inconclusive
|
||||
|
||||
When a user's role is (re-)assigned, both the proxy (on OIDC login) and the graph
|
||||
appRoleAssignment handler check the `Drives.Create` permission to decide whether to
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -1,4 +1,4 @@
|
||||
Enhancement Add vault themes
|
||||
Enhancement: Add vault themes
|
||||
|
||||
We've added new themes that are available in the vault. These new themes are intended to make a clear distinction between regular drives and vault.
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -4,4 +4,4 @@ We've added an optional `href` field to the `logo` theme configuration. When set
|
||||
clicking the topbar logo navigates to the configured URL instead of the default
|
||||
files navigation. When not set, the existing default behavior is unchanged.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/OCISDEV-950
|
||||
https://github.com/owncloud/ocis/pull/12529
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -11,4 +11,3 @@ not accepted by ownCloud Infinite Scale.
|
||||
The check is disabled by default (empty list) to preserve the existing behavior.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12634
|
||||
|
||||
@@ -16,7 +16,7 @@ var (
|
||||
// LatestTag is the latest released version plus the dev meta version.
|
||||
// Will be overwritten by the release pipeline
|
||||
// Needs a manual change for every tagged release
|
||||
LatestTag = "8.0.0+dev"
|
||||
LatestTag = "8.2.0-rc.1"
|
||||
|
||||
// Date indicates the build date.
|
||||
// This has been removed, it looks like you can only replace static strings with recent go versions
|
||||
|
||||
@@ -12,7 +12,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-19 03:23+0000\n"
|
||||
"POT-Creation-Date: 2026-07-10 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: 振东 刘, 2026\n"
|
||||
"Language-Team: Chinese Traditional (https://app.transifex.com/owncloud-org/teams/6149/zh-Hant/)\n"
|
||||
|
||||
@@ -13,7 +13,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-19 03:23+0000\n"
|
||||
"POT-Creation-Date: 2026-07-10 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: 振东 刘, 2026\n"
|
||||
"Language-Team: Chinese (China) (https://app.transifex.com/owncloud-org/teams/6149/zh_CN/)\n"
|
||||
|
||||
@@ -12,7 +12,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-16 03:22+0000\n"
|
||||
"POT-Creation-Date: 2026-07-07 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: Roman Perekhod, 2026\n"
|
||||
"Language-Team: Russian (https://app.transifex.com/owncloud-org/teams/6149/ru/)\n"
|
||||
|
||||
@@ -12,7 +12,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-20 03:19+0000\n"
|
||||
"POT-Creation-Date: 2026-07-10 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: 振东 刘, 2026\n"
|
||||
"Language-Team: Chinese Traditional (https://app.transifex.com/owncloud-org/teams/6149/zh-Hant/)\n"
|
||||
|
||||
@@ -13,7 +13,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-20 03:19+0000\n"
|
||||
"POT-Creation-Date: 2026-07-10 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: 振东 刘, 2026\n"
|
||||
"Language-Team: Chinese (https://app.transifex.com/owncloud-org/teams/6149/zh/)\n"
|
||||
|
||||
@@ -15,7 +15,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-20 03:19+0000\n"
|
||||
"POT-Creation-Date: 2026-07-10 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: 振东 刘, 2026\n"
|
||||
"Language-Team: Chinese (China) (https://app.transifex.com/owncloud-org/teams/6149/zh_CN/)\n"
|
||||
|
||||
@@ -15,7 +15,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-20 03:19+0000\n"
|
||||
"POT-Creation-Date: 2026-07-10 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: 振东 刘, 2026\n"
|
||||
"Language-Team: Chinese (Hong Kong) (https://app.transifex.com/owncloud-org/teams/6149/zh_HK/)\n"
|
||||
|
||||
@@ -14,7 +14,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-06-20 03:19+0000\n"
|
||||
"POT-Creation-Date: 2026-07-10 03:14+0000\n"
|
||||
"PO-Revision-Date: 2026-01-02 10:10+0000\n"
|
||||
"Last-Translator: 振东 刘, 2026\n"
|
||||
"Language-Team: Chinese (Taiwan) (https://app.transifex.com/owncloud-org/teams/6149/zh_TW/)\n"
|
||||
|
||||
@@ -1,332 +0,0 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
grpcmetadata "google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/owncloud/ocis/v2/services/webdav/pkg/constants"
|
||||
"github.com/owncloud/ocis/v2/services/webdav/pkg/net"
|
||||
"github.com/owncloud/ocis/v2/services/webdav/pkg/prop"
|
||||
"github.com/owncloud/ocis/v2/services/webdav/pkg/propfind"
|
||||
"github.com/owncloud/reva/v2/pkg/conversions"
|
||||
revactx "github.com/owncloud/reva/v2/pkg/ctx"
|
||||
"github.com/owncloud/reva/v2/pkg/permission"
|
||||
"github.com/owncloud/reva/v2/pkg/storagespace"
|
||||
"github.com/owncloud/reva/v2/pkg/utils"
|
||||
)
|
||||
|
||||
const propOcFavorite = "http://owncloud.org/ns/favorite"
|
||||
|
||||
// maxFavoriteContainers bounds how many ListContainer calls a single filter-files REPORT
|
||||
// will make (across all spaces and pagination pages) before giving up on collecting further
|
||||
// favorites. Without this, a user with a very large or deeply nested tree could turn a single
|
||||
// "list my favorites" request into an unbounded number of backend round-trips. Hitting the
|
||||
// limit returns whatever favorites were already found rather than failing the request.
|
||||
//
|
||||
// A var, not a const, so tests can lower it temporarily to exercise the cutoff without
|
||||
// needing to construct thousands of fake containers.
|
||||
var maxFavoriteContainers = 5000
|
||||
|
||||
// favoriteInfo holds a ResourceInfo and the resolved path for href construction.
|
||||
type favoriteInfo struct {
|
||||
info *provider.ResourceInfo
|
||||
// href-ready path relative to the space root, e.g. "Documents/notes.md"
|
||||
relativePath string
|
||||
// hrefPrefix is the DAV prefix for constructing hrefs, e.g.
|
||||
// "/dav/files/admin" for personal/share spaces or
|
||||
// "/dav/spaces/<storageId>$<spaceId>" for project spaces.
|
||||
hrefPrefix string
|
||||
}
|
||||
|
||||
// handleFilterFiles handles REPORT requests with oc:filter-files / oc:filter-rules.
|
||||
func (g Webdav) handleFilterFiles(w http.ResponseWriter, r *http.Request, ff *reportFilterFiles) {
|
||||
logger := g.log.SubloggerWithRequestID(r.Context())
|
||||
|
||||
if !ff.Rules.Favorite {
|
||||
// Only favorites filtering is supported; return empty 207.
|
||||
g.sendFavoritesResponse(nil, w, r)
|
||||
return
|
||||
}
|
||||
|
||||
t := r.Header.Get(revactx.TokenHeader)
|
||||
ctx := revactx.ContextSetToken(r.Context(), t)
|
||||
ctx = grpcmetadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)
|
||||
|
||||
gwClient, err := g.gatewaySelector.Next()
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("error selecting gateway client")
|
||||
renderError(w, r, errInternalError("could not get gateway client"))
|
||||
return
|
||||
}
|
||||
|
||||
// Get current user — needed both for CheckPermission (which reads the
|
||||
// user from the context) and for href construction later.
|
||||
whoAmI, err := gwClient.WhoAmI(ctx, &gatewayv1beta1.WhoAmIRequest{Token: t})
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("error getting current user")
|
||||
renderError(w, r, errInternalError("could not get current user"))
|
||||
return
|
||||
}
|
||||
if whoAmI.Status.Code != rpcv1beta1.Code_CODE_OK {
|
||||
logger.Error().Str("status", whoAmI.Status.Message).Msg("could not get current user")
|
||||
renderError(w, r, errInternalError("could not get current user"))
|
||||
return
|
||||
}
|
||||
ctx = revactx.ContextSetUser(ctx, whoAmI.User)
|
||||
username := whoAmI.User.Username
|
||||
|
||||
// Check permission
|
||||
ok, err := utils.CheckPermission(ctx, permission.ListFavorites, gwClient)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("error checking list favorites permission")
|
||||
renderError(w, r, errInternalError("error checking permission"))
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
logger.Debug().Msg("user not allowed to list favorites")
|
||||
renderError(w, r, errPermissionDenied("permission denied"))
|
||||
return
|
||||
}
|
||||
|
||||
// List user's storage spaces. ListStorageSpaces is paginated, so keep fetching pages
|
||||
// until the server reports no more are available — otherwise spaces beyond the first
|
||||
// page would be silently skipped.
|
||||
var storageSpaces []*provider.StorageSpace
|
||||
pageToken := ""
|
||||
for {
|
||||
spacesResp, err := gwClient.ListStorageSpaces(ctx, &provider.ListStorageSpacesRequest{
|
||||
Filters: []*provider.ListStorageSpacesRequest_Filter{
|
||||
{
|
||||
Type: provider.ListStorageSpacesRequest_Filter_TYPE_USER,
|
||||
Term: &provider.ListStorageSpacesRequest_Filter_Owner{
|
||||
Owner: whoAmI.User.Id,
|
||||
},
|
||||
},
|
||||
},
|
||||
PageToken: pageToken,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("error listing storage spaces")
|
||||
renderError(w, r, errInternalError("could not list storage spaces"))
|
||||
return
|
||||
}
|
||||
if spacesResp.Status.Code != rpcv1beta1.Code_CODE_OK {
|
||||
logger.Error().Str("status", spacesResp.Status.Message).Msg("could not list storage spaces")
|
||||
renderError(w, r, errInternalError("could not list storage spaces"))
|
||||
return
|
||||
}
|
||||
storageSpaces = append(storageSpaces, spacesResp.StorageSpaces...)
|
||||
if spacesResp.NextPageToken == "" {
|
||||
break
|
||||
}
|
||||
pageToken = spacesResp.NextPageToken
|
||||
}
|
||||
|
||||
// Build the /dav/files/<user> href prefix.
|
||||
// The frontend expects all hrefs under this prefix when it sends
|
||||
// REPORT to /dav/files/<user>. Project spaces are not addressable
|
||||
// under this path and are skipped for now.
|
||||
filesPrefix := path.Join("/dav/files", username)
|
||||
if strings.HasPrefix(r.URL.Path, "/remote.php/") {
|
||||
filesPrefix = path.Join("/remote.php/dav/files", username)
|
||||
}
|
||||
|
||||
// Collect favorites across personal and share spaces. visited is a shared budget of
|
||||
// remaining ListContainer calls (see maxFavoriteContainers) spent across every space,
|
||||
// not per space, so one space with a huge tree can't starve the others.
|
||||
var favorites []favoriteInfo
|
||||
visited := 0
|
||||
for _, space := range storageSpaces {
|
||||
if space.Root == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var pathPrefix string
|
||||
switch space.SpaceType {
|
||||
case "personal":
|
||||
pathPrefix = ""
|
||||
case "mountpoint", "grant":
|
||||
// Mounted shares appear under "Shares/<name>"
|
||||
name := space.Name
|
||||
if name == "" {
|
||||
name = space.Id.OpaqueId
|
||||
}
|
||||
pathPrefix = path.Join("Shares", name)
|
||||
default:
|
||||
// Project spaces and other types don't appear under
|
||||
// /dav/files/<user>/ — skip for now.
|
||||
continue
|
||||
}
|
||||
|
||||
g.collectFavorites(ctx, gwClient, &provider.Reference{ResourceId: space.Root}, pathPrefix, filesPrefix, &favorites, &visited)
|
||||
}
|
||||
|
||||
g.sendFavoritesResponse(favorites, w, r)
|
||||
}
|
||||
|
||||
// collectFavorites recursively walks a storage space, collecting resources that have the
|
||||
// oc:favorite metadata set. visited tracks how many ListContainer calls have been made so
|
||||
// far against the shared maxFavoriteContainers budget (see that const's doc comment); it's
|
||||
// checked before every call, including subsequent pages of the same container, since those
|
||||
// are just as costly on the backend as a fresh container.
|
||||
func (g Webdav) collectFavorites(
|
||||
ctx context.Context,
|
||||
client gatewayv1beta1.GatewayAPIClient,
|
||||
ref *provider.Reference,
|
||||
pathPrefix string,
|
||||
hrefPrefix string,
|
||||
results *[]favoriteInfo,
|
||||
visited *int,
|
||||
) {
|
||||
pageToken := ""
|
||||
for {
|
||||
if *visited >= maxFavoriteContainers {
|
||||
g.log.Warn().Int("limit", maxFavoriteContainers).Msg("favorites collection hit its container-visit limit; returning partial results")
|
||||
return
|
||||
}
|
||||
*visited++
|
||||
|
||||
resp, err := client.ListContainer(ctx, &provider.ListContainerRequest{
|
||||
Ref: ref,
|
||||
ArbitraryMetadataKeys: []string{propOcFavorite},
|
||||
PageToken: pageToken,
|
||||
})
|
||||
if err != nil {
|
||||
g.log.Error().Err(err).Msg("error listing container for favorites")
|
||||
return
|
||||
}
|
||||
if resp.Status.Code != rpcv1beta1.Code_CODE_OK {
|
||||
// Skip spaces/directories we cannot access
|
||||
return
|
||||
}
|
||||
|
||||
for _, info := range resp.Infos {
|
||||
childPath := path.Join(pathPrefix, info.GetName())
|
||||
|
||||
// Check if this resource is favorited
|
||||
if md := info.GetArbitraryMetadata().GetMetadata(); md != nil {
|
||||
if fav, ok := md[propOcFavorite]; ok && fav != "" && fav != "0" {
|
||||
*results = append(*results, favoriteInfo{
|
||||
info: info,
|
||||
relativePath: childPath,
|
||||
hrefPrefix: hrefPrefix,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Recurse into directories
|
||||
if info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
|
||||
g.collectFavorites(ctx, client, &provider.Reference{ResourceId: info.Id}, childPath, hrefPrefix, results, visited)
|
||||
}
|
||||
}
|
||||
|
||||
if resp.NextPageToken == "" {
|
||||
break
|
||||
}
|
||||
pageToken = resp.NextPageToken
|
||||
}
|
||||
}
|
||||
|
||||
// sendFavoritesResponse writes a 207 Multi-Status response for the collected favorites.
|
||||
func (g Webdav) sendFavoritesResponse(favorites []favoriteInfo, w http.ResponseWriter, r *http.Request) {
|
||||
logger := g.log.SubloggerWithRequestID(r.Context())
|
||||
|
||||
responses := make([]*propfind.ResponseXML, 0, len(favorites))
|
||||
for i := range favorites {
|
||||
resp := favoriteInfoToPropResponse(&favorites[i])
|
||||
responses = append(responses, resp)
|
||||
}
|
||||
|
||||
msr := propfind.NewMultiStatusResponseXML()
|
||||
msr.Responses = responses
|
||||
|
||||
msg, err := xml.Marshal(msr)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("error marshaling favorites response")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set(net.HeaderDav, "1, 3, extended-mkcol")
|
||||
w.Header().Set(net.HeaderContentType, "application/xml; charset=utf-8")
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
if _, err := w.Write(msg); err != nil {
|
||||
logger.Err(err).Msg("error writing favorites response")
|
||||
}
|
||||
}
|
||||
|
||||
// favoriteInfoToPropResponse converts a favoriteInfo into a ResponseXML.
|
||||
func favoriteInfoToPropResponse(fav *favoriteInfo) *propfind.ResponseXML {
|
||||
info := fav.info
|
||||
|
||||
response := &propfind.ResponseXML{
|
||||
Href: net.EncodePath(path.Join(fav.hrefPrefix, fav.relativePath)),
|
||||
Propstat: []propfind.PropstatXML{},
|
||||
}
|
||||
|
||||
propstatOK := propfind.PropstatXML{
|
||||
Status: "HTTP/1.1 200 OK",
|
||||
Prop: []prop.PropertyXML{},
|
||||
}
|
||||
|
||||
// oc:fileid
|
||||
if info.Id != nil {
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:fileid", storagespace.FormatResourceID(info.Id)))
|
||||
}
|
||||
|
||||
// oc:name
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:name", info.GetName()))
|
||||
|
||||
// d:getlastmodified
|
||||
if info.Mtime != nil {
|
||||
t := time.Unix(int64(info.Mtime.Seconds), int64(info.Mtime.Nanos))
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("d:getlastmodified", t.UTC().Format(constants.RFC1123)))
|
||||
}
|
||||
|
||||
// d:getcontenttype
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("d:getcontenttype", info.GetMimeType()))
|
||||
|
||||
// d:getetag
|
||||
if info.Etag != "" {
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("d:getetag", "\""+info.Etag+"\""))
|
||||
}
|
||||
|
||||
// oc:permissions
|
||||
if info.PermissionSet != nil {
|
||||
role := conversions.RoleFromResourcePermissions(info.PermissionSet, false)
|
||||
isDir := info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER
|
||||
wdp := role.WebDAVPermissions(isDir, false, false, false)
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:permissions", wdp))
|
||||
}
|
||||
|
||||
// oc:favorite (always "1" since we only return favorites)
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:favorite", "1"))
|
||||
|
||||
// d:resourcetype + size
|
||||
size := strconv.FormatUint(info.Size, 10)
|
||||
if info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Raw("d:resourcetype", "<d:collection/>"))
|
||||
propstatOK.Prop = append(propstatOK.Prop, prop.Escaped("oc:size", size))
|
||||
} else {
|
||||
propstatOK.Prop = append(propstatOK.Prop,
|
||||
prop.Escaped("d:resourcetype", ""),
|
||||
prop.Escaped("d:getcontentlength", size),
|
||||
)
|
||||
}
|
||||
|
||||
if len(propstatOK.Prop) > 0 {
|
||||
response.Propstat = append(response.Propstat, propstatOK)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
@@ -1,701 +0,0 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
|
||||
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
revactx "github.com/owncloud/reva/v2/pkg/ctx"
|
||||
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
|
||||
cs3mocks "github.com/owncloud/reva/v2/tests/cs3mocks/mocks"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/webdav/pkg/constants"
|
||||
"github.com/owncloud/ocis/v2/services/webdav/pkg/propfind"
|
||||
)
|
||||
|
||||
const filterFilesBody = `<?xml version="1.0" encoding="utf-8" ?>
|
||||
<oc:filter-files xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
|
||||
<d:prop>
|
||||
<d:getlastmodified />
|
||||
<d:getetag />
|
||||
<d:getcontenttype />
|
||||
<d:getcontentlength />
|
||||
<oc:size />
|
||||
<d:resourcetype />
|
||||
<oc:fileid />
|
||||
<oc:favorite />
|
||||
<oc:permissions />
|
||||
</d:prop>
|
||||
<oc:filter-rules>
|
||||
<oc:favorite>1</oc:favorite>
|
||||
</oc:filter-rules>
|
||||
</oc:filter-files>`
|
||||
|
||||
func setupTestWebdav(t *testing.T, gwClient *cs3mocks.GatewayAPIClient) Webdav {
|
||||
t.Helper()
|
||||
|
||||
pool.RemoveSelector("GatewaySelector" + "com.owncloud.api.gateway")
|
||||
selector := pool.GetSelector[gateway.GatewayAPIClient](
|
||||
"GatewaySelector",
|
||||
"com.owncloud.api.gateway",
|
||||
func(cc grpc.ClientConnInterface) gateway.GatewayAPIClient {
|
||||
return gwClient
|
||||
},
|
||||
)
|
||||
|
||||
return Webdav{
|
||||
log: log.NopLogger(),
|
||||
gatewaySelector: selector,
|
||||
}
|
||||
}
|
||||
|
||||
func newFilterFilesRequest(username string) *http.Request {
|
||||
r := httptest.NewRequest("REPORT", "/dav/files/"+username, strings.NewReader(filterFilesBody))
|
||||
ctx := context.WithValue(r.Context(), constants.ContextKeyID, username)
|
||||
ctx = revactx.ContextSetToken(ctx, "test-token")
|
||||
ctx = revactx.ContextSetUser(ctx, &userpb.User{
|
||||
Id: &userpb.UserId{OpaqueId: username},
|
||||
Username: username,
|
||||
})
|
||||
r.Header.Set(revactx.TokenHeader, "test-token")
|
||||
return r.WithContext(ctx)
|
||||
}
|
||||
|
||||
// mustParseFilterFiles reads and decodes a filter-files REPORT body, failing the test
|
||||
// immediately (rather than risking a nil-pointer panic later) if decoding errors or the
|
||||
// filter-files element wasn't present.
|
||||
func mustParseFilterFiles(t *testing.T, r *http.Request) *reportFilterFiles {
|
||||
t.Helper()
|
||||
|
||||
rep, err := readReport(r.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("readReport: %v", err)
|
||||
}
|
||||
if rep.FilterFiles == nil {
|
||||
t.Fatal("expected FilterFiles to be parsed")
|
||||
}
|
||||
return rep.FilterFiles
|
||||
}
|
||||
|
||||
func okStatus() *rpcv1beta1.Status {
|
||||
return &rpcv1beta1.Status{Code: rpcv1beta1.Code_CODE_OK}
|
||||
}
|
||||
|
||||
func mockCheckPermission(gwClient *cs3mocks.GatewayAPIClient, allowed bool) {
|
||||
code := rpcv1beta1.Code_CODE_OK
|
||||
if !allowed {
|
||||
code = rpcv1beta1.Code_CODE_PERMISSION_DENIED
|
||||
}
|
||||
gwClient.On("CheckPermission", mock.Anything, mock.Anything).Return(
|
||||
&permissions.CheckPermissionResponse{
|
||||
Status: &rpcv1beta1.Status{Code: code},
|
||||
}, nil,
|
||||
)
|
||||
}
|
||||
|
||||
func mockWhoAmI(gwClient *cs3mocks.GatewayAPIClient, username string) {
|
||||
gwClient.On("WhoAmI", mock.Anything, mock.Anything).Return(
|
||||
&gateway.WhoAmIResponse{
|
||||
Status: okStatus(),
|
||||
User: &userpb.User{
|
||||
Id: &userpb.UserId{OpaqueId: username},
|
||||
Username: username,
|
||||
},
|
||||
}, nil,
|
||||
)
|
||||
}
|
||||
|
||||
func mockListStorageSpaces(gwClient *cs3mocks.GatewayAPIClient, spaces []*provider.StorageSpace) {
|
||||
gwClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(
|
||||
&provider.ListStorageSpacesResponse{
|
||||
Status: okStatus(),
|
||||
StorageSpaces: spaces,
|
||||
}, nil,
|
||||
)
|
||||
}
|
||||
|
||||
func personalSpace(spaceID string) *provider.StorageSpace {
|
||||
return &provider.StorageSpace{
|
||||
Id: &provider.StorageSpaceId{OpaqueId: spaceID},
|
||||
SpaceType: "personal",
|
||||
Name: "alice",
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "storage1",
|
||||
SpaceId: spaceID,
|
||||
OpaqueId: spaceID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFilesReturns207WithFavorites(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
mockListStorageSpaces(gwClient, []*provider.StorageSpace{personalSpace("space1")})
|
||||
|
||||
// Root listing returns a favorited file and a non-favorited directory
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space1"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{
|
||||
{
|
||||
Id: &provider.ResourceId{StorageId: "storage1", SpaceId: "space1", OpaqueId: "file1"},
|
||||
Name: "favorite-doc.txt",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
MimeType: "text/plain",
|
||||
Size: 1024,
|
||||
Etag: "abc123",
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
PermissionSet: &provider.ResourcePermissions{
|
||||
GetPath: true,
|
||||
Stat: true,
|
||||
InitiateFileDownload: true,
|
||||
},
|
||||
ArbitraryMetadata: &provider.ArbitraryMetadata{
|
||||
Metadata: map[string]string{
|
||||
"http://owncloud.org/ns/favorite": "1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: &provider.ResourceId{StorageId: "storage1", SpaceId: "space1", OpaqueId: "dir1"},
|
||||
Name: "not-favorite-dir",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
Size: 0,
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
PermissionSet: &provider.ResourcePermissions{
|
||||
GetPath: true,
|
||||
Stat: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
// Recursive listing of the non-favorite directory: empty
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "dir1"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{},
|
||||
}, nil)
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
|
||||
// Re-create request since body was consumed
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Errorf("expected 207, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
|
||||
// Verify XML response
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal response: %v", err)
|
||||
}
|
||||
|
||||
if len(ms.Responses) != 1 {
|
||||
t.Fatalf("expected 1 favorite response, got %d", len(ms.Responses))
|
||||
}
|
||||
|
||||
// Check href — personal space favorites use /dav/files/<user>/ format
|
||||
expectedHref := "/dav/files/alice/favorite-doc.txt"
|
||||
if ms.Responses[0].Href != expectedHref {
|
||||
t.Errorf("expected href %q, got %q", expectedHref, ms.Responses[0].Href)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFilesEmptyFavoritesReturns207(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
mockListStorageSpaces(gwClient, []*provider.StorageSpace{personalSpace("space1")})
|
||||
|
||||
// Root listing: no files at all
|
||||
gwClient.On("ListContainer", mock.Anything, mock.Anything).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{},
|
||||
}, nil)
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Errorf("expected 207, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal response: %v", err)
|
||||
}
|
||||
|
||||
if len(ms.Responses) != 0 {
|
||||
t.Errorf("expected 0 responses, got %d", len(ms.Responses))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFilesReturnsBothFileAndFolderFavorites(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
mockListStorageSpaces(gwClient, []*provider.StorageSpace{personalSpace("space1")})
|
||||
|
||||
favMeta := &provider.ArbitraryMetadata{
|
||||
Metadata: map[string]string{propOcFavorite: "1"},
|
||||
}
|
||||
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space1"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{
|
||||
{
|
||||
Id: &provider.ResourceId{StorageId: "s1", SpaceId: "space1", OpaqueId: "file1"},
|
||||
Name: "my-file.pdf",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
Size: 2048,
|
||||
MimeType: "application/pdf",
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
ArbitraryMetadata: favMeta,
|
||||
},
|
||||
{
|
||||
Id: &provider.ResourceId{StorageId: "s1", SpaceId: "space1", OpaqueId: "dir1"},
|
||||
Name: "my-folder",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
Size: 4096,
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
ArbitraryMetadata: favMeta,
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
// Recursive listing of the favorite folder: empty
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "dir1"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{},
|
||||
}, nil)
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Fatalf("expected 207, got %d", rr.Code)
|
||||
}
|
||||
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
if len(ms.Responses) != 2 {
|
||||
t.Fatalf("expected 2 favorites (file + folder), got %d", len(ms.Responses))
|
||||
}
|
||||
|
||||
// Verify one is a file (no collection) and one is a folder (collection)
|
||||
var hasFile, hasFolder bool
|
||||
for _, resp := range ms.Responses {
|
||||
if strings.Contains(resp.Href, "my-file.pdf") {
|
||||
hasFile = true
|
||||
}
|
||||
if strings.Contains(resp.Href, "my-folder") {
|
||||
hasFolder = true
|
||||
}
|
||||
}
|
||||
if !hasFile {
|
||||
t.Error("expected file favorite in response")
|
||||
}
|
||||
if !hasFolder {
|
||||
t.Error("expected folder favorite in response")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFilesHrefsUseFilesPrefix(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "bob")
|
||||
mockListStorageSpaces(gwClient, []*provider.StorageSpace{personalSpace("space1")})
|
||||
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space1"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{
|
||||
{
|
||||
Id: &provider.ResourceId{StorageId: "s1", SpaceId: "space1", OpaqueId: "nested"},
|
||||
Name: "Documents",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
// Nested file that is a favorite
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "nested"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{
|
||||
{
|
||||
Id: &provider.ResourceId{StorageId: "s1", SpaceId: "space1", OpaqueId: "deepfile"},
|
||||
Name: "notes.md",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
Size: 512,
|
||||
MimeType: "text/markdown",
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
ArbitraryMetadata: &provider.ArbitraryMetadata{
|
||||
Metadata: map[string]string{propOcFavorite: "1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
r := newFilterFilesRequest("bob")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
r = newFilterFilesRequest("bob")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Fatalf("expected 207, got %d", rr.Code)
|
||||
}
|
||||
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
if len(ms.Responses) != 1 {
|
||||
t.Fatalf("expected 1 response, got %d", len(ms.Responses))
|
||||
}
|
||||
|
||||
// Personal space favorites use /dav/files/<user>/ format
|
||||
expectedHref := "/dav/files/bob/Documents/notes.md"
|
||||
if ms.Responses[0].Href != expectedHref {
|
||||
t.Errorf("expected href %q, got %q", expectedHref, ms.Responses[0].Href)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFilesSkipsProjectSpaces(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
|
||||
projectSpace := &provider.StorageSpace{
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "proj-space"},
|
||||
SpaceType: "project",
|
||||
Name: "Engineering",
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "storage1",
|
||||
SpaceId: "proj-space",
|
||||
OpaqueId: "proj-space",
|
||||
},
|
||||
}
|
||||
mockListStorageSpaces(gwClient, []*provider.StorageSpace{projectSpace})
|
||||
|
||||
// No ListContainer mock needed — project spaces should be skipped entirely
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Fatalf("expected 207, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
// Project spaces are not addressable under /dav/files/<user>/,
|
||||
// so they should be skipped — no favorites returned.
|
||||
if len(ms.Responses) != 0 {
|
||||
t.Fatalf("expected 0 responses (project spaces skipped), got %d", len(ms.Responses))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFilesPermissionDenied(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
mockCheckPermission(gwClient, false)
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusForbidden {
|
||||
t.Errorf("expected 403, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
// favoritedFile builds a minimal favorited ResourceInfo for pagination tests, where the
|
||||
// exact prop values don't matter beyond being present and distinguishable by name.
|
||||
func favoritedFile(storageID, spaceID, opaqueID, name string) *provider.ResourceInfo {
|
||||
return &provider.ResourceInfo{
|
||||
Id: &provider.ResourceId{StorageId: storageID, SpaceId: spaceID, OpaqueId: opaqueID},
|
||||
Name: name,
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
MimeType: "text/plain",
|
||||
Size: 1,
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
ArbitraryMetadata: &provider.ArbitraryMetadata{
|
||||
Metadata: map[string]string{propOcFavorite: "1"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// TestFilterFilesListStorageSpacesPagination regression-tests that ListStorageSpaces'
|
||||
// pagination is followed to completion: without it, favorites in any space beyond the
|
||||
// first page would be silently omitted.
|
||||
func TestFilterFilesListStorageSpacesPagination(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
|
||||
gwClient.On("ListStorageSpaces", mock.Anything, mock.MatchedBy(func(req *provider.ListStorageSpacesRequest) bool {
|
||||
return req.PageToken == ""
|
||||
})).Return(&provider.ListStorageSpacesResponse{
|
||||
Status: okStatus(),
|
||||
StorageSpaces: []*provider.StorageSpace{personalSpace("space1")},
|
||||
NextPageToken: "page2",
|
||||
}, nil)
|
||||
gwClient.On("ListStorageSpaces", mock.Anything, mock.MatchedBy(func(req *provider.ListStorageSpacesRequest) bool {
|
||||
return req.PageToken == "page2"
|
||||
})).Return(&provider.ListStorageSpacesResponse{
|
||||
Status: okStatus(),
|
||||
StorageSpaces: []*provider.StorageSpace{{
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "space2"},
|
||||
SpaceType: "personal",
|
||||
Name: "alice-second-space",
|
||||
Root: &provider.ResourceId{StorageId: "storage1", SpaceId: "space2", OpaqueId: "space2"},
|
||||
}},
|
||||
NextPageToken: "",
|
||||
}, nil)
|
||||
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space1"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{favoritedFile("storage1", "space1", "file-in-space1", "from-space-1.txt")},
|
||||
}, nil)
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space2"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{favoritedFile("storage1", "space2", "file-in-space2", "from-space-2.txt")},
|
||||
}, nil)
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Fatalf("expected 207, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
// A favorite from the second page of storage spaces must be present, proving
|
||||
// ListStorageSpaces' NextPageToken was followed rather than stopping at page one.
|
||||
if len(ms.Responses) != 2 {
|
||||
t.Fatalf("expected 2 favorites (one per space, across two ListStorageSpaces pages), got %d: %+v", len(ms.Responses), ms.Responses)
|
||||
}
|
||||
var hasSpace1, hasSpace2 bool
|
||||
for _, resp := range ms.Responses {
|
||||
if strings.Contains(resp.Href, "from-space-1.txt") {
|
||||
hasSpace1 = true
|
||||
}
|
||||
if strings.Contains(resp.Href, "from-space-2.txt") {
|
||||
hasSpace2 = true
|
||||
}
|
||||
}
|
||||
if !hasSpace1 || !hasSpace2 {
|
||||
t.Fatalf("expected favorites from both spaces, got hasSpace1=%v hasSpace2=%v (responses: %+v)", hasSpace1, hasSpace2, ms.Responses)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFilterFilesListContainerPagination regression-tests that a single container's own
|
||||
// ListContainer pagination is followed to completion, and that a subdirectory only present
|
||||
// on a later page is still recursed into — without it, favorites (and whole subtrees) beyond
|
||||
// a container's first page would be silently omitted.
|
||||
func TestFilterFilesListContainerPagination(t *testing.T) {
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
mockListStorageSpaces(gwClient, []*provider.StorageSpace{personalSpace("space1")})
|
||||
|
||||
// Root container, page 1: one favorite, plus a NextPageToken.
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space1" && req.PageToken == ""
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{favoritedFile("storage1", "space1", "file-a", "file-a.txt")},
|
||||
NextPageToken: "root-page2",
|
||||
}, nil)
|
||||
// Root container, page 2: another favorite, plus a subdirectory that only appears here.
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space1" && req.PageToken == "root-page2"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{
|
||||
favoritedFile("storage1", "space1", "file-b", "file-b.txt"),
|
||||
{
|
||||
Id: &provider.ResourceId{StorageId: "storage1", SpaceId: "space1", OpaqueId: "subdir"},
|
||||
Name: "subdir-from-page-2",
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
// The subdirectory discovered only on the root's second page.
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "subdir"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{favoritedFile("storage1", "space1", "file-c", "file-c.txt")},
|
||||
}, nil)
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Fatalf("expected 207, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
// file-a.txt (page 1), file-b.txt (page 2), and file-c.txt (inside the subdir only
|
||||
// discoverable via page 2) must all be present.
|
||||
if len(ms.Responses) != 3 {
|
||||
t.Fatalf("expected 3 favorites (2 from paginated root + 1 nested), got %d: %+v", len(ms.Responses), ms.Responses)
|
||||
}
|
||||
var hasA, hasB, hasC bool
|
||||
for _, resp := range ms.Responses {
|
||||
hasA = hasA || strings.Contains(resp.Href, "file-a.txt")
|
||||
hasB = hasB || strings.Contains(resp.Href, "file-b.txt")
|
||||
hasC = hasC || strings.Contains(resp.Href, "file-c.txt")
|
||||
}
|
||||
if !hasA || !hasB || !hasC {
|
||||
t.Fatalf("expected file-a.txt, file-b.txt and file-c.txt all present, got hasA=%v hasB=%v hasC=%v (responses: %+v)", hasA, hasB, hasC, ms.Responses)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFilterFilesRespectsContainerVisitLimit regression-tests maxFavoriteContainers: once the
|
||||
// budget of ListContainer calls is exhausted, collection must stop cleanly (partial results,
|
||||
// no error) rather than continuing to recurse without bound. The test lowers the limit to 2
|
||||
// so it can prove the cutoff with a small, fast fixture instead of a real 5000-container tree.
|
||||
func TestFilterFilesRespectsContainerVisitLimit(t *testing.T) {
|
||||
original := maxFavoriteContainers
|
||||
maxFavoriteContainers = 2
|
||||
t.Cleanup(func() { maxFavoriteContainers = original })
|
||||
|
||||
gwClient := cs3mocks.NewGatewayAPIClient(t)
|
||||
svc := setupTestWebdav(t, gwClient)
|
||||
|
||||
mockCheckPermission(gwClient, true)
|
||||
mockWhoAmI(gwClient, "alice")
|
||||
mockListStorageSpaces(gwClient, []*provider.StorageSpace{personalSpace("space1")})
|
||||
|
||||
// Root container: three non-favorited subdirectories, none of which are favorited
|
||||
// themselves — every favorite in this fixture lives one level deeper.
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "space1"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{
|
||||
{Id: &provider.ResourceId{StorageId: "storage1", SpaceId: "space1", OpaqueId: "dirA"}, Name: "dirA", Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000}},
|
||||
{Id: &provider.ResourceId{StorageId: "storage1", SpaceId: "space1", OpaqueId: "dirB"}, Name: "dirB", Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000}},
|
||||
{Id: &provider.ResourceId{StorageId: "storage1", SpaceId: "space1", OpaqueId: "dirC"}, Name: "dirC", Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, Mtime: &typesv1beta1.Timestamp{Seconds: 1700000000}},
|
||||
},
|
||||
}, nil)
|
||||
// Only dirA should ever be queried: the root call plus dirA's call already consume the
|
||||
// budget of 2, so dirB/dirC must never be requested. If the code regresses and queries
|
||||
// them anyway, this test fails via the mock's unexpected-call panic (no .On(...) is
|
||||
// registered for dirB/dirC), not just via the assertion below.
|
||||
gwClient.On("ListContainer", mock.Anything, mock.MatchedBy(func(req *provider.ListContainerRequest) bool {
|
||||
return req.Ref.ResourceId.OpaqueId == "dirA"
|
||||
})).Return(&provider.ListContainerResponse{
|
||||
Status: okStatus(),
|
||||
Infos: []*provider.ResourceInfo{favoritedFile("storage1", "space1", "deep-file", "deep-file.txt")},
|
||||
}, nil)
|
||||
|
||||
r := newFilterFilesRequest("alice")
|
||||
filterFiles := mustParseFilterFiles(t, r)
|
||||
r = newFilterFilesRequest("alice")
|
||||
rr := httptest.NewRecorder()
|
||||
svc.handleFilterFiles(rr, r, filterFiles)
|
||||
|
||||
// The request must still succeed (partial results), not error out.
|
||||
if rr.Code != http.StatusMultiStatus {
|
||||
t.Fatalf("expected 207 even when the container-visit limit is hit, got %d: %s", rr.Code, rr.Body.String())
|
||||
}
|
||||
|
||||
gwClient.AssertNumberOfCalls(t, "ListContainer", 2)
|
||||
|
||||
var ms propfind.MultiStatusResponseUnmarshalXML
|
||||
if err := xml.Unmarshal(rr.Body.Bytes(), &ms); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if len(ms.Responses) != 1 {
|
||||
t.Fatalf("expected exactly 1 favorite (from dirA, before the budget ran out), got %d: %+v", len(ms.Responses), ms.Responses)
|
||||
}
|
||||
if !strings.Contains(ms.Responses[0].Href, "deep-file.txt") {
|
||||
t.Fatalf("expected the favorite found in dirA, got %+v", ms.Responses[0])
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
const (
|
||||
elementNameSearchFiles = "search-files"
|
||||
elementNameFilterFiles = "filter-files"
|
||||
// TODO elementNameFilterFiles = "filter-files"
|
||||
)
|
||||
|
||||
// Search is the endpoint for retrieving search results for REPORT requests
|
||||
@@ -40,39 +40,35 @@ func (g Webdav) Search(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
switch {
|
||||
case rep.SearchFiles != nil:
|
||||
t := r.Header.Get(revactx.TokenHeader)
|
||||
ctx := revactx.ContextSetToken(r.Context(), t)
|
||||
ctx = metadata.Set(ctx, revactx.TokenHeader, t)
|
||||
|
||||
req := &searchsvc.SearchRequest{
|
||||
Query: rep.SearchFiles.Search.Pattern,
|
||||
PageSize: int32(rep.SearchFiles.Search.Limit),
|
||||
}
|
||||
|
||||
rsp, err := g.searchClient.Search(ctx, req)
|
||||
if err != nil {
|
||||
e := merrors.Parse(err.Error())
|
||||
switch e.Code {
|
||||
case http.StatusBadRequest:
|
||||
renderError(w, r, errBadRequest(e.Detail))
|
||||
default:
|
||||
// Don't reflect the raw upstream error back to the caller — same fix
|
||||
// as landed independently on master; keep it when merging.
|
||||
renderError(w, r, errInternalError("could not get search results"))
|
||||
}
|
||||
logger.Error().Err(err).Msg("could not get search results")
|
||||
return
|
||||
}
|
||||
|
||||
g.sendSearchResponse(rsp, w, r)
|
||||
case rep.FilterFiles != nil:
|
||||
g.handleFilterFiles(w, r, rep.FilterFiles)
|
||||
default:
|
||||
renderError(w, r, errBadRequest("missing search-files or filter-files element"))
|
||||
logger.Debug().Msg("error reading report: no recognized element")
|
||||
if rep.SearchFiles == nil {
|
||||
renderError(w, r, errBadRequest("missing search-files tag"))
|
||||
logger.Debug().Err(err).Msg("error reading report")
|
||||
return
|
||||
}
|
||||
|
||||
t := r.Header.Get(revactx.TokenHeader)
|
||||
ctx := revactx.ContextSetToken(r.Context(), t)
|
||||
ctx = metadata.Set(ctx, revactx.TokenHeader, t)
|
||||
|
||||
req := &searchsvc.SearchRequest{
|
||||
Query: rep.SearchFiles.Search.Pattern,
|
||||
PageSize: int32(rep.SearchFiles.Search.Limit),
|
||||
}
|
||||
|
||||
rsp, err := g.searchClient.Search(ctx, req)
|
||||
if err != nil {
|
||||
e := merrors.Parse(err.Error())
|
||||
switch e.Code {
|
||||
case http.StatusBadRequest:
|
||||
renderError(w, r, errBadRequest(e.Detail))
|
||||
default:
|
||||
renderError(w, r, errInternalError("could not get search results"))
|
||||
}
|
||||
logger.Error().Err(err).Msg("could not get search results")
|
||||
return
|
||||
}
|
||||
|
||||
g.sendSearchResponse(rsp, w, r)
|
||||
}
|
||||
|
||||
func (g Webdav) sendSearchResponse(rsp *searchsvc.SearchResponse, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -358,13 +354,15 @@ func readReport(r io.Reader) (rep *report, err error) {
|
||||
return nil, err
|
||||
}
|
||||
rep.SearchFiles = &repSF
|
||||
} else if v.Name.Local == elementNameFilterFiles {
|
||||
var repFF reportFilterFiles
|
||||
err = decoder.DecodeElement(&repFF, &v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rep.FilterFiles = &repFF
|
||||
/*
|
||||
} else if v.Name.Local == elementNameFilterFiles {
|
||||
var repFF reportFilterFiles
|
||||
err = decoder.DecodeElement(&repFF, &v)
|
||||
if err != nil {
|
||||
return nil, http.StatusBadRequest, err
|
||||
}
|
||||
rep.FilterFiles = &repFF
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
sonar.projectKey=owncloud_ocis
|
||||
sonar.organization=owncloud-1
|
||||
sonar.projectName=ocis
|
||||
sonar.projectVersion=8.0.0+dev
|
||||
sonar.projectVersion=8.2.0-rc.1
|
||||
sonar.host.url=https://sonarcloud.io
|
||||
|
||||
# =====================================================
|
||||
|
||||
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user