Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
131 lines
4.1 KiB
Go
131 lines
4.1 KiB
Go
package svc_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"time"
|
|
|
|
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
|
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
|
|
"github.com/cs3org/reva/v2/pkg/utils"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
libregraph "github.com/owncloud/libre-graph-api-go"
|
|
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
|
"github.com/owncloud/ocis/v2/services/graph/mocks"
|
|
"github.com/owncloud/ocis/v2/services/graph/pkg/config"
|
|
"github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults"
|
|
identitymocks "github.com/owncloud/ocis/v2/services/graph/pkg/identity/mocks"
|
|
service "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0"
|
|
)
|
|
|
|
type itemsList struct {
|
|
Value []*libregraph.DriveItem
|
|
}
|
|
|
|
var _ = Describe("Driveitems", func() {
|
|
var (
|
|
svc service.Service
|
|
ctx context.Context
|
|
cfg *config.Config
|
|
gatewayClient *mocks.GatewayClient
|
|
eventsPublisher mocks.Publisher
|
|
identityBackend *identitymocks.Backend
|
|
|
|
rr *httptest.ResponseRecorder
|
|
|
|
newGroup *libregraph.Group
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
eventsPublisher.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
|
|
|
rr = httptest.NewRecorder()
|
|
|
|
identityBackend = &identitymocks.Backend{}
|
|
gatewayClient = &mocks.GatewayClient{}
|
|
newGroup = libregraph.NewGroup()
|
|
newGroup.SetMembersodataBind([]string{"/users/user1"})
|
|
newGroup.SetId("group1")
|
|
|
|
rr = httptest.NewRecorder()
|
|
ctx = context.Background()
|
|
|
|
cfg = defaults.FullDefaultConfig()
|
|
cfg.Identity.LDAP.CACert = "" // skip the startup checks, we don't use LDAP at all in this tests
|
|
cfg.TokenManager.JWTSecret = "loremipsum"
|
|
cfg.Commons = &shared.Commons{}
|
|
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
|
|
|
|
_ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...)
|
|
svc = service.NewService(
|
|
service.Config(cfg),
|
|
service.WithGatewayClient(gatewayClient),
|
|
service.EventsPublisher(&eventsPublisher),
|
|
service.WithIdentityBackend(identityBackend),
|
|
)
|
|
})
|
|
|
|
Describe("GetRootDriveChildren", func() {
|
|
It("handles failing GetHome", func() {
|
|
gatewayClient.On("GetHome", mock.Anything, mock.Anything).Return(&provider.GetHomeResponse{
|
|
Status: status.NewNotFound(ctx, "not found"),
|
|
}, nil)
|
|
|
|
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drive/root/children", nil)
|
|
svc.GetRootDriveChildren(rr, r)
|
|
Expect(rr.Code).To(Equal(http.StatusNotFound))
|
|
})
|
|
|
|
It("handles failing GetHome", func() {
|
|
gatewayClient.On("GetHome", mock.Anything, mock.Anything).Return(&provider.GetHomeResponse{
|
|
Status: status.NewInternal(ctx, "not found"),
|
|
}, nil)
|
|
|
|
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drive/root/children", nil)
|
|
svc.GetRootDriveChildren(rr, r)
|
|
Expect(rr.Code).To(Equal(http.StatusInternalServerError))
|
|
})
|
|
|
|
It("succeeds", func() {
|
|
mtime := time.Now()
|
|
gatewayClient.On("GetHome", mock.Anything, mock.Anything).Return(&provider.GetHomeResponse{
|
|
Status: status.NewOK(ctx),
|
|
Path: "/",
|
|
}, nil)
|
|
gatewayClient.On("ListContainer", mock.Anything, mock.Anything).Return(&provider.ListContainerResponse{
|
|
Status: status.NewOK(ctx),
|
|
Infos: []*provider.ResourceInfo{
|
|
{
|
|
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
|
Id: &provider.ResourceId{StorageId: "storageid", SpaceId: "spaceid", OpaqueId: "opaqueid"},
|
|
Etag: "etag",
|
|
Mtime: utils.TimeToTS(mtime),
|
|
},
|
|
},
|
|
}, nil)
|
|
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drive/root/children", nil)
|
|
svc.GetRootDriveChildren(rr, r)
|
|
Expect(rr.Code).To(Equal(http.StatusOK))
|
|
data, err := io.ReadAll(rr.Body)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
res := itemsList{}
|
|
|
|
err = json.Unmarshal(data, &res)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(len(res.Value)).To(Equal(1))
|
|
Expect(res.Value[0].GetLastModifiedDateTime().Equal(mtime)).To(BeTrue())
|
|
Expect(res.Value[0].GetETag()).To(Equal("etag"))
|
|
Expect(res.Value[0].GetId()).To(Equal("storageid$spaceid!opaqueid"))
|
|
})
|
|
})
|
|
})
|