RBAC: Remove dashboard guardians pt 3 (#102558)
* remove usage of New dashboard guardian * fix tests
This commit is contained in:
+20
-19
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/web/webtest"
|
||||
)
|
||||
@@ -110,7 +109,10 @@ func TestAPI_Annotations(t *testing.T) {
|
||||
path: "/api/annotations/2",
|
||||
method: http.MethodPut,
|
||||
expectedCode: http.StatusOK,
|
||||
permissions: []accesscontrol.Permission{{Action: accesscontrol.ActionAnnotationsWrite, Scope: accesscontrol.ScopeAnnotationsTypeDashboard}},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: accesscontrol.ActionAnnotationsWrite, Scope: accesscontrol.ScopeAnnotationsTypeDashboard},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should not be able to update dashboard annotation without correct permission",
|
||||
@@ -162,7 +164,10 @@ func TestAPI_Annotations(t *testing.T) {
|
||||
path: "/api/annotations/2",
|
||||
method: http.MethodPatch,
|
||||
expectedCode: http.StatusOK,
|
||||
permissions: []accesscontrol.Permission{{Action: accesscontrol.ActionAnnotationsWrite, Scope: accesscontrol.ScopeAnnotationsTypeDashboard}},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: accesscontrol.ActionAnnotationsWrite, Scope: accesscontrol.ScopeAnnotationsTypeDashboard},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should not be able to patch dashboard annotation without correct permission",
|
||||
@@ -215,7 +220,10 @@ func TestAPI_Annotations(t *testing.T) {
|
||||
method: http.MethodPost,
|
||||
body: "{\"dashboardId\": 2,\"text\": \"test\"}",
|
||||
expectedCode: http.StatusOK,
|
||||
permissions: []accesscontrol.Permission{{Action: accesscontrol.ActionAnnotationsCreate, Scope: accesscontrol.ScopeAnnotationsTypeDashboard}},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: accesscontrol.ActionAnnotationsCreate, Scope: accesscontrol.ScopeAnnotationsTypeDashboard},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should not be able to create dashboard annotation without correct permission",
|
||||
@@ -273,7 +281,10 @@ func TestAPI_Annotations(t *testing.T) {
|
||||
path: "/api/annotations/2",
|
||||
method: http.MethodDelete,
|
||||
expectedCode: http.StatusOK,
|
||||
permissions: []accesscontrol.Permission{{Action: accesscontrol.ActionAnnotationsDelete, Scope: accesscontrol.ScopeAnnotationsTypeDashboard}},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: accesscontrol.ActionAnnotationsDelete, Scope: accesscontrol.ScopeAnnotationsTypeDashboard},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should not be able to delete dashboard annotation without correct permission",
|
||||
@@ -341,7 +352,10 @@ func TestAPI_Annotations(t *testing.T) {
|
||||
body: "{\"dashboardId\": 2, \"panelId\": 1}",
|
||||
method: http.MethodPost,
|
||||
expectedCode: http.StatusOK,
|
||||
permissions: []accesscontrol.Permission{{Action: accesscontrol.ActionAnnotationsDelete, Scope: accesscontrol.ScopeAnnotationsTypeDashboard}},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: accesscontrol.ActionAnnotationsDelete, Scope: accesscontrol.ScopeAnnotationsTypeDashboard},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeDashboardsAll},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should not be able to mass delete dashboard annotations without correct permission",
|
||||
@@ -382,10 +396,6 @@ func TestAPI_Annotations(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
// Don't need access to dashboards if annotationPermissionUpdate is enabled
|
||||
if len(tt.featureFlags) == 0 {
|
||||
setUpRBACGuardian(t)
|
||||
}
|
||||
server := SetupAPITestServer(t, func(hs *HTTPServer) {
|
||||
hs.Cfg = setting.NewCfg()
|
||||
repo := annotationstest.NewFakeAnnotationsRepo()
|
||||
@@ -518,12 +528,3 @@ func TestService_AnnotationTypeScopeResolver(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func setUpRBACGuardian(t *testing.T) {
|
||||
origNewGuardian := guardian.New
|
||||
t.Cleanup(func() {
|
||||
guardian.New = origNewGuardian
|
||||
})
|
||||
|
||||
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{CanEditValue: true, CanViewValue: true})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user