mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: prepare for removing RBACenabled
config option (#73845)
prepare for removing RBACenabled config option
This commit is contained in:
parent
31e29de024
commit
ca46a5c1af
@ -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{
|
||||
|
@ -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
|
||||
})
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user