mock

package
v0.0.0-...-fb7f86c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 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{}
	GetUserPermissions             []interface{}
	ClearUserPermissionCache       []interface{}
	IsDisabled                     []interface{}
	DeclareFixedRoles              []interface{}
	DeclarePluginRoles             []interface{}
	GetUserBuiltInRoles            []interface{}
	RegisterFixedRoles             []interface{}
	RegisterAttributeScopeResolver []interface{}
	DeleteUserPermissions          []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, *user.SignedInUser, accesscontrol.Evaluator) (bool, error)
	GetUserPermissionsFunc             func(context.Context, *user.SignedInUser, accesscontrol.Options) ([]accesscontrol.Permission, error)
	ClearUserPermissionCacheFunc       func(*user.SignedInUser)
	IsDisabledFunc                     func() bool
	DeclareFixedRolesFunc              func(...accesscontrol.RoleRegistration) error
	DeclarePluginRolesFunc             func(context.Context, string, string, []plugins.RoleRegistration) error
	GetUserBuiltInRolesFunc            func(user *user.SignedInUser) []string
	RegisterFixedRolesFunc             func() error
	RegisterScopeAttributeResolverFunc func(string, accesscontrol.ScopeAttributeResolver)
	DeleteUserPermissionsFunc          func(context.Context, int64) error
	SearchUsersPermissionsFunc         func(context.Context, *user.SignedInUser, 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
	// 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(usr 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) DeleteUserPermissions

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

func (*Mock) Evaluate

func (m *Mock) Evaluate(ctx context.Context, us 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) GetUsageStats

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

func (*Mock) GetUserPermissions

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

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

func (*Mock) IsDisabled

func (m *Mock) IsDisabled() bool

Middleware checks if service disabled or not to switch to fallback authorization. This mock return m.disabled 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) WithBuiltInRoles

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

func (*Mock) WithDisabled

func (m *Mock) WithDisabled() *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 (m *MockPermissionsService) GetPermissions(ctx context.Context, user *user.SignedInUser, resourceID string) ([]accesscontrol.ResourcePermission, error)

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