mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-26 06:50:36 -05:00
Mock role service in account uuid tests
This commit is contained in:
2
go.mod
2
go.mod
@@ -17,7 +17,7 @@ require (
|
||||
github.com/owncloud/flaex v0.2.0
|
||||
github.com/owncloud/ocis-accounts v0.1.2-0.20200618163128-aa8ae58dd95e
|
||||
github.com/owncloud/ocis-pkg/v2 v2.4.0
|
||||
github.com/owncloud/ocis-settings v0.3.2-0.20200827192608-ad983f1e85c1
|
||||
github.com/owncloud/ocis-settings v0.3.2-0.20200828130413-0cc0f5bf26fe
|
||||
github.com/owncloud/ocis-store v0.0.0-20200716140351-f9670592fb7b
|
||||
github.com/prometheus/client_golang v1.7.1
|
||||
github.com/restic/calens v0.2.0
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1077,6 +1077,8 @@ github.com/owncloud/ocis-settings v0.3.2-0.20200827134219-0f9e141699e5 h1:nkgYnH
|
||||
github.com/owncloud/ocis-settings v0.3.2-0.20200827134219-0f9e141699e5/go.mod h1:vRge9QDkOsc6j76gPBmZs1Z5uOPrV4DIkZCgZCEFwBA=
|
||||
github.com/owncloud/ocis-settings v0.3.2-0.20200827192608-ad983f1e85c1 h1:mI8zZni05KYJqsdsbhVtswWt5q+kbLJ9gtlPoGE0jSY=
|
||||
github.com/owncloud/ocis-settings v0.3.2-0.20200827192608-ad983f1e85c1/go.mod h1:vRge9QDkOsc6j76gPBmZs1Z5uOPrV4DIkZCgZCEFwBA=
|
||||
github.com/owncloud/ocis-settings v0.3.2-0.20200828130413-0cc0f5bf26fe h1:kiU5lz12R0LNJE1/zI2vxesZPWm6BvSO7hvZC8yOoAc=
|
||||
github.com/owncloud/ocis-settings v0.3.2-0.20200828130413-0cc0f5bf26fe/go.mod h1:vRge9QDkOsc6j76gPBmZs1Z5uOPrV4DIkZCgZCEFwBA=
|
||||
github.com/owncloud/ocis-store v0.0.0-20200716140351-f9670592fb7b h1:tjfH02oEawuMdMt3pJdCjFyuWgNRUjV7rdjoTF56Mrw=
|
||||
github.com/owncloud/ocis-store v0.0.0-20200716140351-f9670592fb7b/go.mod h1:7WRMnx4ffwtckNl4qD2Gj/d5fvl84jyydOV2FbUUu3A=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||
|
||||
@@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
settings "github.com/owncloud/ocis-settings/pkg/proto/v0"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -35,6 +36,7 @@ func TestAccountUUIDMiddleware(t *testing.T) {
|
||||
Logger(log.NewLogger()),
|
||||
TokenManagerConfig(config.TokenManager{JWTSecret: "secret"}),
|
||||
AccountsClient(mockAccountUUIDMiddlewareAccSvc(false, true)),
|
||||
SettingsRoleService(mockAccountUUIDMiddlewareRolesSvc(false)),
|
||||
)(next)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "http://www.example.com", nil)
|
||||
@@ -55,6 +57,7 @@ func TestAccountUUIDMiddlewareWithDisabledAccount(t *testing.T) {
|
||||
Logger(log.NewLogger()),
|
||||
TokenManagerConfig(config.TokenManager{JWTSecret: "secret"}),
|
||||
AccountsClient(mockAccountUUIDMiddlewareAccSvc(false, false)),
|
||||
SettingsRoleService(mockAccountUUIDMiddlewareRolesSvc(false)),
|
||||
)(next)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "http://www.example.com", nil)
|
||||
@@ -72,16 +75,11 @@ func TestAccountUUIDMiddlewareWithDisabledAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
func mockAccountUUIDMiddlewareAccSvc(retErr, accEnabled bool) proto.AccountsService {
|
||||
if retErr {
|
||||
return &proto.MockAccountsService{
|
||||
ListFunc: func(ctx context.Context, in *proto.ListAccountsRequest, opts ...client.CallOption) (out *proto.ListAccountsResponse, err error) {
|
||||
return nil, fmt.Errorf("error returned by mockAccountsService LIST")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return &proto.MockAccountsService{
|
||||
ListFunc: func(ctx context.Context, in *proto.ListAccountsRequest, opts ...client.CallOption) (out *proto.ListAccountsResponse, err error) {
|
||||
if retErr {
|
||||
return nil, fmt.Errorf("error returned by mockAccountsService LIST")
|
||||
}
|
||||
return &proto.ListAccountsResponse{
|
||||
Accounts: []*proto.Account{
|
||||
{
|
||||
@@ -92,5 +90,17 @@ func mockAccountUUIDMiddlewareAccSvc(retErr, accEnabled bool) proto.AccountsServ
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func mockAccountUUIDMiddlewareRolesSvc(returnError bool) settings.RoleService {
|
||||
return &settings.MockRoleService{
|
||||
ListRoleAssignmentsFunc: func(ctx context.Context, req *settings.ListRoleAssignmentsRequest, opts ...client.CallOption) (res *settings.ListRoleAssignmentsResponse, err error) {
|
||||
if returnError {
|
||||
return nil, fmt.Errorf("error returned by mockRoleService.ListRoleAssignments")
|
||||
}
|
||||
return &settings.ListRoleAssignmentsResponse{
|
||||
Assignments: []*settings.UserRoleAssignment{},
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user