Remove folderID from service tests (#80615)
* Remove folderID from service tests * Remove folderID from ngalert migration tests * Remove tests related to folderIDs * Roll back change Before removing FolderID from this test, we need to adjust the code * Remove FolderID from publicdashboard pkg * Add back annotations test
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
||||
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -30,9 +29,8 @@ const (
|
||||
var (
|
||||
folderUIDScope = fmt.Sprintf("folders:uid:%s", folderUID)
|
||||
invalidFolderUIDScope = fmt.Sprintf("folders:uid:%s", invalidFolderUID)
|
||||
// nolint:staticcheck
|
||||
dashboard = &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: folderID}
|
||||
fldr = &dashboards.Dashboard{OrgID: orgID, UID: folderUID, IsFolder: true}
|
||||
dashboard = &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderUID: folderUID}
|
||||
fldr = &dashboards.Dashboard{OrgID: orgID, UID: folderUID, IsFolder: true}
|
||||
)
|
||||
|
||||
type accessControlGuardianTestCase struct {
|
||||
@@ -80,7 +78,7 @@ func TestAccessControlDashboardGuardian_CanSave(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to save dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
@@ -89,17 +87,6 @@ func TestAccessControlDashboardGuardian_CanSave(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to save dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to save dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -237,7 +224,7 @@ func TestAccessControlDashboardGuardian_CanEdit(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to edit dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
@@ -246,17 +233,6 @@ func TestAccessControlDashboardGuardian_CanEdit(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to edit dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to edit dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -410,7 +386,7 @@ func TestAccessControlDashboardGuardian_CanView(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to view dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsRead,
|
||||
@@ -419,17 +395,6 @@ func TestAccessControlDashboardGuardian_CanView(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to view dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsRead,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to view dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -530,6 +495,7 @@ func TestAccessControlDashboardGuardian_CanView(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccessControlDashboardGuardian_CanAdmin(t *testing.T) {
|
||||
tests := []accessControlGuardianTestCase{
|
||||
{
|
||||
@@ -579,7 +545,7 @@ func TestAccessControlDashboardGuardian_CanAdmin(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to admin dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsPermissionsRead,
|
||||
@@ -592,21 +558,6 @@ func TestAccessControlDashboardGuardian_CanAdmin(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to admin dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsPermissionsRead,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
{
|
||||
Action: dashboards.ActionDashboardsPermissionsWrite,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to admin dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -821,7 +772,7 @@ func TestAccessControlDashboardGuardian_CanDelete(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to delete dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsDelete,
|
||||
@@ -830,17 +781,6 @@ func TestAccessControlDashboardGuardian_CanDelete(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to delete dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsDelete,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to delete dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -1019,8 +959,6 @@ func setupAccessControlGuardianTest(
|
||||
folderSvc := foldertest.NewFakeService()
|
||||
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
// nolint:staticcheck
|
||||
folderStore.On("GetFolderByID", mock.Anything, mock.Anything, mock.Anything).Maybe().Return(&folder.Folder{ID: folderID, UID: folderUID, OrgID: orgID}, nil)
|
||||
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewDashboardUIDScopeResolver(folderStore, fakeDashboardService, folderSvc))
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewFolderUIDScopeResolver(folderSvc))
|
||||
|
||||
Reference in New Issue
Block a user