From 468362aac4cf3fb54883d09f291f75860928fea0 Mon Sep 17 00:00:00 2001 From: JMboya <44696487+JeffMboya@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:36:12 +0300 Subject: [PATCH] MG-2193 - Generate mocks for proto interface (#2324) Signed-off-by: JeffMboya --- .github/workflows/check-generated-files.yml | 3 + .github/workflows/tests.yml | 1 + Makefile | 3 +- auth/api/grpc/endpoint_test.go | 2 +- auth/mocks/auth_client.go | 1226 ++++++++++++++++++- auth/spicedb/policies.go | 6 +- bootstrap/postgres/configs_test.go | 6 +- consumers/notifiers/api/endpoint_test.go | 26 +- http/api/endpoint_test.go | 7 +- invitations/service_test.go | 5 +- mqtt/handler_test.go | 9 +- pkg/sdk/go/message_test.go | 4 +- readers/api/endpoint_test.go | 5 +- things/service_test.go | 8 +- .golangci.yml => tools/config/.golangci.yml | 0 tools/config/boilerplate.txt | 3 + tools/config/mockery.yaml | 15 + tools/mqtt-bench/bench.go | 53 +- twins/api/http/endpoint_states_test.go | 42 +- twins/api/http/endpoint_twins_test.go | 35 +- twins/service_test.go | 27 +- users/service_test.go | 15 +- ws/adapter_test.go | 20 +- 23 files changed, 1330 insertions(+), 191 deletions(-) rename .golangci.yml => tools/config/.golangci.yml (100%) create mode 100644 tools/config/boilerplate.txt create mode 100644 tools/config/mockery.yaml diff --git a/.github/workflows/check-generated-files.yml b/.github/workflows/check-generated-files.yml index bca413a0c7..921e216e7c 100644 --- a/.github/workflows/check-generated-files.yml +++ b/.github/workflows/check-generated-files.yml @@ -76,6 +76,7 @@ jobs: - "twins/states.go" - "twins/service.go" - "journal/journal.go" + - "magistrala/auth_grpc.pb.go" - name: Set up protoc if: steps.changes.outputs.proto == 'true' @@ -160,6 +161,7 @@ jobs: mv ./twins/mocks/cache.go ./twins/mocks/cache.go.tmp mv ./journal/mocks/repository.go ./journal/mocks/repository.go.tmp mv ./journal/mocks/service.go ./journal/mocks/service.go.tmp + mv ./auth/mocks/auth_client.go ./auth/mocks/auth_client.go.tmp make mocks @@ -213,3 +215,4 @@ jobs: check_mock_changes ./twins/mocks/cache.go "Twins Cache ./twins/mocks/cache.go" check_mock_changes ./journal/mocks/repository.go "Journal Repository ./journal/mocks/repository.go" check_mock_changes ./journal/mocks/service.go "Journal Service ./journal/mocks/service.go" + check_mock_changes ./auth/mocks/auth_client.go "Auth Service Client ./auth/mocks/auth_client.go" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0ca91ac2e6..049b8a104c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,6 +27,7 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: v1.59.1 + args: --config ./tools/config/.golangci.yml - name: Build all Binaries run: | diff --git a/Makefile b/Makefile index 62c2143e6f..8738ccb70d 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ FILTERED_SERVICES = $(filter-out $(RUN_ADDON_ARGS), $(SERVICES)) all: $(SERVICES) -.PHONY: all $(SERVICES) dockers dockers_dev latest release run run_addons grpc_mtls_certs check_mtls check_certs test_api +.PHONY: all $(SERVICES) dockers dockers_dev latest release run run_addons grpc_mtls_certs check_mtls check_certs test_api mocks clean: rm -rf ${BUILD_DIR} @@ -121,6 +121,7 @@ install: mocks: @which mockery > /dev/null || go install github.com/vektra/mockery/v2@$(MOCKERY_VERSION) @unset MOCKERY_VERSION && go generate ./... + mockery --config ./tools/config/mockery.yaml DIRS = consumers readers postgres internal opcua diff --git a/auth/api/grpc/endpoint_test.go b/auth/api/grpc/endpoint_test.go index 541f34a0e3..0221fbaf2f 100644 --- a/auth/api/grpc/endpoint_test.go +++ b/auth/api/grpc/endpoint_test.go @@ -1012,7 +1012,7 @@ func TestListPermissions(t *testing.T) { } func TestDeleteEntityPolicies(t *testing.T) { - conn, err := grpc.Dial(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err)) client := grpcapi.NewClient(conn, time.Second) diff --git a/auth/mocks/auth_client.go b/auth/mocks/auth_client.go index 981edecbfa..37134ba5da 100644 --- a/auth/mocks/auth_client.go +++ b/auth/mocks/auth_client.go @@ -1,132 +1,1228 @@ // Copyright (c) Abstract Machines + // SPDX-License-Identifier: Apache-2.0 +// Code generated by mockery v2.43.2. DO NOT EDIT. + package mocks import ( context "context" - "github.com/absmach/magistrala" - svcerr "github.com/absmach/magistrala/pkg/errors/service" - "github.com/stretchr/testify/mock" - "google.golang.org/grpc" -) + grpc "google.golang.org/grpc" -const InvalidValue = "invalid" + magistrala "github.com/absmach/magistrala" -var _ magistrala.AuthServiceClient = (*AuthClient)(nil) + mock "github.com/stretchr/testify/mock" +) +// AuthClient is an autogenerated mock type for the AuthServiceClient type type AuthClient struct { mock.Mock } -func (m *AuthClient) Issue(ctx context.Context, in *magistrala.IssueReq, opts ...grpc.CallOption) (*magistrala.Token, error) { - ret := m.Called(ctx, in) - if in.GetUserId() == InvalidValue || in.GetUserId() == "" { - return &magistrala.Token{}, svcerr.ErrAuthentication +type AuthClient_Expecter struct { + mock *mock.Mock +} + +func (_m *AuthClient) EXPECT() *AuthClient_Expecter { + return &AuthClient_Expecter{mock: &_m.Mock} +} + +// AddPolicies provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) AddPolicies(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption) (*magistrala.AddPoliciesRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for AddPolicies") + } + + var r0 *magistrala.AddPoliciesRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) (*magistrala.AddPoliciesRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) *magistrala.AddPoliciesRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.AddPoliciesRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_AddPolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddPolicies' +type AuthClient_AddPolicies_Call struct { + *mock.Call +} + +// AddPolicies is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.AddPoliciesReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) AddPolicies(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_AddPolicies_Call { + return &AuthClient_AddPolicies_Call{Call: _e.mock.On("AddPolicies", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_AddPolicies_Call) Run(run func(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption)) *AuthClient_AddPolicies_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.AddPoliciesReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_AddPolicies_Call) Return(_a0 *magistrala.AddPoliciesRes, _a1 error) *AuthClient_AddPolicies_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_AddPolicies_Call) RunAndReturn(run func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) (*magistrala.AddPoliciesRes, error)) *AuthClient_AddPolicies_Call { + _c.Call.Return(run) + return _c +} + +// AddPolicy provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for AddPolicy") + } + + var r0 *magistrala.AddPolicyRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) (*magistrala.AddPolicyRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) *magistrala.AddPolicyRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.AddPolicyRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_AddPolicy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddPolicy' +type AuthClient_AddPolicy_Call struct { + *mock.Call +} + +// AddPolicy is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.AddPolicyReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) AddPolicy(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_AddPolicy_Call { + return &AuthClient_AddPolicy_Call{Call: _e.mock.On("AddPolicy", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_AddPolicy_Call) Run(run func(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption)) *AuthClient_AddPolicy_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.AddPolicyReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_AddPolicy_Call) Return(_a0 *magistrala.AddPolicyRes, _a1 error) *AuthClient_AddPolicy_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_AddPolicy_Call) RunAndReturn(run func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) (*magistrala.AddPolicyRes, error)) *AuthClient_AddPolicy_Call { + _c.Call.Return(run) + return _c +} + +// Authorize provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Authorize") } - return ret.Get(0).(*magistrala.Token), ret.Error(1) + var r0 *magistrala.AuthorizeRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) (*magistrala.AuthorizeRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) *magistrala.AuthorizeRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.AuthorizeRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_Authorize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Authorize' +type AuthClient_Authorize_Call struct { + *mock.Call +} + +// Authorize is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.AuthorizeReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) Authorize(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_Authorize_Call { + return &AuthClient_Authorize_Call{Call: _e.mock.On("Authorize", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_Authorize_Call) Run(run func(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption)) *AuthClient_Authorize_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.AuthorizeReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_Authorize_Call) Return(_a0 *magistrala.AuthorizeRes, _a1 error) *AuthClient_Authorize_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (m *AuthClient) Refresh(ctx context.Context, in *magistrala.RefreshReq, opts ...grpc.CallOption) (*magistrala.Token, error) { - ret := m.Called(ctx, in) - if in.GetRefreshToken() == InvalidValue || in.GetRefreshToken() == "" { - return &magistrala.Token{}, svcerr.ErrAuthentication +func (_c *AuthClient_Authorize_Call) RunAndReturn(run func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) (*magistrala.AuthorizeRes, error)) *AuthClient_Authorize_Call { + _c.Call.Return(run) + return _c +} + +// CountObjects provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CountObjects") + } + + var r0 *magistrala.CountObjectsRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) (*magistrala.CountObjectsRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) *magistrala.CountObjectsRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.CountObjectsRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) } - return ret.Get(0).(*magistrala.Token), ret.Error(1) + return r0, r1 } -func (m *AuthClient) Identify(ctx context.Context, in *magistrala.IdentityReq, opts ...grpc.CallOption) (*magistrala.IdentityRes, error) { - ret := m.Called(ctx, in) - if in.GetToken() == InvalidValue || in.GetToken() == "" { - return &magistrala.IdentityRes{}, svcerr.ErrAuthentication +// AuthClient_CountObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountObjects' +type AuthClient_CountObjects_Call struct { + *mock.Call +} + +// CountObjects is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.CountObjectsReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) CountObjects(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_CountObjects_Call { + return &AuthClient_CountObjects_Call{Call: _e.mock.On("CountObjects", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_CountObjects_Call) Run(run func(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption)) *AuthClient_CountObjects_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.CountObjectsReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_CountObjects_Call) Return(_a0 *magistrala.CountObjectsRes, _a1 error) *AuthClient_CountObjects_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_CountObjects_Call) RunAndReturn(run func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) (*magistrala.CountObjectsRes, error)) *AuthClient_CountObjects_Call { + _c.Call.Return(run) + return _c +} + +// CountSubjects provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CountSubjects") + } + + var r0 *magistrala.CountSubjectsRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) (*magistrala.CountSubjectsRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) *magistrala.CountSubjectsRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.CountSubjectsRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} - return ret.Get(0).(*magistrala.IdentityRes), ret.Error(1) +// AuthClient_CountSubjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountSubjects' +type AuthClient_CountSubjects_Call struct { + *mock.Call } -func (m *AuthClient) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) { - ret := m.Called(ctx, in) - if in.GetSubject() == InvalidValue || in.GetSubject() == "" { - return &magistrala.AuthorizeRes{Authorized: false}, svcerr.ErrAuthorization +// CountSubjects is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.CountSubjectsReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) CountSubjects(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_CountSubjects_Call { + return &AuthClient_CountSubjects_Call{Call: _e.mock.On("CountSubjects", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_CountSubjects_Call) Run(run func(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption)) *AuthClient_CountSubjects_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.CountSubjectsReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_CountSubjects_Call) Return(_a0 *magistrala.CountSubjectsRes, _a1 error) *AuthClient_CountSubjects_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_CountSubjects_Call) RunAndReturn(run func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) (*magistrala.CountSubjectsRes, error)) *AuthClient_CountSubjects_Call { + _c.Call.Return(run) + return _c +} + +// DeleteEntityPolicies provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) DeleteEntityPolicies(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for DeleteEntityPolicies") + } + + var r0 *magistrala.DeletePolicyRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)); ok { + return rf(ctx, in, opts...) } - if in.GetObject() == InvalidValue || in.GetObject() == "" { - return &magistrala.AuthorizeRes{Authorized: false}, svcerr.ErrAuthorization + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) *magistrala.DeletePolicyRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.DeletePolicyRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) } - return ret.Get(0).(*magistrala.AuthorizeRes), ret.Error(1) + return r0, r1 } -func (m *AuthClient) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) { - ret := m.Called(ctx, in) +// AuthClient_DeleteEntityPolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteEntityPolicies' +type AuthClient_DeleteEntityPolicies_Call struct { + *mock.Call +} + +// DeleteEntityPolicies is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.DeleteEntityPoliciesReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) DeleteEntityPolicies(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_DeleteEntityPolicies_Call { + return &AuthClient_DeleteEntityPolicies_Call{Call: _e.mock.On("DeleteEntityPolicies", + append([]interface{}{ctx, in}, opts...)...)} +} - return ret.Get(0).(*magistrala.AddPolicyRes), ret.Error(1) +func (_c *AuthClient_DeleteEntityPolicies_Call) Run(run func(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption)) *AuthClient_DeleteEntityPolicies_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.DeleteEntityPoliciesReq), variadicArgs...) + }) + return _c } -func (m *AuthClient) AddPolicies(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption) (*magistrala.AddPoliciesRes, error) { - ret := m.Called(ctx, in) +func (_c *AuthClient_DeleteEntityPolicies_Call) Return(_a0 *magistrala.DeletePolicyRes, _a1 error) *AuthClient_DeleteEntityPolicies_Call { + _c.Call.Return(_a0, _a1) + return _c +} - return ret.Get(0).(*magistrala.AddPoliciesRes), ret.Error(1) +func (_c *AuthClient_DeleteEntityPolicies_Call) RunAndReturn(run func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)) *AuthClient_DeleteEntityPolicies_Call { + _c.Call.Return(run) + return _c } -func (m *AuthClient) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) { - ret := m.Called(ctx, in) +// DeletePolicies provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for DeletePolicies") + } + + var r0 *magistrala.DeletePolicyRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) *magistrala.DeletePolicyRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.DeletePolicyRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } - return ret.Get(0).(*magistrala.DeletePolicyRes), ret.Error(1) + return r0, r1 } -func (m *AuthClient) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) { - ret := m.Called(ctx, in) +// AuthClient_DeletePolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeletePolicies' +type AuthClient_DeletePolicies_Call struct { + *mock.Call +} - return ret.Get(0).(*magistrala.DeletePolicyRes), ret.Error(1) +// DeletePolicies is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.DeletePoliciesReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) DeletePolicies(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_DeletePolicies_Call { + return &AuthClient_DeletePolicies_Call{Call: _e.mock.On("DeletePolicies", + append([]interface{}{ctx, in}, opts...)...)} } -func (m *AuthClient) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) { - ret := m.Called(ctx, in) +func (_c *AuthClient_DeletePolicies_Call) Run(run func(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption)) *AuthClient_DeletePolicies_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.DeletePoliciesReq), variadicArgs...) + }) + return _c +} - return ret.Get(0).(*magistrala.ListObjectsRes), ret.Error(1) +func (_c *AuthClient_DeletePolicies_Call) Return(_a0 *magistrala.DeletePolicyRes, _a1 error) *AuthClient_DeletePolicies_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (m *AuthClient) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) { - ret := m.Called(ctx, in) +func (_c *AuthClient_DeletePolicies_Call) RunAndReturn(run func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)) *AuthClient_DeletePolicies_Call { + _c.Call.Return(run) + return _c +} + +// DeletePolicyFilter provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for DeletePolicyFilter") + } - return ret.Get(0).(*magistrala.ListObjectsRes), ret.Error(1) + var r0 *magistrala.DeletePolicyRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) *magistrala.DeletePolicyRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.DeletePolicyRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -func (m *AuthClient) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) { - ret := m.Called(ctx, in) +// AuthClient_DeletePolicyFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeletePolicyFilter' +type AuthClient_DeletePolicyFilter_Call struct { + *mock.Call +} - return ret.Get(0).(*magistrala.CountObjectsRes), ret.Error(1) +// DeletePolicyFilter is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.DeletePolicyFilterReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) DeletePolicyFilter(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_DeletePolicyFilter_Call { + return &AuthClient_DeletePolicyFilter_Call{Call: _e.mock.On("DeletePolicyFilter", + append([]interface{}{ctx, in}, opts...)...)} } -func (m *AuthClient) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) { - ret := m.Called(ctx, in) +func (_c *AuthClient_DeletePolicyFilter_Call) Run(run func(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption)) *AuthClient_DeletePolicyFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.DeletePolicyFilterReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_DeletePolicyFilter_Call) Return(_a0 *magistrala.DeletePolicyRes, _a1 error) *AuthClient_DeletePolicyFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} - return ret.Get(0).(*magistrala.ListSubjectsRes), ret.Error(1) +func (_c *AuthClient_DeletePolicyFilter_Call) RunAndReturn(run func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)) *AuthClient_DeletePolicyFilter_Call { + _c.Call.Return(run) + return _c } -func (m *AuthClient) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) { - ret := m.Called(ctx, in) +// Identify provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) Identify(ctx context.Context, in *magistrala.IdentityReq, opts ...grpc.CallOption) (*magistrala.IdentityRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Identify") + } + + var r0 *magistrala.IdentityRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.IdentityReq, ...grpc.CallOption) (*magistrala.IdentityRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.IdentityReq, ...grpc.CallOption) *magistrala.IdentityRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.IdentityRes) + } + } - return ret.Get(0).(*magistrala.ListSubjectsRes), ret.Error(1) + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.IdentityReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -func (m *AuthClient) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) { - ret := m.Called(ctx, in) +// AuthClient_Identify_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Identify' +type AuthClient_Identify_Call struct { + *mock.Call +} - return ret.Get(0).(*magistrala.CountSubjectsRes), ret.Error(1) +// Identify is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.IdentityReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) Identify(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_Identify_Call { + return &AuthClient_Identify_Call{Call: _e.mock.On("Identify", + append([]interface{}{ctx, in}, opts...)...)} } -func (m *AuthClient) ListPermissions(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption) (*magistrala.ListPermissionsRes, error) { - ret := m.Called(ctx, in) +func (_c *AuthClient_Identify_Call) Run(run func(ctx context.Context, in *magistrala.IdentityReq, opts ...grpc.CallOption)) *AuthClient_Identify_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.IdentityReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_Identify_Call) Return(_a0 *magistrala.IdentityRes, _a1 error) *AuthClient_Identify_Call { + _c.Call.Return(_a0, _a1) + return _c +} - return ret.Get(0).(*magistrala.ListPermissionsRes), ret.Error(1) +func (_c *AuthClient_Identify_Call) RunAndReturn(run func(context.Context, *magistrala.IdentityReq, ...grpc.CallOption) (*magistrala.IdentityRes, error)) *AuthClient_Identify_Call { + _c.Call.Return(run) + return _c } -func (m *AuthClient) DeleteEntityPolicies(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) { - ret := m.Called(ctx, in) +// Issue provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) Issue(ctx context.Context, in *magistrala.IssueReq, opts ...grpc.CallOption) (*magistrala.Token, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Issue") + } + + var r0 *magistrala.Token + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.IssueReq, ...grpc.CallOption) (*magistrala.Token, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.IssueReq, ...grpc.CallOption) *magistrala.Token); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.Token) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.IssueReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_Issue_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Issue' +type AuthClient_Issue_Call struct { + *mock.Call +} + +// Issue is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.IssueReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) Issue(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_Issue_Call { + return &AuthClient_Issue_Call{Call: _e.mock.On("Issue", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_Issue_Call) Run(run func(ctx context.Context, in *magistrala.IssueReq, opts ...grpc.CallOption)) *AuthClient_Issue_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.IssueReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_Issue_Call) Return(_a0 *magistrala.Token, _a1 error) *AuthClient_Issue_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_Issue_Call) RunAndReturn(run func(context.Context, *magistrala.IssueReq, ...grpc.CallOption) (*magistrala.Token, error)) *AuthClient_Issue_Call { + _c.Call.Return(run) + return _c +} + +// ListAllObjects provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for ListAllObjects") + } + + var r0 *magistrala.ListObjectsRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) *magistrala.ListObjectsRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.ListObjectsRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_ListAllObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllObjects' +type AuthClient_ListAllObjects_Call struct { + *mock.Call +} + +// ListAllObjects is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.ListObjectsReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) ListAllObjects(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_ListAllObjects_Call { + return &AuthClient_ListAllObjects_Call{Call: _e.mock.On("ListAllObjects", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_ListAllObjects_Call) Run(run func(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption)) *AuthClient_ListAllObjects_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.ListObjectsReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_ListAllObjects_Call) Return(_a0 *magistrala.ListObjectsRes, _a1 error) *AuthClient_ListAllObjects_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_ListAllObjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)) *AuthClient_ListAllObjects_Call { + _c.Call.Return(run) + return _c +} + +// ListAllSubjects provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for ListAllSubjects") + } + + var r0 *magistrala.ListSubjectsRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) *magistrala.ListSubjectsRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.ListSubjectsRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_ListAllSubjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllSubjects' +type AuthClient_ListAllSubjects_Call struct { + *mock.Call +} + +// ListAllSubjects is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.ListSubjectsReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) ListAllSubjects(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_ListAllSubjects_Call { + return &AuthClient_ListAllSubjects_Call{Call: _e.mock.On("ListAllSubjects", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_ListAllSubjects_Call) Run(run func(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption)) *AuthClient_ListAllSubjects_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.ListSubjectsReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_ListAllSubjects_Call) Return(_a0 *magistrala.ListSubjectsRes, _a1 error) *AuthClient_ListAllSubjects_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_ListAllSubjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)) *AuthClient_ListAllSubjects_Call { + _c.Call.Return(run) + return _c +} + +// ListObjects provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for ListObjects") + } + + var r0 *magistrala.ListObjectsRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) *magistrala.ListObjectsRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.ListObjectsRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_ListObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListObjects' +type AuthClient_ListObjects_Call struct { + *mock.Call +} + +// ListObjects is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.ListObjectsReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) ListObjects(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_ListObjects_Call { + return &AuthClient_ListObjects_Call{Call: _e.mock.On("ListObjects", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_ListObjects_Call) Run(run func(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption)) *AuthClient_ListObjects_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.ListObjectsReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_ListObjects_Call) Return(_a0 *magistrala.ListObjectsRes, _a1 error) *AuthClient_ListObjects_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_ListObjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)) *AuthClient_ListObjects_Call { + _c.Call.Return(run) + return _c +} + +// ListPermissions provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) ListPermissions(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption) (*magistrala.ListPermissionsRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for ListPermissions") + } + + var r0 *magistrala.ListPermissionsRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) (*magistrala.ListPermissionsRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) *magistrala.ListPermissionsRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.ListPermissionsRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_ListPermissions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPermissions' +type AuthClient_ListPermissions_Call struct { + *mock.Call +} + +// ListPermissions is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.ListPermissionsReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) ListPermissions(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_ListPermissions_Call { + return &AuthClient_ListPermissions_Call{Call: _e.mock.On("ListPermissions", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_ListPermissions_Call) Run(run func(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption)) *AuthClient_ListPermissions_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.ListPermissionsReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_ListPermissions_Call) Return(_a0 *magistrala.ListPermissionsRes, _a1 error) *AuthClient_ListPermissions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_ListPermissions_Call) RunAndReturn(run func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) (*magistrala.ListPermissionsRes, error)) *AuthClient_ListPermissions_Call { + _c.Call.Return(run) + return _c +} + +// ListSubjects provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for ListSubjects") + } + + var r0 *magistrala.ListSubjectsRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) *magistrala.ListSubjectsRes); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.ListSubjectsRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_ListSubjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListSubjects' +type AuthClient_ListSubjects_Call struct { + *mock.Call +} + +// ListSubjects is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.ListSubjectsReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) ListSubjects(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_ListSubjects_Call { + return &AuthClient_ListSubjects_Call{Call: _e.mock.On("ListSubjects", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_ListSubjects_Call) Run(run func(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption)) *AuthClient_ListSubjects_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.ListSubjectsReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_ListSubjects_Call) Return(_a0 *magistrala.ListSubjectsRes, _a1 error) *AuthClient_ListSubjects_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_ListSubjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)) *AuthClient_ListSubjects_Call { + _c.Call.Return(run) + return _c +} + +// Refresh provides a mock function with given fields: ctx, in, opts +func (_m *AuthClient) Refresh(ctx context.Context, in *magistrala.RefreshReq, opts ...grpc.CallOption) (*magistrala.Token, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Refresh") + } + + var r0 *magistrala.Token + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.RefreshReq, ...grpc.CallOption) (*magistrala.Token, error)); ok { + return rf(ctx, in, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, *magistrala.RefreshReq, ...grpc.CallOption) *magistrala.Token); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*magistrala.Token) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *magistrala.RefreshReq, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AuthClient_Refresh_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Refresh' +type AuthClient_Refresh_Call struct { + *mock.Call +} + +// Refresh is a helper method to define mock.On call +// - ctx context.Context +// - in *magistrala.RefreshReq +// - opts ...grpc.CallOption +func (_e *AuthClient_Expecter) Refresh(ctx interface{}, in interface{}, opts ...interface{}) *AuthClient_Refresh_Call { + return &AuthClient_Refresh_Call{Call: _e.mock.On("Refresh", + append([]interface{}{ctx, in}, opts...)...)} +} + +func (_c *AuthClient_Refresh_Call) Run(run func(ctx context.Context, in *magistrala.RefreshReq, opts ...grpc.CallOption)) *AuthClient_Refresh_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]grpc.CallOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(grpc.CallOption) + } + } + run(args[0].(context.Context), args[1].(*magistrala.RefreshReq), variadicArgs...) + }) + return _c +} + +func (_c *AuthClient_Refresh_Call) Return(_a0 *magistrala.Token, _a1 error) *AuthClient_Refresh_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AuthClient_Refresh_Call) RunAndReturn(run func(context.Context, *magistrala.RefreshReq, ...grpc.CallOption) (*magistrala.Token, error)) *AuthClient_Refresh_Call { + _c.Call.Return(run) + return _c +} + +// NewAuthClient creates a new instance of AuthClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewAuthClient(t interface { + mock.TestingT + Cleanup(func()) +}) *AuthClient { + mock := &AuthClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) - return ret.Get(0).(*magistrala.DeletePolicyRes), ret.Error(1) + return mock } diff --git a/auth/spicedb/policies.go b/auth/spicedb/policies.go index 99f5118790..7ac2ba4a2c 100644 --- a/auth/spicedb/policies.go +++ b/auth/spicedb/policies.go @@ -350,9 +350,9 @@ func (pa *policyAgent) RetrieveAllSubjectsCount(ctx context.Context, pr auth.Pol } func (pa *policyAgent) RetrievePermissions(ctx context.Context, pr auth.PolicyReq, filterPermission []string) (auth.Permissions, error) { - var permissionChecks []*v1.BulkCheckPermissionRequestItem + var permissionChecks []*v1.CheckBulkPermissionsRequestItem for _, fp := range filterPermission { - permissionChecks = append(permissionChecks, &v1.BulkCheckPermissionRequestItem{ + permissionChecks = append(permissionChecks, &v1.CheckBulkPermissionsRequestItem{ Resource: &v1.ObjectReference{ ObjectType: pr.ObjectType, ObjectId: pr.Object, @@ -367,7 +367,7 @@ func (pa *policyAgent) RetrievePermissions(ctx context.Context, pr auth.PolicyRe }, }) } - resp, err := pa.client.ExperimentalServiceClient.BulkCheckPermission(ctx, &v1.BulkCheckPermissionRequest{ + resp, err := pa.client.PermissionsServiceClient.CheckBulkPermissions(ctx, &v1.CheckBulkPermissionsRequest{ Consistency: &v1.Consistency{ Requirement: &v1.Consistency_FullyConsistent{ FullyConsistent: true, diff --git a/bootstrap/postgres/configs_test.go b/bootstrap/postgres/configs_test.go index 9d80312e31..b66a52fcbd 100644 --- a/bootstrap/postgres/configs_test.go +++ b/bootstrap/postgres/configs_test.go @@ -730,10 +730,9 @@ func TestConnectThing(t *testing.T) { wrongID := testsutil.GenerateUUID(&testing.T{}) connectedThing := c - connectedThing.State = bootstrap.Active randomThing := c - randomThingID, err := uuid.NewV4() + randomThingID, _ := uuid.NewV4() randomThing.ThingID = randomThingID.String() emptyThing := c @@ -830,10 +829,9 @@ func TestDisconnectThing(t *testing.T) { wrongID := testsutil.GenerateUUID(&testing.T{}) connectedThing := c - connectedThing.State = bootstrap.Active randomThing := c - randomThingID, err := uuid.NewV4() + randomThingID, _ := uuid.NewV4() randomThing.ThingID = randomThingID.String() emptyThing := c diff --git a/consumers/notifiers/api/endpoint_test.go b/consumers/notifiers/api/endpoint_test.go index 89c53d7062..ec9e7842cc 100644 --- a/consumers/notifiers/api/endpoint_test.go +++ b/consumers/notifiers/api/endpoint_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" - authmocks "github.com/absmach/magistrala/auth/mocks" "github.com/absmach/magistrala/consumers/notifiers" httpapi "github.com/absmach/magistrala/consumers/notifiers/api" "github.com/absmach/magistrala/consumers/notifiers/mocks" @@ -27,14 +26,15 @@ import ( ) const ( - contentType = "application/json" - email = "user@example.com" - contact1 = "email1@example.com" - contact2 = "email2@example.com" - token = "token" - topic = "topic" - instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" - validID = "d4ebb847-5d0e-4e46-bdd9-b6aceaaa3a22" + contentType = "application/json" + email = "user@example.com" + contact1 = "email1@example.com" + contact2 = "email2@example.com" + token = "token" + invalidToken = "invalid" + topic = "topic" + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" + validID = "d4ebb847-5d0e-4e46-bdd9-b6aceaaa3a22" ) var ( @@ -145,7 +145,7 @@ func TestCreate(t *testing.T) { desc: "add with invalid auth token", req: data, contentType: contentType, - auth: authmocks.InvalidValue, + auth: invalidToken, status: http.StatusUnauthorized, location: "", err: svcerr.ErrAuthentication, @@ -249,7 +249,7 @@ func TestView(t *testing.T) { { desc: "view with invalid auth token", id: sub.ID, - auth: authmocks.InvalidValue, + auth: invalidToken, status: http.StatusUnauthorized, res: unauthRes, err: svcerr.ErrAuthentication, @@ -406,7 +406,7 @@ func TestList(t *testing.T) { }, { desc: "list with invalid auth token", - auth: authmocks.InvalidValue, + auth: invalidToken, status: http.StatusUnauthorized, res: unauthRes, err: svcerr.ErrAuthentication, @@ -477,7 +477,7 @@ func TestRemove(t *testing.T) { { desc: "view with invalid auth token", id: id, - auth: authmocks.InvalidValue, + auth: invalidToken, status: http.StatusUnauthorized, res: unauthRes, err: svcerr.ErrAuthentication, diff --git a/http/api/endpoint_test.go b/http/api/endpoint_test.go index 885a6a4817..c1c48f44bf 100644 --- a/http/api/endpoint_test.go +++ b/http/api/endpoint_test.go @@ -25,7 +25,10 @@ import ( "github.com/stretchr/testify/mock" ) -const instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" +const ( + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" + invalidValue = "invalid" +) func newService(auth magistrala.AuthzServiceClient) (session.Handler, *pubsub.PubSub) { pub := new(pubsub.PubSub) @@ -84,7 +87,7 @@ func TestPublish(t *testing.T) { ctSenmlCBOR := "application/senml+cbor" ctJSON := "application/json" thingKey := "thing_key" - invalidKey := authmocks.InvalidValue + invalidKey := invalidValue msg := `[{"n":"current","t":-1,"v":1.6}]` msgJSON := `{"field1":"val1","field2":"val2"}` msgCBOR := `81A3616E6763757272656E746174206176FB3FF999999999999A` diff --git a/invitations/service_test.go b/invitations/service_test.go index 2e3d47e9e4..4baff01097 100644 --- a/invitations/service_test.go +++ b/invitations/service_test.go @@ -28,7 +28,8 @@ var ( DomainID: testsutil.GenerateUUID(&testing.T{}), Relation: auth.ContributorRelation, } - validToken = "token" + validToken = "token" + invalidToken = "invalid" ) func TestSendInvitation(t *testing.T) { @@ -262,7 +263,7 @@ func TestViewInvitation(t *testing.T) { }, { desc: "invalid token", - token: authmocks.InvalidValue, + token: invalidToken, tokenUserID: "", userID: validInvitation.UserID, domainID: validInvitation.DomainID, diff --git a/mqtt/handler_test.go b/mqtt/handler_test.go index f5fb599f7c..2beb3f4bdb 100644 --- a/mqtt/handler_test.go +++ b/mqtt/handler_test.go @@ -29,7 +29,8 @@ const ( password = "password" password1 = "password1" chanID = "123e4567-e89b-12d3-a456-000000000001" - invalidID = authmocks.InvalidValue + invalidID = "invalidID" + invalidValue = "invalidValue" clientID = "clientID" clientID1 = "clientID1" subtopic = "testSubtopic" @@ -39,11 +40,11 @@ const ( var ( topicMsg = "channels/%s/messages" topic = fmt.Sprintf(topicMsg, chanID) - invalidTopic = authmocks.InvalidValue + invalidTopic = invalidValue payload = []byte("[{'n':'test-name', 'v': 1.2}]") topics = []string{topic} - invalidTopics = []string{authmocks.InvalidValue} - invalidChanIDTopics = []string{fmt.Sprintf(topicMsg, authmocks.InvalidValue)} + invalidTopics = []string{invalidValue} + invalidChanIDTopics = []string{fmt.Sprintf(topicMsg, invalidValue)} // Test log messages for cases the handler does not provide a return value. logBuffer = bytes.Buffer{} sessionClient = session.Session{ diff --git a/pkg/sdk/go/message_test.go b/pkg/sdk/go/message_test.go index 730e0faf6f..ccf13fbb4a 100644 --- a/pkg/sdk/go/message_test.go +++ b/pkg/sdk/go/message_test.go @@ -293,8 +293,8 @@ func TestReadMessages(t *testing.T) { Publisher: validID, }, authRes: &magistrala.AuthorizeRes{Authorized: false, Id: ""}, + authErr: svcerr.ErrAuthorization, repoRes: readers.MessagesPage{}, - repoErr: nil, response: sdk.MessagesPage{}, err: errors.NewSDKErrorWithStatus(errors.Wrap(svcerr.ErrAuthorization, svcerr.ErrAuthorization), http.StatusUnauthorized), }, @@ -311,8 +311,8 @@ func TestReadMessages(t *testing.T) { Publisher: validID, }, authRes: &magistrala.AuthorizeRes{Authorized: false, Id: ""}, + authErr: svcerr.ErrAuthorization, repoRes: readers.MessagesPage{}, - repoErr: nil, response: sdk.MessagesPage{}, err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrBearerToken), http.StatusUnauthorized), }, diff --git a/readers/api/endpoint_test.go b/readers/api/endpoint_test.go index 682cebfd52..87e7f2d330 100644 --- a/readers/api/endpoint_test.go +++ b/readers/api/endpoint_test.go @@ -30,6 +30,7 @@ const ( svcName = "test-service" thingToken = "1" userToken = "token" + invalidToken = "invalid" email = "user@example.com" invalid = "invalid" numOfMessages = 100 @@ -213,7 +214,7 @@ func TestReadAll(t *testing.T) { { desc: "read page with invalid token as thing", url: fmt.Sprintf("%s/channels/%s/messages?offset=0&limit=10", ts.URL, chanID), - token: authmocks.InvalidValue, + token: invalidToken, authResponse: false, status: http.StatusUnauthorized, err: svcerr.ErrAuthorization, @@ -622,7 +623,7 @@ func TestReadAll(t *testing.T) { { desc: "read page with invalid token as user", url: fmt.Sprintf("%s/channels/%s/messages?offset=0&limit=10", ts.URL, chanID), - token: authmocks.InvalidValue, + token: invalidToken, authResponse: false, status: http.StatusUnauthorized, err: svcerr.ErrAuthorization, diff --git a/things/service_test.go b/things/service_test.go index 721c147e0a..abdb547194 100644 --- a/things/service_test.go +++ b/things/service_test.go @@ -375,7 +375,7 @@ func TestViewClient(t *testing.T) { { desc: "view client with an invalid token", response: mgclients.Client{}, - token: authmocks.InvalidValue, + token: inValidToken, clientID: "", authorizeResponse: &magistrala.AuthorizeRes{Authorized: false}, authorizeErr: svcerr.ErrAuthorization, @@ -1475,7 +1475,7 @@ func TestListMembers(t *testing.T) { }, { desc: "list members with an invalid token", - token: authmocks.InvalidValue, + token: inValidToken, groupID: testsutil.GenerateUUID(t), identifyResponse: &magistrala.IdentityRes{}, response: mgclients.MembersPage{ @@ -1637,7 +1637,7 @@ func TestDeleteClient(t *testing.T) { }, { desc: "Delete client with unauthorized token", - token: authmocks.InvalidValue, + token: inValidToken, clientID: client.ID, identifyResponse: &magistrala.IdentityRes{}, identifyErr: svcerr.ErrAuthentication, @@ -1646,7 +1646,7 @@ func TestDeleteClient(t *testing.T) { { desc: "Delete invalid client", token: validToken, - clientID: authmocks.InvalidValue, + clientID: wrongID, identifyResponse: &magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, authorizeResponse: &magistrala.AuthorizeRes{Authorized: false}, authorizeErr: svcerr.ErrAuthorization, diff --git a/.golangci.yml b/tools/config/.golangci.yml similarity index 100% rename from .golangci.yml rename to tools/config/.golangci.yml diff --git a/tools/config/boilerplate.txt b/tools/config/boilerplate.txt new file mode 100644 index 0000000000..b3f5a643de --- /dev/null +++ b/tools/config/boilerplate.txt @@ -0,0 +1,3 @@ +// Copyright (c) Abstract Machines + +// SPDX-License-Identifier: Apache-2.0 diff --git a/tools/config/mockery.yaml b/tools/config/mockery.yaml new file mode 100644 index 0000000000..7de20b2236 --- /dev/null +++ b/tools/config/mockery.yaml @@ -0,0 +1,15 @@ +# Copyright (c) Abstract Machines +# SPDX-License-Identifier: Apache-2.0 + +with-expecter: true +filename: "{{.InterfaceName}}.go" +outpkg: "mocks" +boilerplate-file: "./tools/config/boilerplate.txt" +packages: + github.com/absmach/magistrala: + interfaces: + AuthServiceClient: + config: + dir: "./auth/mocks" + mockname: "AuthClient" + filename: "auth_client.go" diff --git a/tools/mqtt-bench/bench.go b/tools/mqtt-bench/bench.go index 2c46406b91..b79f7a3d05 100644 --- a/tools/mqtt-bench/bench.go +++ b/tools/mqtt-bench/bench.go @@ -11,6 +11,7 @@ import ( "io" "os" "strconv" + "sync" "time" mglog "github.com/absmach/magistrala/logger" @@ -34,7 +35,7 @@ func Benchmark(cfg Config) error { defer func() { if err = caFile.Close(); err != nil { - logger.Warn(fmt.Sprintf("Could not close file: %s", err)) + logger.Warn(fmt.Sprintf("Could not close file: %s", err)) } }() if err != nil { @@ -63,30 +64,41 @@ func Benchmark(cfg Config) error { start := time.Now() - // Publishers - for i := 0; i < cfg.Test.Pubs; i++ { - mgChan := mg.Channels[i%n] - mgThing := mg.Things[i%n] + var wg sync.WaitGroup + errorChan := make(chan error, cfg.Test.Pubs) - if cfg.MQTT.TLS.MTLS { - cert, err = tls.X509KeyPair([]byte(mgThing.MTLSCert), []byte(mgThing.MTLSKey)) + for i := 0; i < cfg.Test.Pubs; i++ { + wg.Add(1) + go func(i int) { + defer wg.Done() + mgChan := mg.Channels[i%n] + mgThing := mg.Things[i%n] + + if cfg.MQTT.TLS.MTLS { + cert, err = tls.X509KeyPair([]byte(mgThing.MTLSCert), []byte(mgThing.MTLSKey)) + if err != nil { + errorChan <- err + return + } + } + c, err := makeClient(i, cfg, mgChan, mgThing, startStamp, caByte, cert) if err != nil { - return err + errorChan <- fmt.Errorf("unable to create message payload %s", err.Error()) + return } - } - c, err := makeClient(i, cfg, mgChan, mgThing, startStamp, caByte, cert) - if err != nil { - return fmt.Errorf("unable to create message payload %s", err.Error()) - } - errorChan := make(chan error) - go c.publish(resCh, errorChan) + c.publish(resCh, errorChan) + }(i) + } + + go func() { + wg.Wait() + close(errorChan) + }() - for { - err := <-errorChan - if err != nil { - return err - } + for err := range errorChan { + if err != nil { + return err } } @@ -112,7 +124,6 @@ func Benchmark(cfg Config) error { return fmt.Errorf("totals not assigned") } - // Print sats printResults(results, totals, cfg.MQTT.Message.Format, cfg.Log.Quiet) return nil } diff --git a/twins/api/http/endpoint_states_test.go b/twins/api/http/endpoint_states_test.go index 732fea20ee..8330b8bc24 100644 --- a/twins/api/http/endpoint_states_test.go +++ b/twins/api/http/endpoint_states_test.go @@ -24,8 +24,10 @@ import ( ) const ( - numRecs = 100 - publisher = "twins" + numRecs = 100 + publisher = "twins" + validToken = "validToken" + invalidToken = "invalidToken" ) var ( @@ -81,7 +83,7 @@ func TestListStates(t *testing.T) { queryFmt := "%s?offset=%d&limit=%d" cases := []struct { desc string - auth string + token string status int url string res []stateRes @@ -92,7 +94,7 @@ func TestListStates(t *testing.T) { }{ { desc: "get a list of states", - auth: token, + token: validToken, status: http.StatusOK, url: baseURL, res: data[0:10], @@ -105,7 +107,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with valid offset and limit", - auth: token, + token: validToken, status: http.StatusOK, url: fmt.Sprintf(queryFmt, baseURL, 20, 15), res: data[20:35], @@ -118,7 +120,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with invalid token", - auth: authmocks.InvalidValue, + token: invalidToken, status: http.StatusUnauthorized, url: fmt.Sprintf(queryFmt, baseURL, 0, 5), res: nil, @@ -127,7 +129,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with empty token", - auth: "", + token: "", status: http.StatusUnauthorized, url: fmt.Sprintf(queryFmt, baseURL, 0, 5), res: nil, @@ -136,7 +138,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with + limit > total", - auth: token, + token: validToken, status: http.StatusOK, url: fmt.Sprintf(queryFmt, baseURL, 91, 20), res: data[91:], @@ -149,7 +151,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with negative offset", - auth: token, + token: validToken, status: http.StatusBadRequest, url: fmt.Sprintf(queryFmt, baseURL, -1, 5), res: nil, @@ -159,7 +161,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with negative limit", - auth: token, + token: validToken, status: http.StatusBadRequest, url: fmt.Sprintf(queryFmt, baseURL, 0, -5), res: nil, @@ -169,7 +171,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with zero limit", - auth: token, + token: validToken, status: http.StatusBadRequest, url: fmt.Sprintf(queryFmt, baseURL, 0, 0), res: nil, @@ -179,7 +181,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with limit greater than max", - auth: token, + token: validToken, status: http.StatusBadRequest, url: fmt.Sprintf(queryFmt, baseURL, 0, 110), res: nil, @@ -189,7 +191,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with invalid offset", - auth: token, + token: validToken, status: http.StatusBadRequest, url: fmt.Sprintf("%s?offset=invalid&limit=%d", baseURL, 15), res: nil, @@ -199,7 +201,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with invalid limit", - auth: token, + token: validToken, status: http.StatusBadRequest, url: fmt.Sprintf("%s?offset=%d&limit=invalid", baseURL, 0), res: nil, @@ -209,7 +211,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states without offset", - auth: token, + token: validToken, status: http.StatusOK, url: fmt.Sprintf("%s?limit=%d", baseURL, 15), res: data[0:15], @@ -222,7 +224,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states without limit", - auth: token, + token: validToken, status: http.StatusOK, url: fmt.Sprintf("%s?offset=%d", baseURL, 14), res: data[14:24], @@ -235,7 +237,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with invalid number of parameters", - auth: token, + token: validToken, status: http.StatusBadRequest, url: fmt.Sprintf("%s%s", baseURL, "?offset=4&limit=4&limit=5&offset=5"), res: nil, @@ -245,7 +247,7 @@ func TestListStates(t *testing.T) { }, { desc: "get a list of states with redundant query parameters", - auth: token, + token: validToken, status: http.StatusOK, url: fmt.Sprintf("%s?offset=%d&limit=%d&value=something", baseURL, 0, 5), res: data[0:5], @@ -259,13 +261,13 @@ func TestListStates(t *testing.T) { } for _, tc := range cases { - authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.auth}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr) + authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr) repoCall := stateRepo.On("RetrieveAll", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.page, tc.err) req := testRequest{ client: ts.Client(), method: http.MethodGet, url: tc.url, - token: tc.auth, + token: tc.token, } res, err := req.make() assert.Nil(t, err, fmt.Sprintf("%s: unexpected error %s", tc.desc, err)) diff --git a/twins/api/http/endpoint_twins_test.go b/twins/api/http/endpoint_twins_test.go index 8f8391055d..8325305951 100644 --- a/twins/api/http/endpoint_twins_test.go +++ b/twins/api/http/endpoint_twins_test.go @@ -14,7 +14,6 @@ import ( "testing" "github.com/absmach/magistrala" - authmocks "github.com/absmach/magistrala/auth/mocks" "github.com/absmach/magistrala/internal/testsutil" mglog "github.com/absmach/magistrala/logger" "github.com/absmach/magistrala/pkg/apiutil" @@ -26,15 +25,16 @@ import ( ) const ( - twinName = "name" - contentType = "application/json" - email = "user@example.com" - token = "token" - wrongID = 0 - maxNameSize = 1024 - instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" - retained = "saved" - validID = "123e4567-e89b-12d3-a456-426614174000" + twinName = "name" + contentType = "application/json" + email = "user@example.com" + token = "token" + invalidtoken = "invalid" + wrongID = 0 + maxNameSize = 1024 + instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002" + retained = "saved" + validID = "123e4567-e89b-12d3-a456-426614174000" ) var invalidName = strings.Repeat("m", maxNameSize+1) @@ -153,7 +153,7 @@ func TestAddTwin(t *testing.T) { desc: "add twin with invalid auth token", req: data, contentType: contentType, - auth: authmocks.InvalidValue, + auth: invalidtoken, status: http.StatusUnauthorized, location: "", err: svcerr.ErrAuthentication, @@ -318,7 +318,7 @@ func TestUpdateTwin(t *testing.T) { req: data, id: twin.ID, contentType: contentType, - auth: authmocks.InvalidValue, + auth: invalidtoken, status: http.StatusUnauthorized, err: svcerr.ErrAuthentication, retrieveErr: svcerr.ErrNotFound, @@ -468,7 +468,7 @@ func TestViewTwin(t *testing.T) { { desc: "view twin by passing invalid token", id: twin.ID, - auth: authmocks.InvalidValue, + auth: invalidtoken, status: http.StatusForbidden, res: twinRes{}, err: svcerr.ErrAuthentication, @@ -560,7 +560,7 @@ func TestListTwins(t *testing.T) { }, { desc: "get a list of twins with invalid token", - auth: authmocks.InvalidValue, + auth: invalidtoken, status: http.StatusUnauthorized, url: fmt.Sprintf(queryFmt, baseURL, 0, 1), res: nil, @@ -767,10 +767,7 @@ func TestRemoveTwin(t *testing.T) { defer ts.Close() twin := twins.Twin{ - Owner: email, - ID: testsutil.GenerateUUID(t), - Name: twinName, - Revision: 50, + ID: testsutil.GenerateUUID(t), } cases := []struct { @@ -816,7 +813,7 @@ func TestRemoveTwin(t *testing.T) { { desc: "delete twin with invalid token", id: twin.ID, - auth: authmocks.InvalidValue, + auth: invalidtoken, status: http.StatusUnauthorized, err: svcerr.ErrAuthentication, removeErr: svcerr.ErrRemoveEntity, diff --git a/twins/service_test.go b/twins/service_test.go index b210b87c76..cd5658d262 100644 --- a/twins/service_test.go +++ b/twins/service_test.go @@ -23,13 +23,14 @@ import ( ) const ( - twinName = "name" - wrongID = "" - token = "token" - email = "user@example.com" - numRecs = 100 - retained = "saved" - validID = "123e4567-e89b-12d3-a456-426614174000" + twinName = "name" + wrongID = "" + token = "token" + invalidToken = "invalidToken" + email = "user@example.com" + numRecs = 100 + retained = "saved" + validID = "123e4567-e89b-12d3-a456-426614174000" ) var ( @@ -75,7 +76,7 @@ func TestAddTwin(t *testing.T) { { desc: "add twin with wrong credentials", twin: twin, - token: authmocks.InvalidValue, + token: invalidToken, err: svcerr.ErrAuthentication, saveErr: svcerr.ErrCreateEntity, identifyErr: svcerr.ErrAuthentication, @@ -128,7 +129,7 @@ func TestUpdateTwin(t *testing.T) { { desc: "update twin with wrong credentials", twin: twin, - token: authmocks.InvalidValue, + token: invalidToken, err: svcerr.ErrAuthentication, retrieveErr: svcerr.ErrNotFound, updateErr: svcerr.ErrUpdateEntity, @@ -188,7 +189,7 @@ func TestViewTwin(t *testing.T) { { desc: "view twin with wrong credentials", id: twin.ID, - token: authmocks.InvalidValue, + token: invalidToken, err: svcerr.ErrAuthentication, identifyErr: svcerr.ErrAuthentication, }, @@ -265,7 +266,7 @@ func TestListTwins(t *testing.T) { }, { desc: "list with wrong credentials", - token: authmocks.InvalidValue, + token: invalidToken, limit: 0, offset: n, err: svcerr.ErrAuthentication, @@ -303,7 +304,7 @@ func TestRemoveTwin(t *testing.T) { { desc: "remove twin with wrong credentials", id: twin.ID, - token: authmocks.InvalidValue, + token: invalidToken, err: svcerr.ErrAuthentication, removeErr: svcerr.ErrRemoveEntity, identifyErr: svcerr.ErrAuthentication, @@ -545,7 +546,7 @@ func TestListStates(t *testing.T) { { desc: "get a list with wrong user token", id: twin.ID, - token: authmocks.InvalidValue, + token: invalidToken, offset: 0, limit: 10, size: 0, diff --git a/users/service_test.go b/users/service_test.go index 404e8e8b00..7244e5b532 100644 --- a/users/service_test.go +++ b/users/service_test.go @@ -394,12 +394,15 @@ func TestViewClient(t *testing.T) { checkSuperAdminErr: svcerr.ErrAuthorization, }, { - desc: "view client with an invalid token", - identifyResponse: &magistrala.IdentityRes{}, - response: mgclients.Client{}, - token: inValidToken, - err: svcerr.ErrAuthentication, - checkSuperAdminErr: svcerr.ErrAuthorization, + desc: "view client with an invalid token", + token: inValidToken, + clientID: clientID, + identifyResponse: &magistrala.IdentityRes{}, + authorizeResponse: &magistrala.AuthorizeRes{}, + retrieveByIDResponse: mgclients.Client{}, + response: mgclients.Client{}, + identifyErr: svcerr.ErrAuthentication, + err: svcerr.ErrAuthentication, }, { desc: "view client as normal user with failed to retrieve client", diff --git a/ws/adapter_test.go b/ws/adapter_test.go index 82291a03d6..4bccf87f62 100644 --- a/ws/adapter_test.go +++ b/ws/adapter_test.go @@ -20,11 +20,13 @@ import ( ) const ( - chanID = "1" - id = "1" - thingKey = "thing_key" - subTopic = "subtopic" - protocol = "ws" + chanID = "1" + invalidID = "invalidID" + invalidKey = "invalidKey" + id = "1" + thingKey = "thing_key" + subTopic = "subtopic" + protocol = "ws" ) var msg = messaging.Message{ @@ -77,10 +79,10 @@ func TestSubscribe(t *testing.T) { }, { desc: "subscribe to channel with invalid chanID and invalid thingKey", - thingKey: authmocks.InvalidValue, - chanID: authmocks.InvalidValue, + thingKey: invalidKey, + chanID: invalidID, subtopic: subTopic, - err: svcerr.ErrAuthorization, + err: ws.ErrFailedSubscription, }, { desc: "subscribe to channel with empty channel", @@ -109,7 +111,7 @@ func TestSubscribe(t *testing.T) { thingID := testsutil.GenerateUUID(t) subConfig := messaging.SubscriberConfig{ ID: thingID, - Topic: "channels." + chanID + "." + subTopic, + Topic: "channels." + tc.chanID + "." + subTopic, Handler: c, } repocall := pubsub.On("Subscribe", mock.Anything, subConfig).Return(tc.err)