diff --git a/pkg/api/common_test.go b/pkg/api/common_test.go index 4cbdbd9641c..2b5777c30e6 100644 --- a/pkg/api/common_test.go +++ b/pkg/api/common_test.go @@ -224,7 +224,6 @@ func setupSimpleHTTPServer(features *featuremgmt.FeatureManager) *HTTPServer { features = featuremgmt.WithFeatures() } cfg := setting.NewCfg() - cfg.RBACEnabled = false cfg.IsFeatureToggleEnabled = features.IsEnabled return &HTTPServer{ diff --git a/pkg/api/folder_test.go b/pkg/api/folder_test.go index 7d3b12f8808..6ad16c110f0 100644 --- a/pkg/api/folder_test.go +++ b/pkg/api/folder_test.go @@ -120,9 +120,7 @@ func TestFoldersCreateAPIEndpoint(t *testing.T) { folderPermService.On("SetPermissions", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]accesscontrol.ResourcePermission{}, nil) srv := SetupAPITestServer(t, func(hs *HTTPServer) { - hs.Cfg = &setting.Cfg{ - RBACEnabled: true, - } + hs.Cfg = setting.NewCfg() if tc.withNestedFolders { hs.Features = featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders) @@ -232,9 +230,7 @@ func TestFoldersUpdateAPIEndpoint(t *testing.T) { folderService.ExpectedError = tc.expectedFolderSvcError srv := SetupAPITestServer(t, func(hs *HTTPServer) { - hs.Cfg = &setting.Cfg{ - RBACEnabled: true, - } + hs.Cfg = setting.NewCfg() hs.folderService = folderService }) @@ -273,9 +269,7 @@ func TestHTTPServer_FolderMetadata(t *testing.T) { folderService := &foldertest.FakeService{} features := featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders) server := SetupAPITestServer(t, func(hs *HTTPServer) { - hs.Cfg = &setting.Cfg{ - RBACEnabled: true, - } + hs.Cfg = setting.NewCfg() hs.folderService = folderService hs.QuotaService = quotatest.New(false, nil) hs.SearchService = &mockSearchService{ @@ -404,9 +398,7 @@ func TestFolderMoveAPIEndpoint(t *testing.T) { for _, tc := range tcs { srv := SetupAPITestServer(t, func(hs *HTTPServer) { - hs.Cfg = &setting.Cfg{ - RBACEnabled: true, - } + hs.Cfg = setting.NewCfg() hs.Features = featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders) hs.folderService = folderService }) @@ -479,9 +471,7 @@ func TestFolderGetAPIEndpoint(t *testing.T) { for _, tc := range tcs { srv := SetupAPITestServer(t, func(hs *HTTPServer) { - hs.Cfg = &setting.Cfg{ - RBACEnabled: true, - } + hs.Cfg = setting.NewCfg() hs.Features = tc.features hs.folderService = folderService }) diff --git a/pkg/services/accesscontrol/acimpl/service_test.go b/pkg/services/accesscontrol/acimpl/service_test.go index d8e365e7db0..598af455117 100644 --- a/pkg/services/accesscontrol/acimpl/service_test.go +++ b/pkg/services/accesscontrol/acimpl/service_test.go @@ -24,7 +24,6 @@ import ( func setupTestEnv(t testing.TB) *Service { t.Helper() cfg := setting.NewCfg() - cfg.RBACEnabled = true ac := &Service{ cfg: cfg, @@ -41,12 +40,10 @@ func setupTestEnv(t testing.TB) *Service { func TestUsageMetrics(t *testing.T) { tests := []struct { name string - enabled bool expectedValue int }{ { name: "Expecting metric with value 1", - enabled: true, expectedValue: 1, }, } @@ -54,7 +51,6 @@ func TestUsageMetrics(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cfg := setting.NewCfg() - cfg.RBACEnabled = tt.enabled s := ProvideOSSService( cfg, diff --git a/pkg/services/dashboards/database/database_folder_test.go b/pkg/services/dashboards/database/database_folder_test.go index 7a69a168d03..b97e25f4acc 100644 --- a/pkg/services/dashboards/database/database_folder_test.go +++ b/pkg/services/dashboards/database/database_folder_test.go @@ -45,7 +45,6 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) { setup := func() { sqlStore = db.InitTestDB(t) - sqlStore.Cfg.RBACEnabled = false quotaService := quotatest.New(false, nil) var err error dashboardStore, err = ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore, sqlStore.Cfg), quotaService) @@ -247,7 +246,6 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) { setup := func() { sqlStore = db.InitTestDB(t) - sqlStore.Cfg.RBACEnabled = true quotaService := quotatest.New(false, nil) // enable nested folders so that the folder table is populated for all the tests diff --git a/pkg/services/publicdashboards/api/api_test.go b/pkg/services/publicdashboards/api/api_test.go index b1307edf99b..5e1b1705333 100644 --- a/pkg/services/publicdashboards/api/api_test.go +++ b/pkg/services/publicdashboards/api/api_test.go @@ -22,10 +22,9 @@ import ( "github.com/grafana/grafana/pkg/util/errutil" ) -var userAdmin = &user.SignedInUser{UserID: 1, OrgID: 1, OrgRole: org.RoleAdmin, Login: "testAdminUser"} -var userAdminRBAC = &user.SignedInUser{UserID: 2, OrgID: 1, OrgRole: org.RoleAdmin, Login: "testAdminUserRBAC", Permissions: map[int64]map[string][]string{1: {dashboards.ActionDashboardsPublicWrite: {dashboards.ScopeDashboardsAll}}}} -var userViewer = &user.SignedInUser{UserID: 3, OrgID: 1, OrgRole: org.RoleViewer, Login: "testViewerUser"} -var userViewerRBAC = &user.SignedInUser{UserID: 4, OrgID: 1, OrgRole: org.RoleViewer, Login: "testViewerUserRBAC", Permissions: map[int64]map[string][]string{1: {dashboards.ActionDashboardsRead: {dashboards.ScopeDashboardsAll}}}} +var userNoRBACPerms = &user.SignedInUser{UserID: 1, OrgID: 1, OrgRole: org.RoleAdmin, Login: "testAdminUserNoRBACPerms"} +var userAdmin = &user.SignedInUser{UserID: 2, OrgID: 1, OrgRole: org.RoleAdmin, Login: "testAdminUserRBAC", Permissions: map[int64]map[string][]string{1: {dashboards.ActionDashboardsPublicWrite: {dashboards.ScopeDashboardsAll}}}} +var userViewer = &user.SignedInUser{UserID: 4, OrgID: 1, OrgRole: org.RoleViewer, Login: "testViewerUserRBAC", Permissions: map[int64]map[string][]string{1: {dashboards.ActionDashboardsRead: {dashboards.ScopeDashboardsAll}}}} var anonymousUser = &user.SignedInUser{IsAnonymous: true} type JsonErrResponse struct { @@ -78,7 +77,6 @@ func TestAPIFeatureFlag(t *testing.T) { for _, test := range testCases { t.Run(test.Name, func(t *testing.T) { cfg := setting.NewCfg() - cfg.RBACEnabled = false service := publicdashboards.NewFakePublicDashboardService(t) features := featuremgmt.WithFeatures() testServer := setupTestServer(t, cfg, features, service, nil, userAdmin) @@ -137,7 +135,6 @@ func TestAPIListPublicDashboard(t *testing.T) { Return(test.Response, test.ResponseErr).Maybe() cfg := setting.NewCfg() - cfg.RBACEnabled = false features := featuremgmt.WithFeatures(featuremgmt.FlagPublicDashboards) testServer := setupTestServer(t, cfg, features, service, nil, test.User) @@ -314,7 +311,7 @@ func TestAPIGetPublicDashboard(t *testing.T) { ExpectedHttpResponse: http.StatusNotFound, PublicDashboardResult: nil, PublicDashboardErr: ErrDashboardNotFound.Errorf(""), - User: userViewerRBAC, + User: userViewer, ShouldCallService: true, }, { @@ -323,7 +320,7 @@ func TestAPIGetPublicDashboard(t *testing.T) { ExpectedHttpResponse: http.StatusInternalServerError, PublicDashboardResult: nil, PublicDashboardErr: errors.New("database broken"), - User: userViewerRBAC, + User: userViewer, ShouldCallService: true, }, { @@ -332,7 +329,7 @@ func TestAPIGetPublicDashboard(t *testing.T) { ExpectedHttpResponse: http.StatusOK, PublicDashboardResult: pubdash, PublicDashboardErr: nil, - User: userViewerRBAC, + User: userViewer, ShouldCallService: true, }, { @@ -340,7 +337,7 @@ func TestAPIGetPublicDashboard(t *testing.T) { ExpectedHttpResponse: http.StatusForbidden, PublicDashboardResult: pubdash, PublicDashboardErr: nil, - User: userViewer, + User: userNoRBACPerms, ShouldCallService: false, }, } @@ -400,7 +397,7 @@ func TestApiCreatePublicDashboard(t *testing.T) { ExpectedHttpResponse: http.StatusInternalServerError, publicDashboard: &PublicDashboard{}, SaveDashboardErr: ErrInternalServerError.Errorf(""), - User: userAdminRBAC, + User: userAdmin, ShouldCallService: true, }, { @@ -408,7 +405,7 @@ func TestApiCreatePublicDashboard(t *testing.T) { ExpectedHttpResponse: http.StatusNotFound, publicDashboard: &PublicDashboard{}, SaveDashboardErr: ErrDashboardNotFound.Errorf(""), - User: userAdminRBAC, + User: userAdmin, ShouldCallService: true, }, { @@ -417,7 +414,7 @@ func TestApiCreatePublicDashboard(t *testing.T) { publicDashboard: &PublicDashboard{IsEnabled: true}, ExpectedHttpResponse: http.StatusOK, SaveDashboardErr: nil, - User: userAdminRBAC, + User: userAdmin, ShouldCallService: true, }, { @@ -425,7 +422,7 @@ func TestApiCreatePublicDashboard(t *testing.T) { ExpectedHttpResponse: http.StatusForbidden, publicDashboard: &PublicDashboard{IsEnabled: true}, SaveDashboardErr: nil, - User: userAdmin, + User: userNoRBACPerms, ShouldCallService: false, }, } diff --git a/pkg/services/publicdashboards/api/query_test.go b/pkg/services/publicdashboards/api/query_test.go index af827e266d7..5e9aced61d6 100644 --- a/pkg/services/publicdashboards/api/query_test.go +++ b/pkg/services/publicdashboards/api/query_test.go @@ -88,7 +88,6 @@ func TestAPIViewPublicDashboard(t *testing.T) { Return(&PublicDashboard{Uid: "pubdashuid"}, test.DashboardResult, test.Err).Maybe() cfg := setting.NewCfg() - cfg.RBACEnabled = false testServer := setupTestServer( t, @@ -326,7 +325,6 @@ func TestIntegrationUnauthenticatedUserCanGetPubdashPanelQueryData(t *testing.T) cfg := setting.NewCfg() ac := acmock.New() ws := publicdashboardsService.ProvideServiceWrapper(store) - cfg.RBACEnabled = false service := publicdashboardsService.ProvideService(cfg, store, qds, annotationsService, ac, ws) pubdash, err := service.Create(context.Background(), &user.SignedInUser{}, savePubDashboardCmd) require.NoError(t, err) @@ -415,7 +413,6 @@ func TestAPIGetAnnotations(t *testing.T) { for _, test := range testCases { t.Run(test.Name, func(t *testing.T) { cfg := setting.NewCfg() - cfg.RBACEnabled = false service := publicdashboards.NewFakePublicDashboardService(t) if test.ExpectedServiceCalled {