From 8e9694b8daaee810dbb32f226aa27bb0a5f81516 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 29 Mar 2023 16:01:06 +0200 Subject: [PATCH] use reva gateway client and mocks Signed-off-by: jkoberg --- services/graph/Makefile | 1 - .../graph/pkg/service/v0/application_test.go | 5 +- .../pkg/service/v0/approleassignments_test.go | 5 +- .../graph/pkg/service/v0/driveitems_test.go | 5 +- .../pkg/service/v0/educationclasses_test.go | 5 +- .../pkg/service/v0/educationschools_test.go | 6 +-- .../pkg/service/v0/educationuser_test.go | 5 +- services/graph/pkg/service/v0/graph.go | 51 ++----------------- services/graph/pkg/service/v0/graph_test.go | 5 +- services/graph/pkg/service/v0/groups_test.go | 5 +- services/graph/pkg/service/v0/option.go | 5 +- .../graph/pkg/service/v0/password_test.go | 5 +- services/graph/pkg/service/v0/users_test.go | 5 +- 13 files changed, 36 insertions(+), 72 deletions(-) diff --git a/services/graph/Makefile b/services/graph/Makefile index 382f03f125d..34176900550 100644 --- a/services/graph/Makefile +++ b/services/graph/Makefile @@ -25,7 +25,6 @@ include ../../.make/generate.mk .PHONY: ci-go-generate ci-go-generate: $(MOCKERY) # CI runs ci-node-generate automatically before this target - $(MOCKERY) --dir pkg/service/v0 --case underscore --name GatewayClient $(MOCKERY) --dir pkg/service/v0 --case underscore --name HTTPClient $(MOCKERY) --dir pkg/service/v0 --case underscore --name Publisher $(MOCKERY) --dir pkg/service/v0 --case underscore --name Permissions diff --git a/services/graph/pkg/service/v0/application_test.go b/services/graph/pkg/service/v0/application_test.go index 028ab59408c..851e2ebed3b 100644 --- a/services/graph/pkg/service/v0/application_test.go +++ b/services/graph/pkg/service/v0/application_test.go @@ -13,6 +13,7 @@ import ( libregraph "github.com/owncloud/libre-graph-api-go" "github.com/stretchr/testify/mock" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" @@ -33,7 +34,7 @@ var _ = Describe("Applications", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher roleService *mocks.RoleService identityBackend *identitymocks.Backend @@ -46,7 +47,7 @@ var _ = Describe("Applications", func() { identityBackend = &identitymocks.Backend{} roleService = &mocks.RoleService{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} rr = httptest.NewRecorder() ctx = context.Background() diff --git a/services/graph/pkg/service/v0/approleassignments_test.go b/services/graph/pkg/service/v0/approleassignments_test.go index 807bbc1ceda..7f37975a54d 100644 --- a/services/graph/pkg/service/v0/approleassignments_test.go +++ b/services/graph/pkg/service/v0/approleassignments_test.go @@ -10,6 +10,7 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" "github.com/golang/protobuf/ptypes/empty" . "github.com/onsi/ginkgo/v2" @@ -37,7 +38,7 @@ var _ = Describe("AppRoleAssignments", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher roleService *mocks.RoleService identityBackend *identitymocks.Backend @@ -56,7 +57,7 @@ var _ = Describe("AppRoleAssignments", func() { identityBackend = &identitymocks.Backend{} roleService = &mocks.RoleService{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} rr = httptest.NewRecorder() ctx = context.Background() diff --git a/services/graph/pkg/service/v0/driveitems_test.go b/services/graph/pkg/service/v0/driveitems_test.go index 2feb50ae54b..b830cb14a9c 100644 --- a/services/graph/pkg/service/v0/driveitems_test.go +++ b/services/graph/pkg/service/v0/driveitems_test.go @@ -11,6 +11,7 @@ import ( 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" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" @@ -34,7 +35,7 @@ var _ = Describe("Driveitems", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher identityBackend *identitymocks.Backend @@ -49,7 +50,7 @@ var _ = Describe("Driveitems", func() { rr = httptest.NewRecorder() identityBackend = &identitymocks.Backend{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} newGroup = libregraph.NewGroup() newGroup.SetMembersodataBind([]string{"/users/user1"}) newGroup.SetId("group1") diff --git a/services/graph/pkg/service/v0/educationclasses_test.go b/services/graph/pkg/service/v0/educationclasses_test.go index 4f8431862e3..50564cf8e99 100644 --- a/services/graph/pkg/service/v0/educationclasses_test.go +++ b/services/graph/pkg/service/v0/educationclasses_test.go @@ -11,6 +11,7 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -33,7 +34,7 @@ var _ = Describe("EducationClass", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher identityBackend *identitymocks.Backend identityEducationBackend *identitymocks.EducationBackend @@ -53,7 +54,7 @@ var _ = Describe("EducationClass", func() { identityEducationBackend = &identitymocks.EducationBackend{} identityBackend = &identitymocks.Backend{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} newClass = libregraph.NewEducationClass("math", "course") newClass.SetMembersodataBind([]string{"/users/user1"}) newClass.SetId("math") diff --git a/services/graph/pkg/service/v0/educationschools_test.go b/services/graph/pkg/service/v0/educationschools_test.go index 4a30b407f54..3bf5157faff 100644 --- a/services/graph/pkg/service/v0/educationschools_test.go +++ b/services/graph/pkg/service/v0/educationschools_test.go @@ -11,6 +11,7 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -19,7 +20,6 @@ import ( 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" @@ -36,7 +36,7 @@ var _ = Describe("Schools", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient identityEducationBackend *identitymocks.EducationBackend rr *httptest.ResponseRecorder @@ -51,7 +51,7 @@ var _ = Describe("Schools", func() { BeforeEach(func() { identityEducationBackend = &identitymocks.EducationBackend{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} newSchool = libregraph.NewEducationSchool() newSchool.SetId("school1") diff --git a/services/graph/pkg/service/v0/educationuser_test.go b/services/graph/pkg/service/v0/educationuser_test.go index 586c8abdb50..1d4a10407de 100644 --- a/services/graph/pkg/service/v0/educationuser_test.go +++ b/services/graph/pkg/service/v0/educationuser_test.go @@ -13,6 +13,7 @@ import ( typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rgrpc/status" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -38,7 +39,7 @@ var _ = Describe("EducationUsers", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher roleService *mocks.RoleService identityEducationBackend *identitymocks.EducationBackend @@ -57,7 +58,7 @@ var _ = Describe("EducationUsers", func() { identityEducationBackend = &identitymocks.EducationBackend{} roleService = &mocks.RoleService{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} rr = httptest.NewRecorder() ctx = context.Background() diff --git a/services/graph/pkg/service/v0/graph.go b/services/graph/pkg/service/v0/graph.go index 9a2db2421d2..e4fc0d8f5bc 100644 --- a/services/graph/pkg/service/v0/graph.go +++ b/services/graph/pkg/service/v0/graph.go @@ -25,51 +25,6 @@ import ( //go:generate make -C ../../.. generate -type GatewayClient = gateway.GatewayAPIClient - -/* -// GatewayClient is the subset of the gateway.GatewayAPIClient that is being used to interact with the gateway -type GatewayClient interface { - //gateway.GatewayAPIClient - - // Authenticates a user. - Authenticate(ctx context.Context, in *gateway.AuthenticateRequest, opts ...grpc.CallOption) (*gateway.AuthenticateResponse, error) - // Returns the home path for the given authenticated user. - // When a user has access to multiple storage providers, one of them is the home. - GetHome(ctx context.Context, in *provider.GetHomeRequest, opts ...grpc.CallOption) (*provider.GetHomeResponse, error) - // GetPath does a path lookup for a resource by ID - GetPath(ctx context.Context, in *provider.GetPathRequest, opts ...grpc.CallOption) (*provider.GetPathResponse, error) - // Returns a list of resource information - // for the provided reference. - // MUST return CODE_NOT_FOUND if the reference does not exists. - ListContainer(ctx context.Context, in *provider.ListContainerRequest, opts ...grpc.CallOption) (*provider.ListContainerResponse, error) - // Returns the resource information at the provided reference. - // MUST return CODE_NOT_FOUND if the reference does not exist. - Stat(ctx context.Context, in *provider.StatRequest, opts ...grpc.CallOption) (*provider.StatResponse, error) - // TouchFile allows to touch a file - TouchFile(ctx context.Context, req *provider.TouchFileRequest, opts ...grpc.CallOption) (*provider.TouchFileResponse, error) - // Initiates the upload of a file using an out-of-band data transfer mechanism. - InitiateFileUpload(ctx context.Context, in *provider.InitiateFileUploadRequest, opts ...grpc.CallOption) (*gateway.InitiateFileUploadResponse, error) - // Initiates the download of a file using an - // out-of-band data transfer mechanism. - InitiateFileDownload(ctx context.Context, in *provider.InitiateFileDownloadRequest, opts ...grpc.CallOption) (*gateway.InitiateFileDownloadResponse, error) - // Creates a storage space. - CreateStorageSpace(ctx context.Context, in *provider.CreateStorageSpaceRequest, opts ...grpc.CallOption) (*provider.CreateStorageSpaceResponse, error) - // Lists storage spaces. - ListStorageSpaces(ctx context.Context, in *provider.ListStorageSpacesRequest, opts ...grpc.CallOption) (*provider.ListStorageSpacesResponse, error) - // Updates a storage space. - UpdateStorageSpace(ctx context.Context, in *provider.UpdateStorageSpaceRequest, opts ...grpc.CallOption) (*provider.UpdateStorageSpaceResponse, error) - // Deletes a storage space. - DeleteStorageSpace(ctx context.Context, in *provider.DeleteStorageSpaceRequest, opts ...grpc.CallOption) (*provider.DeleteStorageSpaceResponse, error) - // Returns the quota available under the provided - // reference. - // MUST return CODE_NOT_FOUND if the reference does not exist - // MUST return CODE_RESOURCE_EXHAUSTED on exceeded quota limits. - GetQuota(ctx context.Context, in *gateway.GetQuotaRequest, opts ...grpc.CallOption) (*provider.GetQuotaResponse, error) - SetArbitraryMetadata(ctx context.Context, request *provider.SetArbitraryMetadataRequest, opts ...grpc.CallOption) (*provider.SetArbitraryMetadataResponse, error) -} -*/ - // Publisher is the interface for events publisher type Publisher interface { Publish(string, interface{}, ...mevents.PublishOption) error @@ -88,7 +43,7 @@ type HTTPClient interface { } // GetGatewayServiceClientFunc is a callback used to pass in a mock during testing -type GetGatewayServiceClientFunc func() (GatewayClient, error) +type GetGatewayServiceClientFunc func() (gateway.GatewayAPIClient, error) // RoleService is the interface used to access the role service type RoleService interface { @@ -105,7 +60,7 @@ type Graph struct { logger *log.Logger identityBackend identity.Backend identityEducationBackend identity.EducationBackend - gatewayClient GatewayClient + gatewayClient gateway.GatewayAPIClient roleService RoleService permissionsService Permissions spacePropertiesCache *ttlcache.Cache[string, interface{}] @@ -121,7 +76,7 @@ func (g Graph) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // GetGatewayClient returns a gateway client to talk to reva -func (g Graph) GetGatewayClient() GatewayClient { +func (g Graph) GetGatewayClient() gateway.GatewayAPIClient { return g.gatewayClient } diff --git a/services/graph/pkg/service/v0/graph_test.go b/services/graph/pkg/service/v0/graph_test.go index 717f6f6f8cc..7f63e681533 100644 --- a/services/graph/pkg/service/v0/graph_test.go +++ b/services/graph/pkg/service/v0/graph_test.go @@ -17,6 +17,7 @@ import ( revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rgrpc/status" "github.com/cs3org/reva/v2/pkg/utils" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -38,7 +39,7 @@ import ( var _ = Describe("Graph", func() { var ( svc service.Service - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher permissionService mocks.Permissions ctx context.Context @@ -63,7 +64,7 @@ var _ = Describe("Graph", func() { cfg.GRPCClientTLS = &shared.GRPCClientTLS{} _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} eventsPublisher = mocks.Publisher{} permissionService = mocks.Permissions{} svc, _ = service.NewService( diff --git a/services/graph/pkg/service/v0/groups_test.go b/services/graph/pkg/service/v0/groups_test.go index 16f7aa572e0..afc96961384 100644 --- a/services/graph/pkg/service/v0/groups_test.go +++ b/services/graph/pkg/service/v0/groups_test.go @@ -11,6 +11,7 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -36,7 +37,7 @@ var _ = Describe("Groups", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher identityBackend *identitymocks.Backend @@ -54,7 +55,7 @@ var _ = Describe("Groups", func() { eventsPublisher.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) identityBackend = &identitymocks.Backend{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} newGroup = libregraph.NewGroup() newGroup.SetMembersodataBind([]string{"/users/user1"}) newGroup.SetId("group1") diff --git a/services/graph/pkg/service/v0/option.go b/services/graph/pkg/service/v0/option.go index b159b806115..ccbde28b4d9 100644 --- a/services/graph/pkg/service/v0/option.go +++ b/services/graph/pkg/service/v0/option.go @@ -3,6 +3,7 @@ package svc import ( "net/http" + gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" "github.com/cs3org/reva/v2/pkg/events" "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/roles" @@ -21,7 +22,7 @@ type Options struct { Config *config.Config Middleware []func(http.Handler) http.Handler RequireAdminMiddleware func(http.Handler) http.Handler - GatewayClient GatewayClient + GatewayClient gateway.GatewayAPIClient IdentityBackend identity.Backend IdentityEducationBackend identity.EducationBackend RoleService RoleService @@ -71,7 +72,7 @@ func WithRequireAdminMiddleware(val func(http.Handler) http.Handler) Option { } // WithGatewayClient provides a function to set the gateway client option. -func WithGatewayClient(val GatewayClient) Option { +func WithGatewayClient(val gateway.GatewayAPIClient) Option { return func(o *Options) { o.GatewayClient = val } diff --git a/services/graph/pkg/service/v0/password_test.go b/services/graph/pkg/service/v0/password_test.go index 188e9e4def1..4a92da952ba 100644 --- a/services/graph/pkg/service/v0/password_test.go +++ b/services/graph/pkg/service/v0/password_test.go @@ -12,6 +12,7 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rgrpc/status" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-ldap/ldap/v3" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -28,7 +29,7 @@ import ( var _ = Describe("Users changing their own password", func() { var ( svc service.Service - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient ldapClient *mocks.Client ldapConfig config.LDAP identityBackend identity.Backend @@ -44,7 +45,7 @@ var _ = Describe("Users changing their own password", func() { cfg = defaults.FullDefaultConfig() cfg.TokenManager.JWTSecret = "loremipsum" - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} ldapClient = mockedLDAPClient() ldapConfig = config.LDAP{ diff --git a/services/graph/pkg/service/v0/users_test.go b/services/graph/pkg/service/v0/users_test.go index 95b50f6d684..4719f366e6f 100644 --- a/services/graph/pkg/service/v0/users_test.go +++ b/services/graph/pkg/service/v0/users_test.go @@ -14,6 +14,7 @@ import ( typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rgrpc/status" + cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks" "github.com/go-chi/chi/v5" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -41,7 +42,7 @@ var _ = Describe("Users", func() { svc service.Service ctx context.Context cfg *config.Config - gatewayClient *mocks.GatewayClient + gatewayClient *cs3mocks.GatewayAPIClient eventsPublisher mocks.Publisher roleService *mocks.RoleService identityBackend *identitymocks.Backend @@ -60,7 +61,7 @@ var _ = Describe("Users", func() { identityBackend = &identitymocks.Backend{} roleService = &mocks.RoleService{} - gatewayClient = &mocks.GatewayClient{} + gatewayClient = &cs3mocks.GatewayAPIClient{} rr = httptest.NewRecorder() ctx = context.Background()