mock

package
v11.1.4-modfix Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Calls

type Calls struct {
	Evaluate                       []interface{}
	GetRoleByName                  []interface{}
	GetUserPermissions             []interface{}
	ClearUserPermissionCache       []interface{}
	DeclareFixedRoles              []interface{}
	DeclarePluginRoles             []interface{}
	GetUserBuiltInRoles            []interface{}
	RegisterFixedRoles             []interface{}
	RegisterAttributeScopeResolver []interface{}
	DeleteUserPermissions          []interface{}
	DeleteTeamPermissions          []interface{}
	SearchUsersPermissions         []interface{}
	SearchUserPermissions          []interface{}
	SaveExternalServiceRole        []interface{}
	DeleteExternalServiceRole      []interface{}
}

type Mock

type Mock struct {

	// Track the list of calls
	Calls Calls

	// Override functions
	EvaluateFunc                       func(context.Context, identity.Requester, accesscontrol.Evaluator) (bool, error)
	GetRoleByNameFunc                  func(context.Context, int64, string) (*accesscontrol.RoleDTO, error)
	GetUserPermissionsFunc             func(context.Context, identity.Requester, accesscontrol.Options) ([]accesscontrol.Permission, error)
	ClearUserPermissionCacheFunc       func(identity.Requester)
	DeclareFixedRolesFunc              func(...accesscontrol.RoleRegistration) error
	DeclarePluginRolesFunc             func(context.Context, string, string, []plugins.RoleRegistration) error
	GetUserBuiltInRolesFunc            func(user identity.Requester) []string
	RegisterFixedRolesFunc             func() error
	RegisterScopeAttributeResolverFunc func(string, accesscontrol.ScopeAttributeResolver)
	DeleteUserPermissionsFunc          func(context.Context, int64) error
	DeleteTeamPermissionsFunc          func(context.Context, int64) error
	SearchUsersPermissionsFunc         func(context.Context, identity.Requester, int64, accesscontrol.SearchOptions) (map[int64][]accesscontrol.Permission, error)
	SearchUserPermissionsFunc          func(ctx context.Context, orgID int64, searchOptions accesscontrol.SearchOptions) ([]accesscontrol.Permission, error)
	SaveExternalServiceRoleFunc        func(ctx context.Context, cmd accesscontrol.SaveExternalServiceRoleCommand) error
	DeleteExternalServiceRoleFunc      func(ctx context.Context, externalServiceID string) error
	SyncUserRolesFunc                  func(ctx context.Context, orgID int64, cmd accesscontrol.SyncUserRolesCommand) error
	// contains filtered or unexported fields
}

func New deprecated

func New() *Mock

Deprecated: use fake service and real access control evaluator instead

func (*Mock) ClearUserPermissionCache

func (m *Mock) ClearUserPermissionCache(user identity.Requester)

func (*Mock) DeclareFixedRoles

func (m *Mock) DeclareFixedRoles(registrations ...accesscontrol.RoleRegistration) error

DeclareFixedRoles allow the caller to declare, to the service, fixed roles and their assignments to organization roles ("Viewer", "Editor", "Admin") or "Grafana Admin" This mock returns no error unless an override is provided.

func (*Mock) DeclarePluginRoles

func (m *Mock) DeclarePluginRoles(ctx context.Context, ID, name string, regs []plugins.RoleRegistration) error

DeclarePluginRoles allow the caller to declare, to the service, plugin roles and their assignments to organization roles ("Viewer", "Editor", "Admin") or "Grafana Admin" This mock returns no error unless an override is provided.

func (*Mock) DeleteExternalServiceRole

func (m *Mock) DeleteExternalServiceRole(ctx context.Context, externalServiceID string) error

func (*Mock) DeleteTeamPermissions

func (m *Mock) DeleteTeamPermissions(ctx context.Context, orgID, teamID int64) error

func (*Mock) DeleteUserPermissions

func (m *Mock) DeleteUserPermissions(ctx context.Context, orgID, userID int64) error

func (*Mock) Evaluate

func (m *Mock) Evaluate(ctx context.Context, usr identity.Requester, evaluator accesscontrol.Evaluator) (bool, error)

Evaluate evaluates access to the given resource. This mock uses GetUserPermissions to then call the evaluator Evaluate function.

func (*Mock) GetRoleByName

func (m *Mock) GetRoleByName(ctx context.Context, orgID int64, roleName string) (*accesscontrol.RoleDTO, error)

func (*Mock) GetUsageStats

func (m *Mock) GetUsageStats(ctx context.Context) map[string]interface{}

func (*Mock) GetUserPermissions

func (m *Mock) GetUserPermissions(ctx context.Context, user identity.Requester, opts accesscontrol.Options) ([]accesscontrol.Permission, error)

GetUserPermissions returns user permissions. This mock return m.permissions unless an override is provided.

func (*Mock) RegisterFixedRoles

func (m *Mock) RegisterFixedRoles(ctx context.Context) error

RegisterFixedRoles registers all roles declared to AccessControl This mock returns no error unless an override is provided.

func (*Mock) RegisterScopeAttributeResolver

func (m *Mock) RegisterScopeAttributeResolver(scopePrefix string, resolver accesscontrol.ScopeAttributeResolver)

func (*Mock) SaveExternalServiceRole

func (m *Mock) SaveExternalServiceRole(ctx context.Context, cmd accesscontrol.SaveExternalServiceRoleCommand) error

func (*Mock) SearchUserPermissions

func (m *Mock) SearchUserPermissions(ctx context.Context, orgID int64, searchOptions accesscontrol.SearchOptions) ([]accesscontrol.Permission, error)

func (*Mock) SearchUsersPermissions

func (m *Mock) SearchUsersPermissions(ctx context.Context, usr identity.Requester, options accesscontrol.SearchOptions) (map[int64][]accesscontrol.Permission, error)

SearchUsersPermissions returns all users' permissions filtered by an action prefix

func (*Mock) SyncUserRoles

func (m *Mock) SyncUserRoles(ctx context.Context, orgID int64, cmd accesscontrol.SyncUserRolesCommand) error

func (*Mock) WithBuiltInRoles

func (m *Mock) WithBuiltInRoles(builtInRoles []string) *Mock

func (*Mock) WithPermissions

func (m *Mock) WithPermissions(permissions []accesscontrol.Permission) *Mock

type MockPermissionsService

type MockPermissionsService struct {
	mock.Mock
}

func NewMockedPermissionsService

func NewMockedPermissionsService() *MockPermissionsService

func (*MockPermissionsService) DeleteResourcePermissions

func (m *MockPermissionsService) DeleteResourcePermissions(ctx context.Context, orgID int64, resourceID string) error

func (*MockPermissionsService) GetPermissions

func (*MockPermissionsService) MapActions

func (*MockPermissionsService) SetBuiltInRolePermission

func (m *MockPermissionsService) SetBuiltInRolePermission(ctx context.Context, orgID int64, builtInRole, resourceID, permission string) (*accesscontrol.ResourcePermission, error)

func (*MockPermissionsService) SetPermissions

func (*MockPermissionsService) SetTeamPermission

func (m *MockPermissionsService) SetTeamPermission(ctx context.Context, orgID, teamID int64, resourceID, permission string) (*accesscontrol.ResourcePermission, error)

func (*MockPermissionsService) SetUserPermission

func (m *MockPermissionsService) SetUserPermission(ctx context.Context, orgID int64, user accesscontrol.User, resourceID, permission string) (*accesscontrol.ResourcePermission, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL