mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Guardian: Rewrite tests from goconvey (#29292)
* Guardian: Rewrite tests from goconvey Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/services/guardian/guardian_test.go Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
This commit is contained in:
parent
27b4390484
commit
4c47fc56bb
@ -7,10 +7,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
const (
|
||||||
orgID = int64(1)
|
orgID = int64(1)
|
||||||
defaultDashboardID = int64(-1)
|
defaultDashboardID = int64(-1)
|
||||||
dashboardID = int64(1)
|
dashboardID = int64(1)
|
||||||
@ -20,13 +20,15 @@ var (
|
|||||||
otherUserID = int64(2)
|
otherUserID = int64(2)
|
||||||
teamID = int64(1)
|
teamID = int64(1)
|
||||||
otherTeamID = int64(2)
|
otherTeamID = int64(2)
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
adminRole = models.ROLE_ADMIN
|
adminRole = models.ROLE_ADMIN
|
||||||
editorRole = models.ROLE_EDITOR
|
editorRole = models.ROLE_EDITOR
|
||||||
viewerRole = models.ROLE_VIEWER
|
viewerRole = models.ROLE_VIEWER
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGuardianAdmin(t *testing.T) {
|
func TestGuardianAdmin(t *testing.T) {
|
||||||
Convey("Guardian admin org role tests", t, func() {
|
|
||||||
orgRoleScenario("Given user has admin org role", t, models.ROLE_ADMIN, func(sc *scenarioContext) {
|
orgRoleScenario("Given user has admin org role", t, models.ROLE_ADMIN, func(sc *scenarioContext) {
|
||||||
// dashboard has default permissions
|
// dashboard has default permissions
|
||||||
sc.defaultPermissionScenario(USER, FULL_ACCESS)
|
sc.defaultPermissionScenario(USER, FULL_ACCESS)
|
||||||
@ -71,11 +73,9 @@ func TestGuardianAdmin(t *testing.T) {
|
|||||||
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_EDIT, FULL_ACCESS)
|
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_EDIT, FULL_ACCESS)
|
||||||
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_VIEW, FULL_ACCESS)
|
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_VIEW, FULL_ACCESS)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGuardianEditor(t *testing.T) {
|
func TestGuardianEditor(t *testing.T) {
|
||||||
Convey("Guardian editor org role tests", t, func() {
|
|
||||||
orgRoleScenario("Given user has editor org role", t, models.ROLE_EDITOR, func(sc *scenarioContext) {
|
orgRoleScenario("Given user has editor org role", t, models.ROLE_EDITOR, func(sc *scenarioContext) {
|
||||||
// dashboard has default permissions
|
// dashboard has default permissions
|
||||||
sc.defaultPermissionScenario(USER, EDITOR_ACCESS)
|
sc.defaultPermissionScenario(USER, EDITOR_ACCESS)
|
||||||
@ -120,11 +120,9 @@ func TestGuardianEditor(t *testing.T) {
|
|||||||
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_EDIT, NO_ACCESS)
|
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_EDIT, NO_ACCESS)
|
||||||
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_VIEW, NO_ACCESS)
|
sc.parentFolderPermissionScenario(VIEWER, models.PERMISSION_VIEW, NO_ACCESS)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGuardianViewer(t *testing.T) {
|
func TestGuardianViewer(t *testing.T) {
|
||||||
Convey("Guardian viewer org role tests", t, func() {
|
|
||||||
orgRoleScenario("Given user has viewer org role", t, models.ROLE_VIEWER, func(sc *scenarioContext) {
|
orgRoleScenario("Given user has viewer org role", t, models.ROLE_VIEWER, func(sc *scenarioContext) {
|
||||||
// dashboard has default permissions
|
// dashboard has default permissions
|
||||||
sc.defaultPermissionScenario(USER, VIEWER_ACCESS)
|
sc.defaultPermissionScenario(USER, VIEWER_ACCESS)
|
||||||
@ -174,7 +172,6 @@ func TestGuardianViewer(t *testing.T) {
|
|||||||
// dashboard has default permissions
|
// dashboard has default permissions
|
||||||
sc.defaultPermissionScenario(VIEWER, VIEWER_ACCESS)
|
sc.defaultPermissionScenario(VIEWER, VIEWER_ACCESS)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *scenarioContext) defaultPermissionScenario(pt permissionType, flag permissionFlags) {
|
func (sc *scenarioContext) defaultPermissionScenario(pt permissionType, flag permissionFlags) {
|
||||||
@ -186,7 +183,8 @@ func (sc *scenarioContext) defaultPermissionScenario(pt permissionType, flag per
|
|||||||
toDto(newViewerRolePermission(defaultDashboardID, models.PERMISSION_VIEW)),
|
toDto(newViewerRolePermission(defaultDashboardID, models.PERMISSION_VIEW)),
|
||||||
}
|
}
|
||||||
|
|
||||||
permissionScenario("and existing permissions is the default permissions (everyone with editor role can edit, everyone with viewer role can view)", dashboardID, sc, existingPermissions, func(sc *scenarioContext) {
|
permissionScenario("and existing permissions are the default permissions (everyone with editor role can edit, everyone with viewer role can view)",
|
||||||
|
dashboardID, sc, existingPermissions, func(sc *scenarioContext) {
|
||||||
sc.expectedFlags = flag
|
sc.expectedFlags = flag
|
||||||
sc.verifyExpectedPermissionsFlags()
|
sc.verifyExpectedPermissionsFlags()
|
||||||
sc.verifyDuplicatePermissionsShouldNotBeAllowed()
|
sc.verifyDuplicatePermissionsShouldNotBeAllowed()
|
||||||
@ -212,7 +210,8 @@ func (sc *scenarioContext) dashboardPermissionScenario(pt permissionType, permis
|
|||||||
existingPermissions = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: dashboardID, Role: &viewerRole, Permission: permission}}
|
existingPermissions = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: dashboardID, Role: &viewerRole, Permission: permission}}
|
||||||
}
|
}
|
||||||
|
|
||||||
permissionScenario(fmt.Sprintf("and %s has permission to %s dashboard", pt.String(), permission.String()), dashboardID, sc, existingPermissions, func(sc *scenarioContext) {
|
permissionScenario(fmt.Sprintf("and %s has permission to %s dashboard", pt.String(), permission.String()),
|
||||||
|
dashboardID, sc, existingPermissions, func(sc *scenarioContext) {
|
||||||
sc.expectedFlags = flag
|
sc.expectedFlags = flag
|
||||||
sc.verifyExpectedPermissionsFlags()
|
sc.verifyExpectedPermissionsFlags()
|
||||||
sc.verifyDuplicatePermissionsShouldNotBeAllowed()
|
sc.verifyDuplicatePermissionsShouldNotBeAllowed()
|
||||||
@ -229,16 +228,21 @@ func (sc *scenarioContext) parentFolderPermissionScenario(pt permissionType, per
|
|||||||
|
|
||||||
switch pt {
|
switch pt {
|
||||||
case USER:
|
case USER:
|
||||||
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID, UserId: userID, Permission: permission, Inherited: true}}
|
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID,
|
||||||
|
UserId: userID, Permission: permission, Inherited: true}}
|
||||||
case TEAM:
|
case TEAM:
|
||||||
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID, TeamId: teamID, Permission: permission, Inherited: true}}
|
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID, TeamId: teamID,
|
||||||
|
Permission: permission, Inherited: true}}
|
||||||
case EDITOR:
|
case EDITOR:
|
||||||
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID, Role: &editorRole, Permission: permission, Inherited: true}}
|
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID,
|
||||||
|
Role: &editorRole, Permission: permission, Inherited: true}}
|
||||||
case VIEWER:
|
case VIEWER:
|
||||||
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID, Role: &viewerRole, Permission: permission, Inherited: true}}
|
folderPermissionList = []*models.DashboardAclInfoDTO{{OrgId: orgID, DashboardId: parentFolderID,
|
||||||
|
Role: &viewerRole, Permission: permission, Inherited: true}}
|
||||||
}
|
}
|
||||||
|
|
||||||
permissionScenario(fmt.Sprintf("and parent folder has %s with permission to %s", pt.String(), permission.String()), childDashboardID, sc, folderPermissionList, func(sc *scenarioContext) {
|
permissionScenario(fmt.Sprintf("and parent folder has %s with permission to %s", pt.String(), permission.String()),
|
||||||
|
childDashboardID, sc, folderPermissionList, func(sc *scenarioContext) {
|
||||||
sc.expectedFlags = flag
|
sc.expectedFlags = flag
|
||||||
sc.verifyExpectedPermissionsFlags()
|
sc.verifyExpectedPermissionsFlags()
|
||||||
sc.verifyDuplicatePermissionsShouldNotBeAllowed()
|
sc.verifyDuplicatePermissionsShouldNotBeAllowed()
|
||||||
@ -250,13 +254,17 @@ func (sc *scenarioContext) parentFolderPermissionScenario(pt permissionType, per
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sc *scenarioContext) verifyExpectedPermissionsFlags() {
|
func (sc *scenarioContext) verifyExpectedPermissionsFlags() {
|
||||||
canAdmin, _ := sc.g.CanAdmin()
|
|
||||||
canEdit, _ := sc.g.CanEdit()
|
|
||||||
canSave, _ := sc.g.CanSave()
|
|
||||||
canView, _ := sc.g.CanView()
|
|
||||||
|
|
||||||
tc := fmt.Sprintf("should have permissions to %s", sc.expectedFlags.String())
|
tc := fmt.Sprintf("should have permissions to %s", sc.expectedFlags.String())
|
||||||
Convey(tc, func() {
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
|
canAdmin, err := sc.g.CanAdmin()
|
||||||
|
require.NoError(t, err)
|
||||||
|
canEdit, err := sc.g.CanEdit()
|
||||||
|
require.NoError(t, err)
|
||||||
|
canSave, err := sc.g.CanSave()
|
||||||
|
require.NoError(t, err)
|
||||||
|
canView, err := sc.g.CanView()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
var actualFlag permissionFlags
|
var actualFlag permissionFlags
|
||||||
|
|
||||||
if canAdmin {
|
if canAdmin {
|
||||||
@ -293,7 +301,7 @@ func (sc *scenarioContext) verifyDuplicatePermissionsShouldNotBeAllowed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tc := "When updating dashboard permissions with duplicate permission for user should not be allowed"
|
tc := "When updating dashboard permissions with duplicate permission for user should not be allowed"
|
||||||
Convey(tc, func() {
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
p := []*models.DashboardAcl{
|
p := []*models.DashboardAcl{
|
||||||
newDefaultUserPermission(dashboardID, models.PERMISSION_VIEW),
|
newDefaultUserPermission(dashboardID, models.PERMISSION_VIEW),
|
||||||
newDefaultUserPermission(dashboardID, models.PERMISSION_ADMIN),
|
newDefaultUserPermission(dashboardID, models.PERMISSION_ADMIN),
|
||||||
@ -308,7 +316,7 @@ func (sc *scenarioContext) verifyDuplicatePermissionsShouldNotBeAllowed() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tc = "When updating dashboard permissions with duplicate permission for team should not be allowed"
|
tc = "When updating dashboard permissions with duplicate permission for team should not be allowed"
|
||||||
Convey(tc, func() {
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
p := []*models.DashboardAcl{
|
p := []*models.DashboardAcl{
|
||||||
newDefaultTeamPermission(dashboardID, models.PERMISSION_VIEW),
|
newDefaultTeamPermission(dashboardID, models.PERMISSION_VIEW),
|
||||||
newDefaultTeamPermission(dashboardID, models.PERMISSION_ADMIN),
|
newDefaultTeamPermission(dashboardID, models.PERMISSION_ADMIN),
|
||||||
@ -322,7 +330,7 @@ func (sc *scenarioContext) verifyDuplicatePermissionsShouldNotBeAllowed() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tc = "When updating dashboard permissions with duplicate permission for editor role should not be allowed"
|
tc = "When updating dashboard permissions with duplicate permission for editor role should not be allowed"
|
||||||
Convey(tc, func() {
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
p := []*models.DashboardAcl{
|
p := []*models.DashboardAcl{
|
||||||
newEditorRolePermission(dashboardID, models.PERMISSION_VIEW),
|
newEditorRolePermission(dashboardID, models.PERMISSION_VIEW),
|
||||||
newEditorRolePermission(dashboardID, models.PERMISSION_ADMIN),
|
newEditorRolePermission(dashboardID, models.PERMISSION_ADMIN),
|
||||||
@ -337,7 +345,7 @@ func (sc *scenarioContext) verifyDuplicatePermissionsShouldNotBeAllowed() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tc = "When updating dashboard permissions with duplicate permission for viewer role should not be allowed"
|
tc = "When updating dashboard permissions with duplicate permission for viewer role should not be allowed"
|
||||||
Convey(tc, func() {
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
p := []*models.DashboardAcl{
|
p := []*models.DashboardAcl{
|
||||||
newViewerRolePermission(dashboardID, models.PERMISSION_VIEW),
|
newViewerRolePermission(dashboardID, models.PERMISSION_VIEW),
|
||||||
newViewerRolePermission(dashboardID, models.PERMISSION_ADMIN),
|
newViewerRolePermission(dashboardID, models.PERMISSION_ADMIN),
|
||||||
@ -351,7 +359,7 @@ func (sc *scenarioContext) verifyDuplicatePermissionsShouldNotBeAllowed() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tc = "When updating dashboard permissions with duplicate permission for admin role should not be allowed"
|
tc = "When updating dashboard permissions with duplicate permission for admin role should not be allowed"
|
||||||
Convey(tc, func() {
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
p := []*models.DashboardAcl{
|
p := []*models.DashboardAcl{
|
||||||
newAdminRolePermission(dashboardID, models.PERMISSION_ADMIN),
|
newAdminRolePermission(dashboardID, models.PERMISSION_ADMIN),
|
||||||
}
|
}
|
||||||
@ -371,8 +379,7 @@ func (sc *scenarioContext) verifyUpdateDashboardPermissionsShouldBeAllowed(pt pe
|
|||||||
|
|
||||||
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
||||||
tc := fmt.Sprintf("When updating dashboard permissions with %s permissions should be allowed", p.String())
|
tc := fmt.Sprintf("When updating dashboard permissions with %s permissions should be allowed", p.String())
|
||||||
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
Convey(tc, func() {
|
|
||||||
permissionList := []*models.DashboardAcl{}
|
permissionList := []*models.DashboardAcl{}
|
||||||
switch pt {
|
switch pt {
|
||||||
case USER:
|
case USER:
|
||||||
@ -418,8 +425,7 @@ func (sc *scenarioContext) verifyUpdateDashboardPermissionsShouldNotBeAllowed(pt
|
|||||||
|
|
||||||
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
||||||
tc := fmt.Sprintf("When updating dashboard permissions with %s permissions should NOT be allowed", p.String())
|
tc := fmt.Sprintf("When updating dashboard permissions with %s permissions should NOT be allowed", p.String())
|
||||||
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
Convey(tc, func() {
|
|
||||||
permissionList := []*models.DashboardAcl{
|
permissionList := []*models.DashboardAcl{
|
||||||
newEditorRolePermission(dashboardID, p),
|
newEditorRolePermission(dashboardID, p),
|
||||||
newViewerRolePermission(dashboardID, p),
|
newViewerRolePermission(dashboardID, p),
|
||||||
@ -457,8 +463,7 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsShouldBeAllowed(
|
|||||||
|
|
||||||
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
||||||
tc := fmt.Sprintf("When updating child dashboard permissions with %s permissions should be allowed", p.String())
|
tc := fmt.Sprintf("When updating child dashboard permissions with %s permissions should be allowed", p.String())
|
||||||
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
Convey(tc, func() {
|
|
||||||
permissionList := []*models.DashboardAcl{}
|
permissionList := []*models.DashboardAcl{}
|
||||||
switch pt {
|
switch pt {
|
||||||
case USER:
|
case USER:
|
||||||
@ -519,8 +524,7 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsShouldNotBeAllow
|
|||||||
|
|
||||||
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
for _, p := range []models.PermissionType{models.PERMISSION_ADMIN, models.PERMISSION_EDIT, models.PERMISSION_VIEW} {
|
||||||
tc := fmt.Sprintf("When updating child dashboard permissions with %s permissions should NOT be allowed", p.String())
|
tc := fmt.Sprintf("When updating child dashboard permissions with %s permissions should NOT be allowed", p.String())
|
||||||
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
Convey(tc, func() {
|
|
||||||
permissionList := []*models.DashboardAcl{}
|
permissionList := []*models.DashboardAcl{}
|
||||||
switch pt {
|
switch pt {
|
||||||
case USER:
|
case USER:
|
||||||
@ -586,8 +590,7 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsWithOverrideShou
|
|||||||
}
|
}
|
||||||
|
|
||||||
tc := fmt.Sprintf("When updating child dashboard permissions overriding parent %s permission with %s permission should NOT be allowed", pt.String(), p.String())
|
tc := fmt.Sprintf("When updating child dashboard permissions overriding parent %s permission with %s permission should NOT be allowed", pt.String(), p.String())
|
||||||
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
Convey(tc, func() {
|
|
||||||
permissionList := []*models.DashboardAcl{}
|
permissionList := []*models.DashboardAcl{}
|
||||||
switch pt {
|
switch pt {
|
||||||
case USER:
|
case USER:
|
||||||
@ -629,9 +632,11 @@ func (sc *scenarioContext) verifyUpdateChildDashboardPermissionsWithOverrideShou
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
tc := fmt.Sprintf("When updating child dashboard permissions overriding parent %s permission with %s permission should be allowed", pt.String(), p.String())
|
tc := fmt.Sprintf(
|
||||||
|
"When updating child dashboard permissions overriding parent %s permission with %s permission should be allowed",
|
||||||
Convey(tc, func() {
|
pt.String(), p.String(),
|
||||||
|
)
|
||||||
|
sc.t.Run(tc, func(t *testing.T) {
|
||||||
permissionList := []*models.DashboardAcl{}
|
permissionList := []*models.DashboardAcl{}
|
||||||
switch pt {
|
switch pt {
|
||||||
case USER:
|
case USER:
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type scenarioContext struct {
|
type scenarioContext struct {
|
||||||
@ -29,12 +29,14 @@ type scenarioContext struct {
|
|||||||
type scenarioFunc func(c *scenarioContext)
|
type scenarioFunc func(c *scenarioContext)
|
||||||
|
|
||||||
func orgRoleScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) {
|
func orgRoleScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) {
|
||||||
|
t.Run(desc, func(t *testing.T) {
|
||||||
user := &models.SignedInUser{
|
user := &models.SignedInUser{
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
OrgId: orgID,
|
OrgId: orgID,
|
||||||
OrgRole: role,
|
OrgRole: role,
|
||||||
}
|
}
|
||||||
guard := New(dashboardID, orgID, user)
|
guard := New(dashboardID, orgID, user)
|
||||||
|
|
||||||
sc := &scenarioContext{
|
sc := &scenarioContext{
|
||||||
t: t,
|
t: t,
|
||||||
orgRoleScenario: desc,
|
orgRoleScenario: desc,
|
||||||
@ -42,13 +44,12 @@ func orgRoleScenario(desc string, t *testing.T, role models.RoleType, fn scenari
|
|||||||
givenDashboardID: dashboardID,
|
givenDashboardID: dashboardID,
|
||||||
g: guard,
|
g: guard,
|
||||||
}
|
}
|
||||||
|
|
||||||
Convey(desc, func() {
|
|
||||||
fn(sc)
|
fn(sc)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiKeyScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) {
|
func apiKeyScenario(desc string, t *testing.T, role models.RoleType, fn scenarioFunc) {
|
||||||
|
t.Run(desc, func(t *testing.T) {
|
||||||
user := &models.SignedInUser{
|
user := &models.SignedInUser{
|
||||||
UserId: 0,
|
UserId: 0,
|
||||||
OrgId: orgID,
|
OrgId: orgID,
|
||||||
@ -64,12 +65,13 @@ func apiKeyScenario(desc string, t *testing.T, role models.RoleType, fn scenario
|
|||||||
g: guard,
|
g: guard,
|
||||||
}
|
}
|
||||||
|
|
||||||
Convey(desc, func() {
|
|
||||||
fn(sc)
|
fn(sc)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func permissionScenario(desc string, dashboardID int64, sc *scenarioContext, permissions []*models.DashboardAclInfoDTO, fn scenarioFunc) {
|
func permissionScenario(desc string, dashboardID int64, sc *scenarioContext,
|
||||||
|
permissions []*models.DashboardAclInfoDTO, fn scenarioFunc) {
|
||||||
|
sc.t.Run(desc, func(t *testing.T) {
|
||||||
bus.ClearBusHandlers()
|
bus.ClearBusHandlers()
|
||||||
|
|
||||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||||
@ -110,7 +112,6 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext, per
|
|||||||
sc.givenPermissions = permissions
|
sc.givenPermissions = permissions
|
||||||
sc.givenTeams = teams
|
sc.givenTeams = teams
|
||||||
|
|
||||||
Convey(desc, func() {
|
|
||||||
fn(sc)
|
fn(sc)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -194,7 +195,7 @@ func (f permissionFlags) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sc *scenarioContext) reportSuccess() {
|
func (sc *scenarioContext) reportSuccess() {
|
||||||
So(true, ShouldBeTrue)
|
assert.True(sc.t, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *scenarioContext) reportFailure(desc string, expected interface{}, actual interface{}) {
|
func (sc *scenarioContext) reportFailure(desc string, expected interface{}, actual interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user