mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -06:00
RBAC: Rewrite org users rbac tests (#62469)
* API: refactor legacy org users access control tests
This commit is contained in:
parent
1092c2b383
commit
1204d607a5
@ -253,14 +253,6 @@ func (s *fakeRenderService) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type accessControlTestCase struct {
|
||||
expectedCode int
|
||||
desc string
|
||||
url string
|
||||
method string
|
||||
permissions []accesscontrol.Permission
|
||||
}
|
||||
|
||||
// accessControlScenarioContext contains the setups for accesscontrol tests
|
||||
type accessControlScenarioContext struct {
|
||||
// server we registered hs routes on.
|
||||
@ -289,16 +281,6 @@ type accessControlScenarioContext struct {
|
||||
dashboardPermissionsService *accesscontrolmock.MockPermissionsService
|
||||
}
|
||||
|
||||
func setAccessControlPermissions(acmock *accesscontrolmock.Mock, perms []accesscontrol.Permission, org int64) {
|
||||
acmock.GetUserPermissionsFunc =
|
||||
func(_ context.Context, u *user.SignedInUser, _ accesscontrol.Options) ([]accesscontrol.Permission, error) {
|
||||
if u.OrgID == org {
|
||||
return perms, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func userWithPermissions(orgID int64, permissions []accesscontrol.Permission) *user.SignedInUser {
|
||||
return &user.SignedInUser{OrgID: orgID, OrgRole: org.RoleViewer, Permissions: map[int64]map[string][]string{orgID: accesscontrol.GroupScopesByAction(permissions)}}
|
||||
}
|
||||
@ -309,16 +291,6 @@ func setInitCtxSignedInUser(initCtx *contextmodel.ReqContext, user user.SignedIn
|
||||
initCtx.SignedInUser = &user
|
||||
}
|
||||
|
||||
func setInitCtxSignedInViewer(initCtx *contextmodel.ReqContext) {
|
||||
initCtx.IsSignedIn = true
|
||||
initCtx.SignedInUser = &user.SignedInUser{UserID: testUserID, OrgID: 1, OrgRole: org.RoleViewer, Login: testUserLogin}
|
||||
}
|
||||
|
||||
func setInitCtxSignedInOrgAdmin(initCtx *contextmodel.ReqContext) {
|
||||
initCtx.IsSignedIn = true
|
||||
initCtx.SignedInUser = &user.SignedInUser{UserID: testUserID, OrgID: 1, OrgRole: org.RoleAdmin, Login: testUserLogin}
|
||||
}
|
||||
|
||||
func setupSimpleHTTPServer(features *featuremgmt.FeatureManager) *HTTPServer {
|
||||
if features == nil {
|
||||
features = featuremgmt.WithFeatures()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,7 @@ import (
|
||||
type FakeService struct {
|
||||
ExpectedTeam team.Team
|
||||
ExpectedIsMember bool
|
||||
ExpectedIsAdmin bool
|
||||
ExpectedTeamDTO *team.TeamDTO
|
||||
ExpectedTeamsByUser []*team.TeamDTO
|
||||
ExpectedMembers []*team.TeamMemberDTO
|
||||
@ -69,5 +70,5 @@ func (s *FakeService) GetTeamMembers(ctx context.Context, query *team.GetTeamMem
|
||||
}
|
||||
|
||||
func (s *FakeService) IsAdminOfTeams(ctx context.Context, query *team.IsAdminOfTeamsQuery) (bool, error) {
|
||||
return false, s.ExpectedError
|
||||
return s.ExpectedIsAdmin, s.ExpectedError
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user