Access Control: Add test flag to enable access control (#46780)
* Add feature flags options to test db
This commit is contained in:
@@ -231,16 +231,16 @@ func setupAccessControlScenarioContext(t *testing.T, cfg *setting.Cfg, url strin
|
||||
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
||||
cfg.Quota.Enabled = false
|
||||
|
||||
mockStore := sqlstore.InitTestDB(t)
|
||||
store := sqlstore.InitTestDB(t)
|
||||
hs := &HTTPServer{
|
||||
Cfg: cfg,
|
||||
Bus: bus.GetBus(),
|
||||
Live: newTestLive(t),
|
||||
Live: newTestLive(t, store),
|
||||
Features: features,
|
||||
QuotaService: "a.QuotaService{Cfg: cfg},
|
||||
RouteRegister: routing.NewRouteRegister(),
|
||||
AccessControl: accesscontrolmock.New().WithPermissions(permissions),
|
||||
searchUsersService: searchusers.ProvideUsersService(mockStore, filters.ProvideOSSSearchUserFilter()),
|
||||
searchUsersService: searchusers.ProvideUsersService(store, filters.ProvideOSSSearchUserFilter()),
|
||||
ldapGroups: ldap.ProvideGroupsService(),
|
||||
}
|
||||
|
||||
@@ -352,8 +352,11 @@ func setupHTTPServerWithMockDb(t *testing.T, useFakeAccessControl bool, enableAc
|
||||
}
|
||||
|
||||
func setupHTTPServerWithCfg(t *testing.T, useFakeAccessControl, enableAccessControl bool, cfg *setting.Cfg) accessControlScenarioContext {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
db.Cfg = cfg
|
||||
var featureFlags []string
|
||||
if enableAccessControl {
|
||||
featureFlags = append(featureFlags, featuremgmt.FlagAccesscontrol)
|
||||
}
|
||||
db := sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: featureFlags})
|
||||
return setupHTTPServerWithCfgDb(t, useFakeAccessControl, enableAccessControl, cfg, db, db)
|
||||
}
|
||||
|
||||
@@ -374,7 +377,7 @@ func setupHTTPServerWithCfgDb(t *testing.T, useFakeAccessControl, enableAccessCo
|
||||
Cfg: cfg,
|
||||
Features: features,
|
||||
Bus: bus.GetBus(),
|
||||
Live: newTestLive(t),
|
||||
Live: newTestLive(t, db),
|
||||
QuotaService: "a.QuotaService{Cfg: cfg},
|
||||
RouteRegister: routeRegister,
|
||||
SQLStore: store,
|
||||
|
||||
@@ -85,14 +85,14 @@ func TestGetHomeDashboard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newTestLive(t *testing.T) *live.GrafanaLive {
|
||||
func newTestLive(t *testing.T, store *sqlstore.SQLStore) *live.GrafanaLive {
|
||||
features := featuremgmt.WithFeatures()
|
||||
cfg := &setting.Cfg{AppURL: "http://localhost:3000/"}
|
||||
cfg.IsFeatureToggleEnabled = features.IsEnabled
|
||||
gLive, err := live.ProvideService(nil, cfg,
|
||||
routing.NewRouteRegister(),
|
||||
nil, nil, nil,
|
||||
sqlstore.InitTestDB(t),
|
||||
store,
|
||||
nil,
|
||||
&usagestats.UsageStatsMock{T: t},
|
||||
nil,
|
||||
@@ -216,10 +216,11 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
features := featuremgmt.WithFeatures()
|
||||
dashboardStore := database.ProvideDashboardStore(sqlstore.InitTestDB(t))
|
||||
sql := sqlstore.InitTestDB(t)
|
||||
dashboardStore := database.ProvideDashboardStore(sql)
|
||||
hs := &HTTPServer{
|
||||
Cfg: cfg,
|
||||
Live: newTestLive(t),
|
||||
Live: newTestLive(t, sql),
|
||||
LibraryPanelService: &mockLibraryPanelService{},
|
||||
LibraryElementService: &mockLibraryElementService{},
|
||||
SQLStore: mockSQLStore,
|
||||
@@ -1005,7 +1006,7 @@ func postDashboardScenario(t *testing.T, desc string, url string, routePattern s
|
||||
Bus: bus.GetBus(),
|
||||
Cfg: cfg,
|
||||
ProvisioningService: provisioning.NewProvisioningServiceMock(context.Background()),
|
||||
Live: newTestLive(t),
|
||||
Live: newTestLive(t, sqlstore.InitTestDB(t)),
|
||||
QuotaService: "a.QuotaService{
|
||||
Cfg: cfg,
|
||||
},
|
||||
@@ -1042,7 +1043,7 @@ func postDiffScenario(t *testing.T, desc string, url string, routePattern string
|
||||
Cfg: cfg,
|
||||
Bus: bus.GetBus(),
|
||||
ProvisioningService: provisioning.NewProvisioningServiceMock(context.Background()),
|
||||
Live: newTestLive(t),
|
||||
Live: newTestLive(t, sqlstore.InitTestDB(t)),
|
||||
QuotaService: "a.QuotaService{Cfg: cfg},
|
||||
LibraryPanelService: &mockLibraryPanelService{},
|
||||
LibraryElementService: &mockLibraryElementService{},
|
||||
@@ -1079,7 +1080,7 @@ func restoreDashboardVersionScenario(t *testing.T, desc string, url string, rout
|
||||
Cfg: cfg,
|
||||
Bus: bus.GetBus(),
|
||||
ProvisioningService: provisioning.NewProvisioningServiceMock(context.Background()),
|
||||
Live: newTestLive(t),
|
||||
Live: newTestLive(t, sqlstore.InitTestDB(t)),
|
||||
QuotaService: "a.QuotaService{Cfg: cfg},
|
||||
LibraryPanelService: &mockLibraryPanelService{},
|
||||
LibraryElementService: &mockLibraryElementService{},
|
||||
|
||||
@@ -217,8 +217,6 @@ func TestTeamAPIEndpoint_CreateTeam_FGAC(t *testing.T) {
|
||||
|
||||
func TestTeamAPIEndpoint_SearchTeams_FGAC(t *testing.T) {
|
||||
sc := setupHTTPServer(t, true, true)
|
||||
sc.db = sqlstore.InitTestDB(t)
|
||||
|
||||
// Seed three teams
|
||||
for i := 1; i <= 3; i++ {
|
||||
_, err := sc.db.CreateTeam(fmt.Sprintf("team%d", i), fmt.Sprintf("team%d@example.org", i), 1)
|
||||
|
||||
Reference in New Issue
Block a user