mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Replace sqlstore with db interface (#85366)
* replace sqlstore with db interface in a few packages * remove from stats * remove sqlstore in admin test * remove sqlstore from api plugin tests * fix another createUser * remove sqlstore in publicdashboards * remove sqlstore from orgs * clean up orguser test * more clean up in sso * clean up service accounts * further cleanup * more cleanup in accesscontrol * last cleanup in accesscontrol * clean up teams * more removals * split cfg from db in testenv * few remaining fixes * fix test with bus * pass cfg for testing inside db as an option * set query retries when no opts provided * revert golden test data * rebase and rollback
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
@@ -66,7 +67,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type benchScenario struct {
|
type benchScenario struct {
|
||||||
db *sqlstore.SQLStore
|
db db.DB
|
||||||
// signedInUser is the user that is signed in to the server
|
// signedInUser is the user that is signed in to the server
|
||||||
cfg *setting.Cfg
|
cfg *setting.Cfg
|
||||||
signedInUser *user.SignedInUser
|
signedInUser *user.SignedInUser
|
||||||
@@ -448,7 +449,7 @@ func setupServer(b testing.TB, sc benchScenario, features featuremgmt.FeatureTog
|
|||||||
|
|
||||||
quotaSrv := quotatest.New(false, nil)
|
quotaSrv := quotatest.New(false, nil)
|
||||||
|
|
||||||
dashStore, err := database.ProvideDashboardStore(sc.db, sc.db.Cfg, features, tagimpl.ProvideService(sc.db), quotaSrv)
|
dashStore, err := database.ProvideDashboardStore(sc.db, sc.cfg, features, tagimpl.ProvideService(sc.db), quotaSrv)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
||||||
folderStore := folderimpl.ProvideDashboardFolderStore(sc.db)
|
folderStore := folderimpl.ProvideDashboardFolderStore(sc.db)
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ import (
|
|||||||
spm "github.com/grafana/grafana/pkg/services/secrets/kvstore/migrations"
|
spm "github.com/grafana/grafana/pkg/services/secrets/kvstore/migrations"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||||
"github.com/grafana/grafana/pkg/services/shorturls"
|
"github.com/grafana/grafana/pkg/services/shorturls"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/star"
|
"github.com/grafana/grafana/pkg/services/star"
|
||||||
starApi "github.com/grafana/grafana/pkg/services/star/api"
|
starApi "github.com/grafana/grafana/pkg/services/star/api"
|
||||||
"github.com/grafana/grafana/pkg/services/stats"
|
"github.com/grafana/grafana/pkg/services/stats"
|
||||||
@@ -231,7 +230,7 @@ type ServerOptions struct {
|
|||||||
|
|
||||||
func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routing.RouteRegister, bus bus.Bus,
|
func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routing.RouteRegister, bus bus.Bus,
|
||||||
renderService rendering.Service, licensing licensing.Licensing, hooksService *hooks.HooksService,
|
renderService rendering.Service, licensing licensing.Licensing, hooksService *hooks.HooksService,
|
||||||
cacheService *localcache.CacheService, sqlStore *sqlstore.SQLStore,
|
cacheService *localcache.CacheService, sqlStore db.DB,
|
||||||
pluginRequestValidator validations.PluginRequestValidator, pluginStaticRouteResolver plugins.StaticRouteResolver,
|
pluginRequestValidator validations.PluginRequestValidator, pluginStaticRouteResolver plugins.StaticRouteResolver,
|
||||||
pluginDashboardService plugindashboards.Service, pluginStore pluginstore.Store, pluginClient plugins.Client,
|
pluginDashboardService plugindashboards.Service, pluginStore pluginstore.Store, pluginClient plugins.Client,
|
||||||
pluginErrorResolver plugins.ErrorResolver, pluginInstaller plugins.Installer, settingsProvider setting.Provider,
|
pluginErrorResolver plugins.ErrorResolver, pluginInstaller plugins.Installer, settingsProvider setting.Provider,
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
@@ -36,14 +35,14 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/web/webtest"
|
"github.com/grafana/grafana/pkg/web/webtest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setUpGetOrgUsersDB(t *testing.T, sqlStore *sqlstore.SQLStore) {
|
func setUpGetOrgUsersDB(t *testing.T, sqlStore db.DB, cfg *setting.Cfg) {
|
||||||
sqlStore.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
sqlStore.Cfg.AutoAssignOrgId = int(testOrgID)
|
cfg.AutoAssignOrgId = int(testOrgID)
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
id, err := orgService.GetOrCreate(context.Background(), "testOrg")
|
id, err := orgService.GetOrCreate(context.Background(), "testOrg")
|
||||||
@@ -68,7 +67,7 @@ func TestOrgUsersAPIEndpoint_userLoggedIn(t *testing.T) {
|
|||||||
orgService := orgtest.NewOrgServiceFake()
|
orgService := orgtest.NewOrgServiceFake()
|
||||||
orgService.ExpectedSearchOrgUsersResult = &org.SearchOrgUsersQueryResult{}
|
orgService.ExpectedSearchOrgUsersResult = &org.SearchOrgUsersQueryResult{}
|
||||||
hs.orgService = orgService
|
hs.orgService = orgService
|
||||||
setUpGetOrgUsersDB(t, sqlStore)
|
setUpGetOrgUsersDB(t, sqlStore, settings)
|
||||||
mock := dbtest.NewFakeDB()
|
mock := dbtest.NewFakeDB()
|
||||||
|
|
||||||
loggedInUserScenario(t, "When calling GET on", "api/org/users", "api/org/users", func(sc *scenarioContext) {
|
loggedInUserScenario(t, "When calling GET on", "api/org/users", "api/org/users", func(sc *scenarioContext) {
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/httpclient"
|
"github.com/grafana/grafana/pkg/infra/httpclient"
|
||||||
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/grpcserver"
|
"github.com/grafana/grafana/pkg/services/grpcserver"
|
||||||
"github.com/grafana/grafana/pkg/services/notifications"
|
"github.com/grafana/grafana/pkg/services/notifications"
|
||||||
"github.com/grafana/grafana/pkg/services/oauthtoken/oauthtokentest"
|
"github.com/grafana/grafana/pkg/services/oauthtoken/oauthtokentest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/web"
|
"github.com/grafana/grafana/pkg/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideTestEnv(
|
func ProvideTestEnv(
|
||||||
server *Server,
|
server *Server,
|
||||||
store *sqlstore.SQLStore,
|
db db.DB,
|
||||||
|
cfg *setting.Cfg,
|
||||||
ns *notifications.NotificationServiceMock,
|
ns *notifications.NotificationServiceMock,
|
||||||
grpcServer grpcserver.Provider,
|
grpcServer grpcserver.Provider,
|
||||||
pluginRegistry registry.Service,
|
pluginRegistry registry.Service,
|
||||||
@@ -23,7 +25,8 @@ func ProvideTestEnv(
|
|||||||
) (*TestEnv, error) {
|
) (*TestEnv, error) {
|
||||||
return &TestEnv{
|
return &TestEnv{
|
||||||
Server: server,
|
Server: server,
|
||||||
SQLStore: store,
|
SQLStore: db,
|
||||||
|
Cfg: cfg,
|
||||||
NotificationService: ns,
|
NotificationService: ns,
|
||||||
GRPCServer: grpcServer,
|
GRPCServer: grpcServer,
|
||||||
PluginRegistry: pluginRegistry,
|
PluginRegistry: pluginRegistry,
|
||||||
@@ -35,7 +38,8 @@ func ProvideTestEnv(
|
|||||||
|
|
||||||
type TestEnv struct {
|
type TestEnv struct {
|
||||||
Server *Server
|
Server *Server
|
||||||
SQLStore *sqlstore.SQLStore
|
SQLStore db.DB
|
||||||
|
Cfg *setting.Cfg
|
||||||
NotificationService *notifications.NotificationServiceMock
|
NotificationService *notifications.NotificationServiceMock
|
||||||
GRPCServer grpcserver.Provider
|
GRPCServer grpcserver.Provider
|
||||||
PluginRegistry registry.Service
|
PluginRegistry registry.Service
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Ser
|
|||||||
|
|
||||||
func InitializeForTest(t sqlutil.ITestDB, cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*TestEnv, error) {
|
func InitializeForTest(t sqlutil.ITestDB, cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*TestEnv, error) {
|
||||||
wire.Build(wireExtsTestSet)
|
wire.Build(wireExtsTestSet)
|
||||||
return &TestEnv{Server: &Server{}, SQLStore: &sqlstore.SQLStore{}}, nil
|
return &TestEnv{Server: &Server{}, SQLStore: &sqlstore.SQLStore{}, Cfg: &setting.Cfg{}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitializeForCLI(cfg *setting.Cfg) (Runner, error) {
|
func InitializeForCLI(cfg *setting.Cfg) (Runner, error) {
|
||||||
|
|||||||
@@ -13,17 +13,18 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/web"
|
"github.com/grafana/grafana/pkg/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ func TestApi_getDescription(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, _, _ := setupTestEnvironment(t, tt.options)
|
service, _, _, _ := setupTestEnvironment(t, tt.options)
|
||||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/access-control/%s/description", tt.options.Resource), nil)
|
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/access-control/%s/description", tt.options.Resource), nil)
|
||||||
@@ -162,10 +163,10 @@ func TestApi_getPermissions(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, sql, _ := setupTestEnvironment(t, testOptions)
|
service, sql, cfg, _ := setupTestEnvironment(t, testOptions)
|
||||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||||
|
|
||||||
seedPermissions(t, tt.resourceID, sql, service)
|
seedPermissions(t, tt.resourceID, sql, cfg, service)
|
||||||
|
|
||||||
permissions, recorder := getPermission(t, server, testOptions.Resource, tt.resourceID)
|
permissions, recorder := getPermission(t, server, testOptions.Resource, tt.resourceID)
|
||||||
assert.Equal(t, tt.expectedStatus, recorder.Code)
|
assert.Equal(t, tt.expectedStatus, recorder.Code)
|
||||||
@@ -239,7 +240,7 @@ func TestApi_setBuiltinRolePermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, _, _ := setupTestEnvironment(t, testOptions)
|
service, _, _, _ := setupTestEnvironment(t, testOptions)
|
||||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||||
|
|
||||||
recorder := setPermission(t, server, testOptions.Resource, tt.resourceID, tt.permission, "builtInRoles", tt.builtInRole)
|
recorder := setPermission(t, server, testOptions.Resource, tt.resourceID, tt.permission, "builtInRoles", tt.builtInRole)
|
||||||
@@ -317,7 +318,7 @@ func TestApi_setTeamPermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, _, teamSvc := setupTestEnvironment(t, testOptions)
|
service, _, _, teamSvc := setupTestEnvironment(t, testOptions)
|
||||||
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
server := setupTestServer(t, &user.SignedInUser{OrgID: 1, Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)}}, service)
|
||||||
|
|
||||||
// seed team
|
// seed team
|
||||||
@@ -400,16 +401,16 @@ func TestApi_setUserPermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, sql, _ := setupTestEnvironment(t, testOptions)
|
service, sql, cfg, _ := setupTestEnvironment(t, testOptions)
|
||||||
server := setupTestServer(t, &user.SignedInUser{
|
server := setupTestServer(t, &user.SignedInUser{
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)},
|
Permissions: map[int64]map[string][]string{1: accesscontrol.GroupScopesByAction(tt.permissions)},
|
||||||
}, service)
|
}, service)
|
||||||
|
|
||||||
// seed user
|
// seed user
|
||||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
_, err = usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -505,19 +506,19 @@ func checkSeededPermissions(t *testing.T, permissions []resourcePermissionDTO) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func seedPermissions(t *testing.T, resourceID string, sql *sqlstore.SQLStore, service *Service) {
|
func seedPermissions(t *testing.T, resourceID string, sql db.DB, cfg *setting.Cfg, service *Service) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
// seed team 1 with "Edit" permission on dashboard 1
|
// seed team 1 with "Edit" permission on dashboard 1
|
||||||
teamSvc, err := teamimpl.ProvideService(sql, sql.Cfg)
|
teamSvc, err := teamimpl.ProvideService(sql, cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
team, err := teamSvc.CreateTeam("test", "test@test.com", 1)
|
team, err := teamSvc.CreateTeam("test", "test@test.com", 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = service.SetTeamPermission(context.Background(), team.OrgID, team.ID, resourceID, "Edit")
|
_, err = service.SetTeamPermission(context.Background(), team.OrgID, team.ID, resourceID, "Edit")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// seed user 1 with "View" permission on dashboard 1
|
// seed user 1 with "View" permission on dashboard 1
|
||||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
u, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
u, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/team"
|
"github.com/grafana/grafana/pkg/services/team"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||||
@@ -44,16 +43,16 @@ func TestService_SetUserPermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, sql, _ := setupTestEnvironment(t, Options{
|
service, sql, cfg, _ := setupTestEnvironment(t, Options{
|
||||||
Resource: "dashboards",
|
Resource: "dashboards",
|
||||||
Assignments: Assignments{Users: true},
|
Assignments: Assignments{Users: true},
|
||||||
PermissionsToActions: nil,
|
PermissionsToActions: nil,
|
||||||
})
|
})
|
||||||
|
|
||||||
// seed user
|
// seed user
|
||||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
user, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
user, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "test", OrgID: 1})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -92,7 +91,7 @@ func TestService_SetTeamPermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, _, teamSvc := setupTestEnvironment(t, Options{
|
service, _, _, teamSvc := setupTestEnvironment(t, Options{
|
||||||
Resource: "dashboards",
|
Resource: "dashboards",
|
||||||
Assignments: Assignments{Teams: true},
|
Assignments: Assignments{Teams: true},
|
||||||
PermissionsToActions: nil,
|
PermissionsToActions: nil,
|
||||||
@@ -136,7 +135,7 @@ func TestService_SetBuiltInRolePermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, _, _ := setupTestEnvironment(t, Options{
|
service, _, _, _ := setupTestEnvironment(t, Options{
|
||||||
Resource: "dashboards",
|
Resource: "dashboards",
|
||||||
Assignments: Assignments{BuiltInRoles: true},
|
Assignments: Assignments{BuiltInRoles: true},
|
||||||
PermissionsToActions: nil,
|
PermissionsToActions: nil,
|
||||||
@@ -209,12 +208,12 @@ func TestService_SetPermissions(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
service, sql, teamSvc := setupTestEnvironment(t, tt.options)
|
service, sql, cfg, teamSvc := setupTestEnvironment(t, tt.options)
|
||||||
|
|
||||||
// seed user
|
// seed user
|
||||||
orgSvc, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
orgSvc, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sql, orgSvc, sql.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sql, orgSvc, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "user", OrgID: 1})
|
_, err = usrSvc.Create(context.Background(), &user.CreateUserCommand{Login: "user", OrgID: 1})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -232,7 +231,7 @@ func TestService_SetPermissions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTestEnvironment(t *testing.T, ops Options) (*Service, *sqlstore.SQLStore, team.Service) {
|
func setupTestEnvironment(t *testing.T, ops Options) (*Service, db.DB, *setting.Cfg, team.Service) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
sql := db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
@@ -251,5 +250,5 @@ func setupTestEnvironment(t *testing.T, ops Options) (*Service, *sqlstore.SQLSto
|
|||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
return service, sql, teamSvc
|
return service, sql, cfg, teamSvc
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,17 +10,18 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
datasourcesService "github.com/grafana/grafana/pkg/services/datasources/service"
|
datasourcesService "github.com/grafana/grafana/pkg/services/datasources/service"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -74,12 +75,12 @@ func getDSPermissions(b *testing.B, store *store, dataSources []int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupResourceBenchmark(b *testing.B, dsNum, usersNum int) (*store, []int64) {
|
func setupResourceBenchmark(b *testing.B, dsNum, usersNum int) (*store, []int64) {
|
||||||
ac, sql := setupTestEnv(b)
|
ac, sql, cfg := setupTestEnv(b)
|
||||||
dataSources := GenerateDatasourcePermissions(b, sql, ac, dsNum, usersNum, permissionsPerDs)
|
dataSources := GenerateDatasourcePermissions(b, sql, cfg, ac, dsNum, usersNum, permissionsPerDs)
|
||||||
return ac, dataSources
|
return ac, dataSources
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateDatasourcePermissions(b *testing.B, db *sqlstore.SQLStore, ac *store, dsNum, usersNum, permissionsPerDs int) []int64 {
|
func GenerateDatasourcePermissions(b *testing.B, db db.DB, cfg *setting.Cfg, ac *store, dsNum, usersNum, permissionsPerDs int) []int64 {
|
||||||
dataSources := make([]int64, 0)
|
dataSources := make([]int64, 0)
|
||||||
for i := 0; i < dsNum; i++ {
|
for i := 0; i < dsNum; i++ {
|
||||||
addDSCommand := &datasources.AddDataSourceCommand{
|
addDSCommand := &datasources.AddDataSourceCommand{
|
||||||
@@ -94,7 +95,7 @@ func GenerateDatasourcePermissions(b *testing.B, db *sqlstore.SQLStore, ac *stor
|
|||||||
dataSources = append(dataSources, dataSource.ID)
|
dataSources = append(dataSources, dataSource.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
userIds, teamIds := generateTeamsAndUsers(b, db, usersNum)
|
userIds, teamIds := generateTeamsAndUsers(b, db, cfg, usersNum)
|
||||||
|
|
||||||
for _, dsID := range dataSources {
|
for _, dsID := range dataSources {
|
||||||
// Add DS permissions for the users
|
// Add DS permissions for the users
|
||||||
@@ -137,15 +138,15 @@ func GenerateDatasourcePermissions(b *testing.B, db *sqlstore.SQLStore, ac *stor
|
|||||||
return dataSources
|
return dataSources
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTeamsAndUsers(b *testing.B, db *sqlstore.SQLStore, users int) ([]int64, []int64) {
|
func generateTeamsAndUsers(b *testing.B, db db.DB, cfg *setting.Cfg, users int) ([]int64, []int64) {
|
||||||
teamSvc, err := teamimpl.ProvideService(db, db.Cfg)
|
teamSvc, err := teamimpl.ProvideService(db, cfg)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
numberOfTeams := int(math.Ceil(float64(users) / UsersPerTeam))
|
numberOfTeams := int(math.Ceil(float64(users) / UsersPerTeam))
|
||||||
globalUserId := 0
|
globalUserId := 0
|
||||||
qs := quotatest.New(false, nil)
|
qs := quotatest.New(false, nil)
|
||||||
orgSvc, err := orgimpl.ProvideService(db, db.Cfg, qs)
|
orgSvc, err := orgimpl.ProvideService(db, cfg, qs)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
usrSvc, err := userimpl.ProvideService(db, orgSvc, db.Cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgSvc, cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
userIds := make([]int64, 0)
|
userIds := make([]int64, 0)
|
||||||
teamIds := make([]int64, 0)
|
teamIds := make([]int64, 0)
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ func TestIntegrationStore_SetUserResourcePermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
store, _ := setupTestEnv(t)
|
store, _, _ := setupTestEnv(t)
|
||||||
|
|
||||||
for _, s := range test.seeds {
|
for _, s := range test.seeds {
|
||||||
_, err := store.SetUserResourcePermission(context.Background(), test.orgID, accesscontrol.User{ID: test.userID}, s, nil)
|
_, err := store.SetUserResourcePermission(context.Background(), test.orgID, accesscontrol.User{ID: test.userID}, s, nil)
|
||||||
@@ -176,7 +176,7 @@ func TestIntegrationStore_SetTeamResourcePermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
store, _ := setupTestEnv(t)
|
store, _, _ := setupTestEnv(t)
|
||||||
|
|
||||||
for _, s := range test.seeds {
|
for _, s := range test.seeds {
|
||||||
_, err := store.SetTeamResourcePermission(context.Background(), test.orgID, test.teamID, s, nil)
|
_, err := store.SetTeamResourcePermission(context.Background(), test.orgID, test.teamID, s, nil)
|
||||||
@@ -264,7 +264,7 @@ func TestIntegrationStore_SetBuiltInResourcePermission(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
store, _ := setupTestEnv(t)
|
store, _, _ := setupTestEnv(t)
|
||||||
|
|
||||||
for _, s := range test.seeds {
|
for _, s := range test.seeds {
|
||||||
_, err := store.SetBuiltInResourcePermission(context.Background(), test.orgID, test.builtInRole, s, nil)
|
_, err := store.SetBuiltInResourcePermission(context.Background(), test.orgID, test.builtInRole, s, nil)
|
||||||
@@ -339,7 +339,7 @@ func TestIntegrationStore_SetResourcePermissions(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
store, _ := setupTestEnv(t)
|
store, _, _ := setupTestEnv(t)
|
||||||
|
|
||||||
permissions, err := store.SetResourcePermissions(context.Background(), tt.orgID, tt.commands, ResourceHooks{})
|
permissions, err := store.SetResourcePermissions(context.Background(), tt.orgID, tt.commands, ResourceHooks{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -469,8 +469,8 @@ func TestIntegrationStore_GetResourcePermissions(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
store, sql := setupTestEnv(t)
|
store, sql, cfg := setupTestEnv(t)
|
||||||
orgService, err := orgimpl.ProvideService(sql, sql.Cfg, quotatest.New(false, nil))
|
orgService, err := orgimpl.ProvideService(sql, cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = sql.WithDbSession(context.Background(), func(sess *db.Session) error {
|
err = sql.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||||
@@ -508,7 +508,7 @@ func TestIntegrationStore_GetResourcePermissions(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
seedResourcePermissions(t, store, sql, orgService, tt.query.Actions, tt.query.Resource, tt.query.ResourceID, tt.query.ResourceAttribute, tt.numUsers, tt.numServiceAccounts)
|
seedResourcePermissions(t, store, sql, cfg, orgService, tt.query.Actions, tt.query.Resource, tt.query.ResourceID, tt.query.ResourceAttribute, tt.numUsers, tt.numServiceAccounts)
|
||||||
|
|
||||||
tt.query.User = tt.user
|
tt.query.User = tt.user
|
||||||
permissions, err := store.GetResourcePermissions(context.Background(), tt.user.OrgID, tt.query)
|
permissions, err := store.GetResourcePermissions(context.Background(), tt.user.OrgID, tt.query)
|
||||||
@@ -519,7 +519,7 @@ func TestIntegrationStore_GetResourcePermissions(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func seedResourcePermissions(
|
func seedResourcePermissions(
|
||||||
t *testing.T, store *store, sql *sqlstore.SQLStore, orgService org.Service,
|
t *testing.T, store *store, sql db.DB, cfg *setting.Cfg, orgService org.Service,
|
||||||
actions []string, resource, resourceID, resourceAttribute string, numUsers, numServiceAccounts int,
|
actions []string, resource, resourceID, resourceAttribute string, numUsers, numServiceAccounts int,
|
||||||
) {
|
) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -527,7 +527,7 @@ func seedResourcePermissions(
|
|||||||
orgID, err := orgService.GetOrCreate(context.Background(), "test")
|
orgID, err := orgService.GetOrCreate(context.Background(), "test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
usrSvc, err := userimpl.ProvideService(sql, orgService, sql.Cfg, nil, nil, quotatest.New(false, nil), supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sql, orgService, cfg, nil, nil, quotatest.New(false, nil), supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
create := func(login string, isServiceAccount bool) {
|
create := func(login string, isServiceAccount bool) {
|
||||||
@@ -557,9 +557,9 @@ func seedResourcePermissions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTestEnv(t testing.TB) (*store, *sqlstore.SQLStore) {
|
func setupTestEnv(t testing.TB) (*store, db.DB, *setting.Cfg) {
|
||||||
sql := db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
return NewStore(sql, featuremgmt.WithFeatures()), sql
|
return NewStore(sql, featuremgmt.WithFeatures()), sql, sql.Cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStore_IsInherited(t *testing.T) {
|
func TestStore_IsInherited(t *testing.T) {
|
||||||
@@ -681,7 +681,7 @@ func TestIntegrationStore_DeleteResourcePermissions(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
store, _ := setupTestEnv(t)
|
store, _, _ := setupTestEnv(t)
|
||||||
|
|
||||||
_, err := store.SetResourcePermissions(context.Background(), 1, []SetResourcePermissionsCommand{
|
_, err := store.SetResourcePermissions(context.Background(), 1, []SetResourcePermissionsCommand{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ func TestIntegrationAuthorize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql := db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
|
cfg := sql.Cfg
|
||||||
|
|
||||||
dash1 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
dash1 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||||
@@ -37,7 +38,7 @@ func TestIntegrationAuthorize(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
dash2 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
dash2 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
@@ -51,7 +50,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
|||||||
|
|
||||||
repo := ProvideService(sql, cfg, features, tagService)
|
repo := ProvideService(sql, cfg, features, tagService)
|
||||||
|
|
||||||
dashboard1 := testutil.CreateDashboard(t, sql, features, dashboards.SaveDashboardCommand{
|
dashboard1 := testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
IsFolder: false,
|
IsFolder: false,
|
||||||
@@ -60,7 +59,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
_ = testutil.CreateDashboard(t, sql, features, dashboards.SaveDashboardCommand{
|
_ = testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
IsFolder: false,
|
IsFolder: false,
|
||||||
@@ -209,7 +208,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
|||||||
allDashboards := make([]dashInfo, 0, folder.MaxNestedFolderDepth+1)
|
allDashboards := make([]dashInfo, 0, folder.MaxNestedFolderDepth+1)
|
||||||
annotationsTexts := make([]string, 0, folder.MaxNestedFolderDepth+1)
|
annotationsTexts := make([]string, 0, folder.MaxNestedFolderDepth+1)
|
||||||
|
|
||||||
setupFolderStructure := func() *sqlstore.SQLStore {
|
setupFolderStructure := func() db.DB {
|
||||||
sql := db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
|
|
||||||
// enable nested folders so that the folder table is populated for all the tests
|
// enable nested folders so that the folder table is populated for all the tests
|
||||||
@@ -253,7 +252,7 @@ func TestIntegrationAnnotationListingWithInheritedRBAC(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboard := testutil.CreateDashboard(t, sql, features, dashboards.SaveDashboardCommand{
|
dashboard := testutil.CreateDashboard(t, sql, cfg, features, dashboards.SaveDashboardCommand{
|
||||||
UserID: usr.UserID,
|
UserID: usr.UserID,
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
IsFolder: false,
|
IsFolder: false,
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql := db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
|
cfg := sql.Cfg
|
||||||
|
|
||||||
dashboard1 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
dashboard1 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||||
@@ -52,7 +53,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
dashboard2 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
dashboard2 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
dashboard := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
dashboard := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||||
@@ -67,7 +67,7 @@ func TestIntegrationAnnotations(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
dashboard2 := testutil.CreateDashboard(t, sql, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
dashboard2 := testutil.CreateDashboard(t, sql, cfg, featuremgmt.WithFeatures(), dashboards.SaveDashboardCommand{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
dashboardstore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
dashboardstore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
@@ -13,10 +14,11 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupRBACRole(t *testing.T, db *sqlstore.SQLStore, user *user.SignedInUser) *accesscontrol.Role {
|
func SetupRBACRole(t *testing.T, db db.DB, user *user.SignedInUser) *accesscontrol.Role {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
var role *accesscontrol.Role
|
var role *accesscontrol.Role
|
||||||
@@ -49,7 +51,7 @@ func SetupRBACRole(t *testing.T, db *sqlstore.SQLStore, user *user.SignedInUser)
|
|||||||
return role
|
return role
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupRBACPermission(t *testing.T, db *sqlstore.SQLStore, role *accesscontrol.Role, user *user.SignedInUser) {
|
func SetupRBACPermission(t *testing.T, db db.DB, role *accesscontrol.Role, user *user.SignedInUser) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
err := db.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
err := db.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||||
@@ -76,14 +78,14 @@ func SetupRBACPermission(t *testing.T, db *sqlstore.SQLStore, role *accesscontro
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDashboard(t *testing.T, sql *sqlstore.SQLStore, features featuremgmt.FeatureToggles, cmd dashboards.SaveDashboardCommand) *dashboards.Dashboard {
|
func CreateDashboard(t *testing.T, db db.DB, cfg *setting.Cfg, features featuremgmt.FeatureToggles, cmd dashboards.SaveDashboardCommand) *dashboards.Dashboard {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
dashboardStore, err := dashboardstore.ProvideDashboardStore(
|
dashboardStore, err := dashboardstore.ProvideDashboardStore(
|
||||||
sql,
|
db,
|
||||||
sql.Cfg,
|
cfg,
|
||||||
features,
|
features,
|
||||||
tagimpl.ProvideService(sql),
|
tagimpl.ProvideService(db),
|
||||||
quotatest.New(false, nil),
|
quotatest.New(false, nil),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -2,22 +2,23 @@ package correlationstest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/correlations"
|
"github.com/grafana/grafana/pkg/services/correlations"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(sqlStore *sqlstore.SQLStore) *correlations.CorrelationsService {
|
func New(db db.DB, cfg *setting.Cfg, bus bus.Bus) *correlations.CorrelationsService {
|
||||||
ds := &fakeDatasources.FakeDataSourceService{
|
ds := &fakeDatasources.FakeDataSourceService{
|
||||||
DataSources: []*datasources.DataSource{
|
DataSources: []*datasources.DataSource{
|
||||||
{ID: 1, UID: "graphite", Type: datasources.DS_GRAPHITE},
|
{ID: 1, UID: "graphite", Type: datasources.DS_GRAPHITE},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
correlationsSvc, _ := correlations.ProvideService(sqlStore, routing.NewRouteRegister(), ds, acimpl.ProvideAccessControl(setting.NewCfg()), sqlStore.Bus(), quotatest.New(false, nil), sqlStore.Cfg)
|
correlationsSvc, _ := correlations.ProvideService(db, routing.NewRouteRegister(), ds, acimpl.ProvideAccessControl(setting.NewCfg()), bus, quotatest.New(false, nil), cfg)
|
||||||
return correlationsSvc
|
return correlationsSvc
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testFeatureToggles = featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch)
|
var testFeatureToggles = featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch)
|
||||||
@@ -40,16 +40,18 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
t.Run("Testing DB", func(t *testing.T) {
|
t.Run("Testing DB", func(t *testing.T) {
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
|
var cfg *setting.Cfg
|
||||||
var flder, dashInRoot, childDash *dashboards.Dashboard
|
var flder, dashInRoot, childDash *dashboards.Dashboard
|
||||||
var currentUser *user.SignedInUser
|
var currentUser *user.SignedInUser
|
||||||
var dashboardStore dashboards.Store
|
var dashboardStore dashboards.Store
|
||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
|
sqlStore, cfg = sql, sql.Cfg
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
var err error
|
var err error
|
||||||
dashboardStore, err = ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
flder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, "", true, "prod", "webapp")
|
flder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, "", true, "prod", "webapp")
|
||||||
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, "", false, "prod", "webapp")
|
dashInRoot = insertTestDashboard(t, dashboardStore, "test dash 67", 1, 0, "", false, "prod", "webapp")
|
||||||
@@ -138,16 +140,18 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Given two dashboard folders with one dashboard each and one dashboard in the root folder", func(t *testing.T) {
|
t.Run("Given two dashboard folders with one dashboard each and one dashboard in the root folder", func(t *testing.T) {
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
|
var cfg *setting.Cfg
|
||||||
var folder1, folder2, dashInRoot, childDash1, childDash2 *dashboards.Dashboard
|
var folder1, folder2, dashInRoot, childDash1, childDash2 *dashboards.Dashboard
|
||||||
var rootFolderId int64 = 0
|
var rootFolderId int64 = 0
|
||||||
var currentUser *user.SignedInUser
|
var currentUser *user.SignedInUser
|
||||||
|
|
||||||
setup2 := func() {
|
setup2 := func() {
|
||||||
sqlStore = db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
|
sqlStore, cfg = sql, sql.Cfg
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
var err error
|
var err error
|
||||||
dashboardStore, err = ProvideDashboardStore(sqlStore, sqlStore.Cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err = ProvideDashboardStore(sqlStore, cfg, testFeatureToggles, tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, "", true, "prod")
|
folder1 = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, "", true, "prod")
|
||||||
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, "", true, "prod")
|
folder2 = insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, "", true, "prod")
|
||||||
@@ -239,7 +243,8 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
|||||||
// the maximux nested folder hierarchy starting from parent down to subfolders
|
// the maximux nested folder hierarchy starting from parent down to subfolders
|
||||||
nestedFolders := make([]*folder.Folder, 0, folder.MaxNestedFolderDepth+1)
|
nestedFolders := make([]*folder.Folder, 0, folder.MaxNestedFolderDepth+1)
|
||||||
|
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
|
var cfg *setting.Cfg
|
||||||
const (
|
const (
|
||||||
dashInRootTitle = "dashboard in root"
|
dashInRootTitle = "dashboard in root"
|
||||||
dashInParentTitle = "dashboard in parent"
|
dashInParentTitle = "dashboard in parent"
|
||||||
@@ -248,26 +253,27 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
|||||||
var viewer *user.SignedInUser
|
var viewer *user.SignedInUser
|
||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
sqlStore = db.InitTestDB(t)
|
sql := db.InitTestDB(t)
|
||||||
|
sqlStore, cfg = sql, sql.Cfg
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
|
|
||||||
// enable nested folders so that the folder table is populated for all the tests
|
// enable nested folders so that the folder table is populated for all the tests
|
||||||
features := featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders)
|
features := featuremgmt.WithFeatures(featuremgmt.FlagNestedFolders)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
dashboardWriteStore, err := ProvideDashboardStore(sqlStore, sqlStore.Cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardWriteStore, err := ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
usr := createUser(t, sqlStore, "viewer", "Viewer", false)
|
usr := createUser(t, sqlStore, cfg, "viewer", "Viewer", false)
|
||||||
viewer = &user.SignedInUser{
|
viewer = &user.SignedInUser{
|
||||||
UserID: usr.ID,
|
UserID: usr.ID,
|
||||||
OrgID: usr.OrgID,
|
OrgID: usr.OrgID,
|
||||||
OrgRole: org.RoleViewer,
|
OrgRole: org.RoleViewer,
|
||||||
}
|
}
|
||||||
|
|
||||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// create admin user in the same org
|
// create admin user in the same org
|
||||||
@@ -295,7 +301,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
|||||||
guardian.New = origNewGuardian
|
guardian.New = origNewGuardian
|
||||||
})
|
})
|
||||||
|
|
||||||
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), sqlStore.Cfg, dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(sqlStore), sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
folderSvc := folderimpl.ProvideService(mock.New(), bus.ProvideBus(tracing.InitializeTracerForTest()), cfg, dashboardWriteStore, folderimpl.ProvideDashboardFolderStore(sqlStore), sqlStore, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||||
|
|
||||||
parentUID := ""
|
parentUID := ""
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
@@ -397,7 +403,7 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
dashboardReadStore, err := ProvideDashboardStore(sqlStore, sqlStore.Cfg, tc.features, tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
dashboardReadStore, err := ProvideDashboardStore(sqlStore, cfg, tc.features, tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
viewer.Permissions = map[int64]map[string][]string{viewer.OrgID: tc.permissions}
|
viewer.Permissions = map[int64]map[string][]string{viewer.OrgID: tc.permissions}
|
||||||
@@ -436,16 +442,16 @@ func moveDashboard(t *testing.T, dashboardStore dashboards.Store, orgId int64, d
|
|||||||
return dash
|
return dash
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(t *testing.T, sqlStore *sqlstore.SQLStore, name string, role string, isAdmin bool) user.User {
|
func createUser(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, name string, role string, isAdmin bool) user.User {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
sqlStore.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
sqlStore.Cfg.AutoAssignOrgId = 1
|
cfg.AutoAssignOrgId = 1
|
||||||
sqlStore.Cfg.AutoAssignOrgRole = role
|
cfg.AutoAssignOrgRole = role
|
||||||
|
|
||||||
qs := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
qs := quotaimpl.ProvideService(sqlStore, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, qs)
|
orgService, err := orgimpl.ProvideService(sqlStore, cfg, qs)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
o, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: fmt.Sprintf("test org %d", time.Now().UnixNano())})
|
o, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: fmt.Sprintf("test org %d", time.Now().UnixNano())})
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
|||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var cfg *setting.Cfg
|
var cfg *setting.Cfg
|
||||||
var savedFolder, savedDash, savedDash2 *dashboards.Dashboard
|
var savedFolder, savedDash, savedDash2 *dashboards.Dashboard
|
||||||
var dashboardStore dashboards.Store
|
var dashboardStore dashboards.Store
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/dashboards/database"
|
"github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
@@ -24,7 +23,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIntegrationDashboardFolderStore(t *testing.T) {
|
func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var cfg *setting.Cfg
|
var cfg *setting.Cfg
|
||||||
var dashboardStore dashboards.Store
|
var dashboardStore dashboards.Store
|
||||||
|
|
||||||
@@ -39,7 +38,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
|||||||
setup()
|
setup()
|
||||||
var orgId int64 = 1
|
var orgId int64 = 1
|
||||||
title := "Very Unique Name"
|
title := "Very Unique Name"
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var folder1, folder2 *dashboards.Dashboard
|
var folder1, folder2 *dashboards.Dashboard
|
||||||
sqlStore = db.InitTestDB(t)
|
sqlStore = db.InitTestDB(t)
|
||||||
folderStore := ProvideDashboardFolderStore(sqlStore)
|
folderStore := ProvideDashboardFolderStore(sqlStore)
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/folder"
|
"github.com/grafana/grafana/pkg/services/folder"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ func TestIntegrationCreate(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
t.Run("creating a folder without providing a UID should fail", func(t *testing.T) {
|
t.Run("creating a folder without providing a UID should fail", func(t *testing.T) {
|
||||||
_, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
_, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
||||||
@@ -152,7 +154,7 @@ func TestIntegrationDelete(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
t.Run("attempt to delete unknown folder should fail", func(t *testing.T) {
|
t.Run("attempt to delete unknown folder should fail", func(t *testing.T) {
|
||||||
@@ -199,7 +201,7 @@ func TestIntegrationUpdate(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
// create parent folder
|
// create parent folder
|
||||||
parent, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
parent, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
||||||
@@ -374,7 +376,7 @@ func TestIntegrationGet(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
// create folder
|
// create folder
|
||||||
uid1 := util.GenerateShortUID()
|
uid1 := util.GenerateShortUID()
|
||||||
@@ -491,7 +493,7 @@ func TestIntegrationGetParents(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
// create folder
|
// create folder
|
||||||
uid1 := util.GenerateShortUID()
|
uid1 := util.GenerateShortUID()
|
||||||
@@ -559,7 +561,7 @@ func TestIntegrationGetChildren(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
// create folder
|
// create folder
|
||||||
uid1 := util.GenerateShortUID()
|
uid1 := util.GenerateShortUID()
|
||||||
@@ -739,7 +741,7 @@ func TestIntegrationGetHeight(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
// create folder
|
// create folder
|
||||||
uid1 := util.GenerateShortUID()
|
uid1 := util.GenerateShortUID()
|
||||||
@@ -772,7 +774,7 @@ func TestIntegrationGetFolders(t *testing.T) {
|
|||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
folderStore := ProvideStore(db, db.Cfg)
|
folderStore := ProvideStore(db, db.Cfg)
|
||||||
|
|
||||||
orgID := CreateOrg(t, db)
|
orgID := CreateOrg(t, db, db.Cfg)
|
||||||
|
|
||||||
// create folders
|
// create folders
|
||||||
uids := make([]string, 0)
|
uids := make([]string, 0)
|
||||||
@@ -886,10 +888,10 @@ func TestIntegrationGetFolders(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOrg(t *testing.T, db *sqlstore.SQLStore) int64 {
|
func CreateOrg(t *testing.T, db db.DB, cfg *setting.Cfg) int64 {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
orgService, err := orgimpl.ProvideService(db, db.Cfg, quotatest.New(false, nil))
|
orgService, err := orgimpl.ProvideService(db, cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
orgID, err := orgService.GetOrCreate(context.Background(), "test-org")
|
orgID, err := orgService.GetOrCreate(context.Background(), "test-org")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/testutil"
|
"github.com/grafana/grafana/pkg/services/ngalert/testutil"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -867,7 +866,7 @@ func createFolder(t *testing.T, store *DBstore, uid, title string, orgID int64,
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupFolderService(t *testing.T, sqlStore *sqlstore.SQLStore, cfg *setting.Cfg, features featuremgmt.FeatureToggles) folder.Service {
|
func setupFolderService(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, features featuremgmt.FeatureToggles) folder.Service {
|
||||||
tracer := tracing.InitializeTracerForTest()
|
tracer := tracing.InitializeTracerForTest()
|
||||||
inProcBus := bus.ProvideBus(tracer)
|
inProcBus := bus.ProvideBus(tracer)
|
||||||
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
|
folderStore := folderimpl.ProvideDashboardFolderStore(sqlStore)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
||||||
"github.com/grafana/grafana/pkg/services/guardian"
|
"github.com/grafana/grafana/pkg/services/guardian"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -30,7 +29,7 @@ func SetupFolderService(tb testing.TB, cfg *setting.Cfg, db db.DB, dashboardStor
|
|||||||
return folderimpl.ProvideService(ac, bus, cfg, dashboardStore, folderStore, db, features, supportbundlestest.NewFakeBundleService(), nil)
|
return folderimpl.ProvideService(ac, bus, cfg, dashboardStore, folderStore, db, features, supportbundlestest.NewFakeBundleService(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupDashboardService(tb testing.TB, sqlStore *sqlstore.SQLStore, fs *folderimpl.DashboardFolderStoreImpl, cfg *setting.Cfg) (*dashboardservice.DashboardServiceImpl, dashboards.Store) {
|
func SetupDashboardService(tb testing.TB, sqlStore db.DB, fs *folderimpl.DashboardFolderStoreImpl, cfg *setting.Cfg) (*dashboardservice.DashboardServiceImpl, dashboards.Store) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
origNewGuardian := guardian.New
|
origNewGuardian := guardian.New
|
||||||
@@ -51,7 +50,7 @@ func SetupDashboardService(tb testing.TB, sqlStore *sqlstore.SQLStore, fs *folde
|
|||||||
features := featuremgmt.WithFeatures()
|
features := featuremgmt.WithFeatures()
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
|
|
||||||
dashboardStore, err := database.ProvideDashboardStore(sqlStore, sqlStore.Cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := database.ProvideDashboardStore(sqlStore, cfg, features, tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
|
|
||||||
dashboardService, err := dashboardservice.ProvideDashboardServiceImpl(
|
dashboardService, err := dashboardservice.ProvideDashboardServiceImpl(
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
|||||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
seedOrgUsers(t, &orgUserStore, store, 10, userSvc, o.ID)
|
seedOrgUsers(t, &orgUserStore, 10, userSvc, o.ID)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
@@ -682,7 +682,7 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func seedOrgUsers(t *testing.T, orgUserStore store, store *sqlstore.SQLStore, numUsers int, usrSvc user.Service, orgID int64) {
|
func seedOrgUsers(t *testing.T, orgUserStore store, numUsers int, usrSvc user.Service, orgID int64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
// Seed users
|
// Seed users
|
||||||
@@ -798,7 +798,7 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
|||||||
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
seedOrgUsers(t, &orgUserStore, store, 10, userSvc, o.ID)
|
seedOrgUsers(t, &orgUserStore, 10, userSvc, o.ID)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
||||||
"github.com/grafana/grafana/pkg/services/searchV2"
|
"github.com/grafana/grafana/pkg/services/searchV2"
|
||||||
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
||||||
@@ -88,7 +89,7 @@ func TestIntegrationPluginManager(t *testing.T) {
|
|||||||
pg := postgres.ProvideService(cfg)
|
pg := postgres.ProvideService(cfg)
|
||||||
my := mysql.ProvideService()
|
my := mysql.ProvideService()
|
||||||
ms := mssql.ProvideService(cfg)
|
ms := mssql.ProvideService(cfg)
|
||||||
sv2 := searchV2.ProvideService(cfg, db.InitTestDB(t), nil, nil, tracer, features, nil, nil, nil)
|
sv2 := searchV2.ProvideService(cfg, db.InitTestDB(t, sqlstore.InitTestDBOpt{Cfg: cfg}), nil, nil, tracer, features, nil, nil, nil)
|
||||||
graf := grafanads.ProvideService(sv2, nil)
|
graf := grafanads.ProvideService(sv2, nil)
|
||||||
pyroscope := pyroscope.ProvideService(hcp)
|
pyroscope := pyroscope.ProvideService(hcp)
|
||||||
parca := parca.ProvideService(hcp)
|
parca := parca.ProvideService(hcp)
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import (
|
|||||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/service"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -48,7 +47,7 @@ func TestIntegrationListPublicDashboard(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var cfg *setting.Cfg
|
var cfg *setting.Cfg
|
||||||
|
|
||||||
var aDash *dashboards.Dashboard
|
var aDash *dashboards.Dashboard
|
||||||
@@ -68,7 +67,7 @@ func TestIntegrationListPublicDashboard(t *testing.T) {
|
|||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicdashboardStore = ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
bDash = insertTestDashboard(t, dashboardStore, "b", orgId, "", false)
|
bDash = insertTestDashboard(t, dashboardStore, "b", orgId, "", false)
|
||||||
aDash = insertTestDashboard(t, dashboardStore, "a", orgId, "", false)
|
aDash = insertTestDashboard(t, dashboardStore, "a", orgId, "", false)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations"
|
"github.com/grafana/grafana/pkg/services/annotations"
|
||||||
"github.com/grafana/grafana/pkg/services/annotations/annotationsimpl"
|
"github.com/grafana/grafana/pkg/services/annotations/annotationsimpl"
|
||||||
@@ -15,6 +16,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
"github.com/grafana/grafana/pkg/services/publicdashboards/service/intervalv2"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newPublicDashboardServiceImpl(
|
func newPublicDashboardServiceImpl(
|
||||||
@@ -22,17 +24,17 @@ func newPublicDashboardServiceImpl(
|
|||||||
publicDashboardStore publicdashboards.Store,
|
publicDashboardStore publicdashboards.Store,
|
||||||
dashboardService dashboards.DashboardService,
|
dashboardService dashboards.DashboardService,
|
||||||
annotationsRepo annotations.Repository,
|
annotationsRepo annotations.Repository,
|
||||||
) (*PublicDashboardServiceImpl, *sqlstore.SQLStore) {
|
) (*PublicDashboardServiceImpl, db.DB, *setting.Cfg) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
sqlStore := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
tagService := tagimpl.ProvideService(sqlStore)
|
tagService := tagimpl.ProvideService(db)
|
||||||
if annotationsRepo == nil {
|
if annotationsRepo == nil {
|
||||||
annotationsRepo = annotationsimpl.ProvideService(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagService)
|
annotationsRepo = annotationsimpl.ProvideService(db, db.Cfg, featuremgmt.WithFeatures(), tagService)
|
||||||
}
|
}
|
||||||
|
|
||||||
if publicDashboardStore == nil {
|
if publicDashboardStore == nil {
|
||||||
publicDashboardStore = database.ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
publicDashboardStore = database.ProvideStore(db, db.Cfg, featuremgmt.WithFeatures())
|
||||||
}
|
}
|
||||||
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
serviceWrapper := ProvideServiceWrapper(publicDashboardStore)
|
||||||
|
|
||||||
@@ -48,5 +50,5 @@ func newPublicDashboardServiceImpl(
|
|||||||
serviceWrapper: serviceWrapper,
|
serviceWrapper: serviceWrapper,
|
||||||
license: license,
|
license: license,
|
||||||
features: featuremgmt.WithFeatures(),
|
features: featuremgmt.WithFeatures(),
|
||||||
}, sqlStore
|
}, db, db.Cfg
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -677,12 +677,12 @@ const (
|
|||||||
|
|
||||||
func TestGetQueryDataResponse(t *testing.T) {
|
func TestGetQueryDataResponse(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, _ := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
fakeQueryService := &query.FakeQueryService{}
|
fakeQueryService := &query.FakeQueryService{}
|
||||||
fakeQueryService.On("QueryData", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&backend.QueryDataResponse{}, nil)
|
fakeQueryService.On("QueryData", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&backend.QueryDataResponse{}, nil)
|
||||||
service.QueryDataService = fakeQueryService
|
service.QueryDataService = fakeQueryService
|
||||||
|
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, service.cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
publicDashboardQueryDTO := PublicDashboardQueryDTO{
|
||||||
@@ -739,7 +739,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
Return(&PublicDashboard{Uid: "uid1", IsEnabled: true}, nil)
|
Return(&PublicDashboard{Uid: "uid1", IsEnabled: true}, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboards.NewDashboard("dash1"), nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboards.NewDashboard("dash1"), nil)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
reqDTO := AnnotationsQueryDTO{
|
reqDTO := AnnotationsQueryDTO{
|
||||||
From: 1,
|
From: 1,
|
||||||
@@ -792,7 +792,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
|
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||||
{
|
{
|
||||||
@@ -849,7 +849,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
|
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||||
{
|
{
|
||||||
@@ -918,7 +918,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
|
|
||||||
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
annotationsRepo.On("Find", mock.Anything, mock.Anything).Return([]*annotations.ItemDTO{
|
||||||
{
|
{
|
||||||
@@ -958,7 +958,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@@ -988,7 +988,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.AnythingOfType("string")).Return(pubdash, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@@ -1020,7 +1020,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dash, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dash, nil)
|
||||||
|
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@@ -1061,7 +1061,7 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}, nil).Maybe()
|
}, nil).Maybe()
|
||||||
|
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, annotationsRepo)
|
||||||
|
|
||||||
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
items, err := service.FindAnnotations(context.Background(), AnnotationsQueryDTO{}, "abc123")
|
||||||
|
|
||||||
@@ -1084,8 +1084,8 @@ func TestFindAnnotations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMetricRequest(t *testing.T) {
|
func TestGetMetricRequest(t *testing.T) {
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, nil, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, nil, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
|
|
||||||
@@ -1165,9 +1165,9 @@ func TestGetUniqueDashboardDatasourceUids(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildMetricRequest(t *testing.T) {
|
func TestBuildMetricRequest(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
publicDashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
nonPublicDashboard := insertTestDashboard(t, dashboardStore, "testNonPublicDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
nonPublicDashboard := insertTestDashboard(t, dashboardStore, "testNonPublicDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ func TestGetPublicDashboardForView(t *testing.T) {
|
|||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
dashboardFullWithMeta, err := service.GetPublicDashboardForView(context.Background(), test.AccessToken)
|
dashboardFullWithMeta, err := service.GetPublicDashboardForView(context.Background(), test.AccessToken)
|
||||||
if test.ErrResp != nil {
|
if test.ErrResp != nil {
|
||||||
@@ -496,7 +496,7 @@ func TestGetPublicDashboard(t *testing.T) {
|
|||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||||
fakeStore := &FakePublicDashboardStore{}
|
fakeStore := &FakePublicDashboardStore{}
|
||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
pdc, dash, err := service.FindPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
pdc, dash, err := service.FindPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
||||||
if test.ErrResp != nil {
|
if test.ErrResp != nil {
|
||||||
@@ -559,7 +559,7 @@ func TestGetEnabledPublicDashboard(t *testing.T) {
|
|||||||
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
fakeStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(test.StoreResp.pd, test.StoreResp.err)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(test.StoreResp.d, test.StoreResp.err)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, fakeStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
pdc, dash, err := service.FindEnabledPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
pdc, dash, err := service.FindEnabledPublicDashboardAndDashboardByAccessToken(context.Background(), test.AccessToken)
|
||||||
if test.ErrResp != nil {
|
if test.ErrResp != nil {
|
||||||
@@ -583,10 +583,10 @@ func TestGetEnabledPublicDashboard(t *testing.T) {
|
|||||||
func TestCreatePublicDashboard(t *testing.T) {
|
func TestCreatePublicDashboard(t *testing.T) {
|
||||||
t.Run("Create public dashboard", func(t *testing.T) {
|
t.Run("Create public dashboard", func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -664,9 +664,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
t.Run(fmt.Sprintf("Create public dashboard with %s null boolean fields stores them as false", tt.Name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("Create public dashboard with %s null boolean fields stores them as false", tt.Name), func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -696,9 +696,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
t.Run("Validate pubdash has default time setting value", func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -723,9 +723,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Creates pubdash whose dashboard has template variables successfully", func(t *testing.T) {
|
t.Run("Creates pubdash whose dashboard has template variables successfully", func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
templateVars := make([]map[string]any, 1)
|
templateVars := make([]map[string]any, 1)
|
||||||
@@ -769,7 +769,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
|
|
||||||
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@@ -789,9 +789,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Create public dashboard with given pubdash uid", func(t *testing.T) {
|
t.Run("Create public dashboard with given pubdash uid", func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -835,7 +835,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
publicDashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(nil, ErrPublicDashboardNotFound.Errorf(""))
|
publicDashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(nil, ErrPublicDashboardNotFound.Errorf(""))
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
isEnabled := true
|
isEnabled := true
|
||||||
dto := &SavePublicDashboardDTO{
|
dto := &SavePublicDashboardDTO{
|
||||||
@@ -855,9 +855,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Create public dashboard with given pubdash access token", func(t *testing.T) {
|
t.Run("Create public dashboard with given pubdash access token", func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]interface{}{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -895,7 +895,7 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
publicDashboardStore := &FakePublicDashboardStore{}
|
publicDashboardStore := &FakePublicDashboardStore{}
|
||||||
publicDashboardStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(pubdash, nil)
|
publicDashboardStore.On("FindByAccessToken", mock.Anything, mock.Anything).Return(pubdash, nil)
|
||||||
service, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, nil, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, publicDashboardStore, nil, nil)
|
||||||
|
|
||||||
_, err := service.NewPublicDashboardAccessToken(context.Background())
|
_, err := service.NewPublicDashboardAccessToken(context.Background())
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
@@ -907,9 +907,9 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
publicdashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(&PublicDashboard{Uid: "newPubdashUid"}, nil)
|
publicdashboardStore.On("FindByDashboardUid", mock.Anything, mock.Anything, mock.Anything).Return(&PublicDashboard{Uid: "newPubdashUid"}, nil)
|
||||||
publicdashboardStore.On("Find", mock.Anything, mock.Anything).Return(nil, nil)
|
publicdashboardStore.On("Find", mock.Anything, mock.Anything).Return(nil, nil)
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, publicdashboardStore, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, publicdashboardStore, fakeDashboardService, nil)
|
||||||
|
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -932,10 +932,10 @@ func TestCreatePublicDashboard(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Validate pubdash has default share value", func(t *testing.T) {
|
t.Run("Validate pubdash has default share value", func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -970,10 +970,10 @@ func assertFalseIfNull(t *testing.T, expectedValue bool, nullableValue *bool) {
|
|||||||
|
|
||||||
func TestUpdatePublicDashboard(t *testing.T) {
|
func TestUpdatePublicDashboard(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
dashboard2 := insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard2 := insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
@@ -1153,10 +1153,10 @@ func TestUpdatePublicDashboard(t *testing.T) {
|
|||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
t.Run(fmt.Sprintf("Update public dashboard with %s null boolean fields let those fields with old persisted value", tt.Name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("Update public dashboard with %s null boolean fields let those fields with old persisted value", tt.Name), func(t *testing.T) {
|
||||||
fakeDashboardService := &dashboards.FakeDashboardService{}
|
fakeDashboardService := &dashboards.FakeDashboardService{}
|
||||||
service, sqlStore := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
service, sqlStore, cfg := newPublicDashboardServiceImpl(t, nil, fakeDashboardService, nil)
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
dashboard := insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true, []map[string]any{}, nil)
|
||||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
fakeDashboardService.On("GetDashboard", mock.Anything, mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||||
@@ -1273,7 +1273,7 @@ func TestDeletePublicDashboard(t *testing.T) {
|
|||||||
if tt.ExpectedErrResp == nil || tt.mockDeleteStore.StoreRespErr != nil {
|
if tt.ExpectedErrResp == nil || tt.mockDeleteStore.StoreRespErr != nil {
|
||||||
store.On("Delete", mock.Anything, mock.Anything).Return(tt.mockDeleteStore.AffectedRowsResp, tt.mockDeleteStore.StoreRespErr)
|
store.On("Delete", mock.Anything, mock.Anything).Return(tt.mockDeleteStore.AffectedRowsResp, tt.mockDeleteStore.StoreRespErr)
|
||||||
}
|
}
|
||||||
service, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
service, _, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||||
|
|
||||||
err := service.Delete(context.Background(), "pubdashUID", "uid")
|
err := service.Delete(context.Background(), "pubdashUID", "uid")
|
||||||
if tt.ExpectedErrResp != nil {
|
if tt.ExpectedErrResp != nil {
|
||||||
@@ -1490,7 +1490,7 @@ func TestPublicDashboardServiceImpl_ListPublicDashboards(t *testing.T) {
|
|||||||
store := NewFakePublicDashboardStore(t)
|
store := NewFakePublicDashboardStore(t)
|
||||||
store.On("FindAllWithPagination", mock.Anything, mock.Anything).
|
store.On("FindAllWithPagination", mock.Anything, mock.Anything).
|
||||||
Return(tt.mockResponse.PublicDashboardListResponseWithPagination, tt.mockResponse.Err)
|
Return(tt.mockResponse.PublicDashboardListResponseWithPagination, tt.mockResponse.Err)
|
||||||
pd, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
pd, _, _ := newPublicDashboardServiceImpl(t, store, nil, nil)
|
||||||
pd.ac = ac
|
pd.ac = ac
|
||||||
|
|
||||||
got, err := pd.FindAllWithPagination(tt.args.ctx, tt.args.query)
|
got, err := pd.FindAllWithPagination(tt.args.ctx, tt.args.query)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/routing"
|
"github.com/grafana/grafana/pkg/api/routing"
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||||
@@ -96,7 +97,7 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
userService, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
userService, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
setupEnv(t, sqlStore, b, quotaService)
|
setupEnv(t, sqlStore, sqlStore.Cfg, b, quotaService)
|
||||||
|
|
||||||
u, err := userService.Create(context.Background(), &user.CreateUserCommand{
|
u, err := userService.Create(context.Background(), &user.CreateUserCommand{
|
||||||
Name: "TestUser",
|
Name: "TestUser",
|
||||||
@@ -468,29 +469,29 @@ func getQuotaBySrvTargetScope(t *testing.T, quotaService quota.Service, srv quot
|
|||||||
return quota.QuotaDTO{}, err
|
return quota.QuotaDTO{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupEnv(t *testing.T, sqlStore *sqlstore.SQLStore, b bus.Bus, quotaService quota.Service) {
|
func setupEnv(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, b bus.Bus, quotaService quota.Service) {
|
||||||
tracer := tracing.InitializeTracerForTest()
|
tracer := tracing.InitializeTracerForTest()
|
||||||
_, err := apikeyimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
_, err := apikeyimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = authimpl.ProvideUserAuthTokenService(sqlStore, nil, quotaService, sqlStore.Cfg)
|
_, err = authimpl.ProvideUserAuthTokenService(sqlStore, nil, quotaService, cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = dashboardStore.ProvideDashboardStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
_, err = dashboardStore.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore())
|
secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore())
|
||||||
secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger"))
|
secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger"))
|
||||||
_, err = dsservice.ProvideService(sqlStore, secretsService, secretsStore, sqlStore.Cfg, featuremgmt.WithFeatures(), acmock.New(), acmock.NewMockedPermissionsService(), quotaService, &pluginstore.FakePluginStore{})
|
_, err = dsservice.ProvideService(sqlStore, secretsService, secretsStore, cfg, featuremgmt.WithFeatures(), acmock.New(), acmock.NewMockedPermissionsService(), quotaService, &pluginstore.FakePluginStore{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
m := metrics.NewNGAlert(prometheus.NewRegistry())
|
m := metrics.NewNGAlert(prometheus.NewRegistry())
|
||||||
|
|
||||||
ac := acimpl.ProvideAccessControl(sqlStore.Cfg)
|
ac := acimpl.ProvideAccessControl(cfg)
|
||||||
ruleStore, err := ngstore.ProvideDBStore(sqlStore.Cfg, featuremgmt.WithFeatures(), sqlStore, &foldertest.FakeService{}, &dashboards.FakeDashboardService{}, ac)
|
ruleStore, err := ngstore.ProvideDBStore(cfg, featuremgmt.WithFeatures(), sqlStore, &foldertest.FakeService{}, &dashboards.FakeDashboardService{}, ac)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = ngalert.ProvideService(
|
_, err = ngalert.ProvideService(
|
||||||
sqlStore.Cfg, featuremgmt.WithFeatures(), nil, nil, routing.NewRouteRegister(), sqlStore, ngalertfakes.NewFakeKVStore(t), nil, nil, quotaService,
|
cfg, featuremgmt.WithFeatures(), nil, nil, routing.NewRouteRegister(), sqlStore, ngalertfakes.NewFakeKVStore(t), nil, nil, quotaService,
|
||||||
secretsService, nil, m, &foldertest.FakeService{}, &acmock.Mock{}, &dashboards.FakeDashboardService{}, nil, b, &acmock.Mock{},
|
secretsService, nil, m, &foldertest.FakeService{}, &acmock.Mock{}, &dashboards.FakeDashboardService{}, nil, b, &acmock.Mock{},
|
||||||
annotationstest.NewFakeAnnotationsRepo(), &pluginstore.FakePluginStore{}, tracer, ruleStore,
|
annotationstest.NewFakeAnnotationsRepo(), &pluginstore.FakePluginStore{}, tracer, ruleStore,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = storesrv.ProvideService(sqlStore, featuremgmt.WithFeatures(), sqlStore.Cfg, quotaService, storesrv.ProvideSystemUsersService())
|
_, err = storesrv.ProvideService(sqlStore, featuremgmt.WithFeatures(), cfg, quotaService, storesrv.ProvideSystemUsersService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/store"
|
"github.com/grafana/grafana/pkg/services/store"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -98,7 +97,7 @@ func runSearchService(searchService *StandardSearchService) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Populates database with dashboards and folders
|
// Populates database with dashboards and folders
|
||||||
func populateDB(folderCount, dashboardsPerFolder int, sqlStore *sqlstore.SQLStore) error {
|
func populateDB(folderCount, dashboardsPerFolder int, sqlStore db.DB) error {
|
||||||
// Insert folders
|
// Insert folders
|
||||||
offset := 1
|
offset := 1
|
||||||
if errInsert := actest.ConcurrentBatch(actest.Concurrency, folderCount, actest.BatchSize, func(start, end int) error {
|
if errInsert := actest.ConcurrentBatch(actest.Concurrency, folderCount, actest.BatchSize, func(start, end int) error {
|
||||||
|
|||||||
@@ -438,13 +438,13 @@ func TestIntegration_SecretsService(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
someData := []byte(`some-data`)
|
someData := []byte(`some-data`)
|
||||||
|
|
||||||
tcs := map[string]func(*testing.T, *sqlstore.SQLStore, *SecretsService){
|
tcs := map[string]func(*testing.T, db.DB, *SecretsService){
|
||||||
"regular": func(t *testing.T, _ *sqlstore.SQLStore, svc *SecretsService) {
|
"regular": func(t *testing.T, _ db.DB, svc *SecretsService) {
|
||||||
// We encrypt some data normally, no transactions implied.
|
// We encrypt some data normally, no transactions implied.
|
||||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
},
|
},
|
||||||
"within successful InTransaction": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
"within successful InTransaction": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||||
require.NoError(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
require.NoError(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
||||||
// We encrypt some data within a transaction that shares the db session.
|
// We encrypt some data within a transaction that shares the db session.
|
||||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||||
@@ -454,7 +454,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
"within unsuccessful InTransaction": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
"within unsuccessful InTransaction": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||||
require.NotNil(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
require.NotNil(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
||||||
// We encrypt some data within a transaction that shares the db session.
|
// We encrypt some data within a transaction that shares the db session.
|
||||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||||
@@ -464,7 +464,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
|||||||
return errors.New("error")
|
return errors.New("error")
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
"within unsuccessful InTransaction (plus forced db fetch)": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
"within unsuccessful InTransaction (plus forced db fetch)": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||||
require.NotNil(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
require.NotNil(t, store.InTransaction(ctx, func(ctx context.Context) error {
|
||||||
// We encrypt some data within a transaction that shares the db session.
|
// We encrypt some data within a transaction that shares the db session.
|
||||||
encrypted, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
encrypted, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||||
@@ -483,7 +483,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
|||||||
return errors.New("error")
|
return errors.New("error")
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
"within successful WithTransactionalDbSession": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
"within successful WithTransactionalDbSession": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||||
require.NoError(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
require.NoError(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
// We encrypt some data within a transaction that does not share the db session.
|
// We encrypt some data within a transaction that does not share the db session.
|
||||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||||
@@ -493,7 +493,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
"within unsuccessful WithTransactionalDbSession": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
"within unsuccessful WithTransactionalDbSession": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||||
require.NotNil(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
require.NotNil(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
// We encrypt some data within a transaction that does not share the db session.
|
// We encrypt some data within a transaction that does not share the db session.
|
||||||
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
_, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||||
@@ -503,7 +503,7 @@ func TestIntegration_SecretsService(t *testing.T) {
|
|||||||
return errors.New("error")
|
return errors.New("error")
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
"within unsuccessful WithTransactionalDbSession (plus forced db fetch)": func(t *testing.T, store *sqlstore.SQLStore, svc *SecretsService) {
|
"within unsuccessful WithTransactionalDbSession (plus forced db fetch)": func(t *testing.T, store db.DB, svc *SecretsService) {
|
||||||
require.NotNil(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
require.NotNil(t, store.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||||
// We encrypt some data within a transaction that does not share the db session.
|
// We encrypt some data within a transaction that does not share the db session.
|
||||||
encrypted, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
encrypted, err := svc.Encrypt(ctx, someData, secrets.WithoutScope())
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import (
|
|||||||
func TestIntegrationStore_UsageStats(t *testing.T) {
|
func TestIntegrationStore_UsageStats(t *testing.T) {
|
||||||
saToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
saToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
sa := tests.SetupUserServiceAccount(t, db, saToCreate)
|
sa := tests.SetupUserServiceAccount(t, db, store.cfg, saToCreate)
|
||||||
|
|
||||||
db.Cfg.SATokenExpirationDayLimit = 4
|
store.cfg.SATokenExpirationDayLimit = 4
|
||||||
|
|
||||||
keyName := t.Name()
|
keyName := t.Name()
|
||||||
key, err := satokengen.New(keyName)
|
key, err := satokengen.New(keyName)
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/tests"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts/tests"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
@@ -209,7 +208,7 @@ func TestStore_DeleteServiceAccount(t *testing.T) {
|
|||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.desc, func(t *testing.T) {
|
t.Run(c.desc, func(t *testing.T) {
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
user := tests.SetupUserServiceAccount(t, db, c.user)
|
user := tests.SetupUserServiceAccount(t, db, store.cfg, c.user)
|
||||||
err := store.DeleteServiceAccount(context.Background(), user.OrgID, user.ID)
|
err := store.DeleteServiceAccount(context.Background(), user.OrgID, user.ID)
|
||||||
if c.expectedErr != nil {
|
if c.expectedErr != nil {
|
||||||
require.ErrorIs(t, err, c.expectedErr)
|
require.ErrorIs(t, err, c.expectedErr)
|
||||||
@@ -220,18 +219,19 @@ func TestStore_DeleteServiceAccount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTestDatabase(t *testing.T) (*sqlstore.SQLStore, *ServiceAccountsStoreImpl) {
|
func setupTestDatabase(t *testing.T) (db.DB, *ServiceAccountsStoreImpl) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
db := db.InitTestDB(t)
|
db := db.InitTestDB(t)
|
||||||
|
cfg := db.Cfg
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
apiKeyService, err := apikeyimpl.ProvideService(db, db.Cfg, quotaService)
|
apiKeyService, err := apikeyimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
kvStore := kvstore.ProvideService(db)
|
kvStore := kvstore.ProvideService(db)
|
||||||
orgService, err := orgimpl.ProvideService(db, db.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
userSvc, err := userimpl.ProvideService(db, orgService, db.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
userSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return db, ProvideServiceAccountsStore(db.Cfg, db, apiKeyService, kvStore, userSvc, orgService)
|
return db, ProvideServiceAccountsStore(cfg, db, apiKeyService, kvStore, userSvc, orgService)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStore_RetrieveServiceAccount(t *testing.T) {
|
func TestStore_RetrieveServiceAccount(t *testing.T) {
|
||||||
@@ -255,7 +255,7 @@ func TestStore_RetrieveServiceAccount(t *testing.T) {
|
|||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.desc, func(t *testing.T) {
|
t.Run(c.desc, func(t *testing.T) {
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
user := tests.SetupUserServiceAccount(t, db, c.user)
|
user := tests.SetupUserServiceAccount(t, db, store.cfg, c.user)
|
||||||
dto, err := store.RetrieveServiceAccount(context.Background(), user.OrgID, user.ID)
|
dto, err := store.RetrieveServiceAccount(context.Background(), user.OrgID, user.ID)
|
||||||
if c.expectedErr != nil {
|
if c.expectedErr != nil {
|
||||||
require.ErrorIs(t, err, c.expectedErr)
|
require.ErrorIs(t, err, c.expectedErr)
|
||||||
@@ -289,7 +289,7 @@ func TestStore_MigrateApiKeys(t *testing.T) {
|
|||||||
store.cfg.AutoAssignOrgRole = "Viewer"
|
store.cfg.AutoAssignOrgRole = "Viewer"
|
||||||
_, err := store.orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "main"})
|
_, err := store.orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "main"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
key := tests.SetupApiKey(t, db, c.key)
|
key := tests.SetupApiKey(t, db, store.cfg, c.key)
|
||||||
err = store.MigrateApiKey(context.Background(), key.OrgID, key.ID)
|
err = store.MigrateApiKey(context.Background(), key.OrgID, key.ID)
|
||||||
if c.expectedErr != nil {
|
if c.expectedErr != nil {
|
||||||
require.ErrorIs(t, err, c.expectedErr)
|
require.ErrorIs(t, err, c.expectedErr)
|
||||||
@@ -402,7 +402,7 @@ func TestStore_MigrateAllApiKeys(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for _, key := range c.keys {
|
for _, key := range c.keys {
|
||||||
tests.SetupApiKey(t, db, key)
|
tests.SetupApiKey(t, db, store.cfg, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
results, err := store.MigrateApiKeysToServiceAccounts(context.Background(), c.orgId)
|
results, err := store.MigrateApiKeysToServiceAccounts(context.Background(), c.orgId)
|
||||||
@@ -458,7 +458,7 @@ func TestServiceAccountsStoreImpl_SearchOrgServiceAccounts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
orgID := tests.SetupUsersServiceAccounts(t, db, initUsers)
|
orgID := tests.SetupUsersServiceAccounts(t, db, store.cfg, initUsers)
|
||||||
|
|
||||||
userWithPerm := &user.SignedInUser{
|
userWithPerm := &user.SignedInUser{
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
@@ -582,7 +582,7 @@ func TestServiceAccountsStoreImpl_EnableServiceAccounts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
orgID := tests.SetupUsersServiceAccounts(t, db, initUsers)
|
orgID := tests.SetupUsersServiceAccounts(t, db, store.cfg, initUsers)
|
||||||
|
|
||||||
fetchStates := func() map[int64]bool {
|
fetchStates := func() map[int64]bool {
|
||||||
sa1, err := store.RetrieveServiceAccount(ctx, orgID, 1)
|
sa1, err := store.RetrieveServiceAccount(ctx, orgID, 1)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
func TestStore_AddServiceAccountToken(t *testing.T) {
|
func TestStore_AddServiceAccountToken(t *testing.T) {
|
||||||
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
user := tests.SetupUserServiceAccount(t, db, userToCreate)
|
user := tests.SetupUserServiceAccount(t, db, store.cfg, userToCreate)
|
||||||
|
|
||||||
type testCasesAdd struct {
|
type testCasesAdd struct {
|
||||||
secondsToLive int64
|
secondsToLive int64
|
||||||
@@ -76,7 +76,7 @@ func TestStore_AddServiceAccountToken(t *testing.T) {
|
|||||||
func TestStore_AddServiceAccountToken_WrongServiceAccount(t *testing.T) {
|
func TestStore_AddServiceAccountToken_WrongServiceAccount(t *testing.T) {
|
||||||
saToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
saToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
sa := tests.SetupUserServiceAccount(t, db, saToCreate)
|
sa := tests.SetupUserServiceAccount(t, db, store.cfg, saToCreate)
|
||||||
|
|
||||||
keyName := t.Name()
|
keyName := t.Name()
|
||||||
key, err := apikeygen.New(sa.OrgID, keyName)
|
key, err := apikeygen.New(sa.OrgID, keyName)
|
||||||
@@ -96,7 +96,7 @@ func TestStore_AddServiceAccountToken_WrongServiceAccount(t *testing.T) {
|
|||||||
func TestStore_RevokeServiceAccountToken(t *testing.T) {
|
func TestStore_RevokeServiceAccountToken(t *testing.T) {
|
||||||
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
sa := tests.SetupUserServiceAccount(t, db, userToCreate)
|
sa := tests.SetupUserServiceAccount(t, db, store.cfg, userToCreate)
|
||||||
|
|
||||||
keyName := t.Name()
|
keyName := t.Name()
|
||||||
key, err := apikeygen.New(sa.OrgID, keyName)
|
key, err := apikeygen.New(sa.OrgID, keyName)
|
||||||
@@ -136,7 +136,7 @@ func TestStore_RevokeServiceAccountToken(t *testing.T) {
|
|||||||
func TestStore_DeleteServiceAccountToken(t *testing.T) {
|
func TestStore_DeleteServiceAccountToken(t *testing.T) {
|
||||||
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
userToCreate := tests.TestUser{Login: "servicetestwithTeam@admin", IsServiceAccount: true}
|
||||||
db, store := setupTestDatabase(t)
|
db, store := setupTestDatabase(t)
|
||||||
sa := tests.SetupUserServiceAccount(t, db, userToCreate)
|
sa := tests.SetupUserServiceAccount(t, db, store.cfg, userToCreate)
|
||||||
|
|
||||||
keyName := t.Name()
|
keyName := t.Name()
|
||||||
key, err := apikeygen.New(sa.OrgID, keyName)
|
key, err := apikeygen.New(sa.OrgID, keyName)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/infra/kvstore"
|
"github.com/grafana/grafana/pkg/infra/kvstore"
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/infra/usagestats"
|
"github.com/grafana/grafana/pkg/infra/usagestats"
|
||||||
@@ -15,7 +16,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/secretscan"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts/secretscan"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
@@ -39,7 +39,7 @@ type ServiceAccountsService struct {
|
|||||||
func ProvideServiceAccountsService(
|
func ProvideServiceAccountsService(
|
||||||
cfg *setting.Cfg,
|
cfg *setting.Cfg,
|
||||||
usageStats usagestats.Service,
|
usageStats usagestats.Service,
|
||||||
store *sqlstore.SQLStore,
|
store db.DB,
|
||||||
apiKeyService apikey.Service,
|
apiKeyService apikey.Service,
|
||||||
kvStore kvstore.KVStore,
|
kvStore kvstore.KVStore,
|
||||||
userService user.Service,
|
userService user.Service,
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestUser struct {
|
type TestUser struct {
|
||||||
@@ -35,16 +35,16 @@ type TestApiKey struct {
|
|||||||
ServiceAccountID *int64
|
ServiceAccountID *int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupUserServiceAccount(t *testing.T, sqlStore *sqlstore.SQLStore, testUser TestUser) *user.User {
|
func SetupUserServiceAccount(t *testing.T, db db.DB, cfg *setting.Cfg, testUser TestUser) *user.User {
|
||||||
role := string(org.RoleViewer)
|
role := string(org.RoleViewer)
|
||||||
if testUser.Role != "" {
|
if testUser.Role != "" {
|
||||||
role = testUser.Role
|
role = testUser.Role
|
||||||
}
|
}
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
org, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{
|
org, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{
|
||||||
@@ -63,7 +63,7 @@ func SetupUserServiceAccount(t *testing.T, sqlStore *sqlstore.SQLStore, testUser
|
|||||||
return u1
|
return u1
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupApiKey(t *testing.T, sqlStore *sqlstore.SQLStore, testKey TestApiKey) *apikey.APIKey {
|
func SetupApiKey(t *testing.T, store db.DB, cfg *setting.Cfg, testKey TestApiKey) *apikey.APIKey {
|
||||||
role := org.RoleViewer
|
role := org.RoleViewer
|
||||||
if testKey.Role != "" {
|
if testKey.Role != "" {
|
||||||
role = testKey.Role
|
role = testKey.Role
|
||||||
@@ -83,13 +83,13 @@ func SetupApiKey(t *testing.T, sqlStore *sqlstore.SQLStore, testKey TestApiKey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
apiKeyService, err := apikeyimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
apiKeyService, err := apikeyimpl.ProvideService(store, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
key, err := apiKeyService.AddAPIKey(context.Background(), addKeyCmd)
|
key, err := apiKeyService.AddAPIKey(context.Background(), addKeyCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if testKey.IsExpired {
|
if testKey.IsExpired {
|
||||||
err := sqlStore.WithTransactionalDbSession(context.Background(), func(sess *db.Session) error {
|
err := store.WithTransactionalDbSession(context.Background(), func(sess *db.Session) error {
|
||||||
// Force setting expires to time before now to make key expired
|
// Force setting expires to time before now to make key expired
|
||||||
var expires int64 = 1
|
var expires int64 = 1
|
||||||
expiringKey := apikey.APIKey{Expires: &expires}
|
expiringKey := apikey.APIKey{Expires: &expires}
|
||||||
@@ -105,13 +105,13 @@ func SetupApiKey(t *testing.T, sqlStore *sqlstore.SQLStore, testKey TestApiKey)
|
|||||||
|
|
||||||
// SetupUsersServiceAccounts creates in "test org" all users or service accounts passed in parameter
|
// SetupUsersServiceAccounts creates in "test org" all users or service accounts passed in parameter
|
||||||
// To achieve this, it sets the AutoAssignOrg and AutoAssignOrgId settings.
|
// To achieve this, it sets the AutoAssignOrg and AutoAssignOrgId settings.
|
||||||
func SetupUsersServiceAccounts(t *testing.T, sqlStore *sqlstore.SQLStore, testUsers []TestUser) (orgID int64) {
|
func SetupUsersServiceAccounts(t *testing.T, sqlStore db.DB, cfg *setting.Cfg, testUsers []TestUser) (orgID int64) {
|
||||||
role := string(org.RoleNone)
|
role := string(org.RoleNone)
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
quotaService := quotaimpl.ProvideService(sqlStore, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(sqlStore, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
org, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{
|
org, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{
|
||||||
@@ -119,8 +119,8 @@ func SetupUsersServiceAccounts(t *testing.T, sqlStore *sqlstore.SQLStore, testUs
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
sqlStore.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
sqlStore.Cfg.AutoAssignOrgId = int(org.ID)
|
cfg.AutoAssignOrgId = int(org.ID)
|
||||||
|
|
||||||
for i := range testUsers {
|
for i := range testUsers {
|
||||||
_, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
_, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||||
|
|||||||
@@ -409,13 +409,15 @@ type InitTestDBOpt struct {
|
|||||||
// EnsureDefaultOrgAndUser flags whether to ensure that default org and user exist.
|
// EnsureDefaultOrgAndUser flags whether to ensure that default org and user exist.
|
||||||
EnsureDefaultOrgAndUser bool
|
EnsureDefaultOrgAndUser bool
|
||||||
FeatureFlags []string
|
FeatureFlags []string
|
||||||
|
Cfg *setting.Cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitTestDBWithMigration initializes the test DB given custom migrations.
|
// InitTestDBWithMigration initializes the test DB given custom migrations.
|
||||||
func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigrator, opts ...InitTestDBOpt) *SQLStore {
|
func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigrator, opts ...InitTestDBOpt) *SQLStore {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
features := getFeaturesForTesting(opts...)
|
features := getFeaturesForTesting(opts...)
|
||||||
store, err := initTestDB(t, setting.NewCfg(), features, migration, opts...)
|
cfg := getCfgForTesting(opts...)
|
||||||
|
store, err := initTestDB(t, cfg, features, migration, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to initialize sql store: %s", err)
|
t.Fatalf("failed to initialize sql store: %s", err)
|
||||||
}
|
}
|
||||||
@@ -426,8 +428,9 @@ func InitTestDBWithMigration(t sqlutil.ITestDB, migration registry.DatabaseMigra
|
|||||||
func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *SQLStore {
|
func InitTestDB(t sqlutil.ITestDB, opts ...InitTestDBOpt) *SQLStore {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
features := getFeaturesForTesting(opts...)
|
features := getFeaturesForTesting(opts...)
|
||||||
|
cfg := getCfgForTesting(opts...)
|
||||||
|
|
||||||
store, err := initTestDB(t, setting.NewCfg(), features, migrations.ProvideOSSMigrations(features), opts...)
|
store, err := initTestDB(t, cfg, features, migrations.ProvideOSSMigrations(features), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to initialize sql store: %s", err)
|
t.Fatalf("failed to initialize sql store: %s", err)
|
||||||
}
|
}
|
||||||
@@ -465,6 +468,16 @@ func CleanupTestDB() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCfgForTesting(opts ...InitTestDBOpt) *setting.Cfg {
|
||||||
|
cfg := setting.NewCfg()
|
||||||
|
for _, opt := range opts {
|
||||||
|
if len(opt.FeatureFlags) > 0 {
|
||||||
|
cfg = opt.Cfg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
func getFeaturesForTesting(opts ...InitTestDBOpt) featuremgmt.FeatureToggles {
|
func getFeaturesForTesting(opts ...InitTestDBOpt) featuremgmt.FeatureToggles {
|
||||||
featureKeys := []any{
|
featureKeys := []any{
|
||||||
featuremgmt.FlagPanelTitleSearch,
|
featuremgmt.FlagPanelTitleSearch,
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/db"
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/ssosettings"
|
"github.com/grafana/grafana/pkg/services/ssosettings"
|
||||||
"github.com/grafana/grafana/pkg/services/ssosettings/models"
|
"github.com/grafana/grafana/pkg/services/ssosettings/models"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
@@ -28,7 +27,7 @@ func TestIntegrationGetSSOSettings(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var ssoSettingsStore *SSOSettingsStore
|
var ssoSettingsStore *SSOSettingsStore
|
||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
@@ -91,7 +90,7 @@ func TestIntegrationUpsertSSOSettings(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var ssoSettingsStore *SSOSettingsStore
|
var ssoSettingsStore *SSOSettingsStore
|
||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
@@ -270,7 +269,7 @@ func TestIntegrationListSSOSettings(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var ssoSettingsStore *SSOSettingsStore
|
var ssoSettingsStore *SSOSettingsStore
|
||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
@@ -336,7 +335,7 @@ func TestIntegrationDeleteSSOSettings(t *testing.T) {
|
|||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlStore *sqlstore.SQLStore
|
var sqlStore db.DB
|
||||||
var ssoSettingsStore *SSOSettingsStore
|
var ssoSettingsStore *SSOSettingsStore
|
||||||
|
|
||||||
setup := func() {
|
setup := func() {
|
||||||
@@ -458,7 +457,7 @@ func TestIntegrationDeleteSSOSettings(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateSSOSettings(sqlStore *sqlstore.SQLStore, template models.SSOSettings, providers ...string) error {
|
func populateSSOSettings(sqlStore db.DB, template models.SSOSettings, providers ...string) error {
|
||||||
return sqlStore.WithDbSession(context.Background(), func(sess *db.Session) error {
|
return sqlStore.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||||
for _, provider := range providers {
|
for _, provider := range providers {
|
||||||
settings := models.SSOSettings{
|
settings := models.SSOSettings{
|
||||||
@@ -478,7 +477,7 @@ func populateSSOSettings(sqlStore *sqlstore.SQLStore, template models.SSOSetting
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSSOSettingsCountByDeleted(sqlStore *sqlstore.SQLStore) (deleted, notDeleted int64, err error) {
|
func getSSOSettingsCountByDeleted(sqlStore db.DB) (deleted, notDeleted int64, err error) {
|
||||||
err = sqlStore.WithDbSession(context.Background(), func(sess *db.Session) error {
|
err = sqlStore.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||||
deleted, err = sess.Table("sso_setting").Where("is_deleted = ?", sqlStore.GetDialect().BooleanStr(true)).Count()
|
deleted, err = sess.Table("sso_setting").Where("is_deleted = ?", sqlStore.GetDialect().BooleanStr(true)).Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -491,7 +490,7 @@ func getSSOSettingsCountByDeleted(sqlStore *sqlstore.SQLStore) (deleted, notDele
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSSOSettingsByProvider(sqlStore *sqlstore.SQLStore, provider string, deleted bool) (*models.SSOSettings, error) {
|
func getSSOSettingsByProvider(sqlStore db.DB, provider string, deleted bool) (*models.SSOSettings, error) {
|
||||||
var model models.SSOSettings
|
var model models.SSOSettings
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
"github.com/grafana/grafana/pkg/services/correlations"
|
"github.com/grafana/grafana/pkg/services/correlations"
|
||||||
"github.com/grafana/grafana/pkg/services/correlations/correlationstest"
|
"github.com/grafana/grafana/pkg/services/correlations/correlationstest"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
@@ -32,7 +35,7 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
db := sqlstore.InitTestDB(t)
|
db := sqlstore.InitTestDB(t)
|
||||||
statsService := &sqlStatsService{db: db}
|
statsService := &sqlStatsService{db: db}
|
||||||
populateDB(t, db)
|
populateDB(t, db, db.Cfg)
|
||||||
|
|
||||||
t.Run("Get system stats should not results in error", func(t *testing.T) {
|
t.Run("Get system stats should not results in error", func(t *testing.T) {
|
||||||
query := stats.GetSystemStatsQuery{}
|
query := stats.GetSystemStatsQuery{}
|
||||||
@@ -81,13 +84,14 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateDB(t *testing.T, sqlStore *sqlstore.SQLStore) {
|
func populateDB(t *testing.T, db db.DB, cfg *setting.Cfg) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
orgService, _ := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotatest.New(false, nil))
|
orgService, _ := orgimpl.ProvideService(db, cfg, quotatest.New(false, nil))
|
||||||
userSvc, _ := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
userSvc, _ := userimpl.ProvideService(db, orgService, cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService())
|
||||||
|
|
||||||
correlationsSvc := correlationstest.New(sqlStore)
|
bus := bus.ProvideBus(tracing.InitializeTracerForTest())
|
||||||
|
correlationsSvc := correlationstest.New(db, cfg, bus)
|
||||||
|
|
||||||
c := make([]correlations.Correlation, 2)
|
c := make([]correlations.Correlation, 2)
|
||||||
for i := range c {
|
for i := range c {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
|
|||||||
func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) (string, *user.SignedInUser) {
|
func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) (string, *user.SignedInUser) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
account := saTests.SetupUserServiceAccount(t, env.SQLStore, saTests.TestUser{
|
account := saTests.SetupUserServiceAccount(t, env.SQLStore, env.Cfg, saTests.TestUser{
|
||||||
Name: "grpc-server-sa",
|
Name: "grpc-server-sa",
|
||||||
Role: string(org.RoleAdmin),
|
Role: string(org.RoleAdmin),
|
||||||
Login: "grpc-server-sa",
|
Login: "grpc-server-sa",
|
||||||
@@ -38,7 +38,7 @@ func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) (string,
|
|||||||
keyGen, err := satokengen.New(saAPI.ServiceID)
|
keyGen, err := satokengen.New(saAPI.ServiceID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_ = saTests.SetupApiKey(t, env.SQLStore, saTests.TestApiKey{
|
_ = saTests.SetupApiKey(t, env.SQLStore, env.Cfg, saTests.TestApiKey{
|
||||||
Name: "grpc-server-test",
|
Name: "grpc-server-test",
|
||||||
Role: org.RoleAdmin,
|
Role: org.RoleAdmin,
|
||||||
OrgId: account.OrgID,
|
OrgId: account.OrgID,
|
||||||
@@ -79,7 +79,7 @@ func createTestContext(t *testing.T) testContext {
|
|||||||
|
|
||||||
authToken, serviceAccountUser := createServiceAccountAdminToken(t, env)
|
authToken, serviceAccountUser := createServiceAccountAdminToken(t, env)
|
||||||
|
|
||||||
eDB, err := dbimpl.ProvideEntityDB(env.SQLStore, env.SQLStore.Cfg, env.FeatureToggles)
|
eDB, err := dbimpl.ProvideEntityDB(env.SQLStore, env.Cfg, env.FeatureToggles)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = eDB.Init()
|
err = eDB.Init()
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/team"
|
"github.com/grafana/grafana/pkg/services/team"
|
||||||
"github.com/grafana/grafana/pkg/services/team/sortopts"
|
"github.com/grafana/grafana/pkg/services/team/sortopts"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -526,17 +526,17 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) {
|
|||||||
userIds := make([]int64, 4)
|
userIds := make([]int64, 4)
|
||||||
|
|
||||||
// Seed 2 teams with 2 members
|
// Seed 2 teams with 2 members
|
||||||
setup := func(store *sqlstore.SQLStore) {
|
setup := func(store db.DB, cfg *setting.Cfg) {
|
||||||
teamSvc, err := ProvideService(store, store.Cfg)
|
teamSvc, err := ProvideService(store, cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
team1, errCreateTeam := teamSvc.CreateTeam("group1 name", "test1@example.org", testOrgID)
|
team1, errCreateTeam := teamSvc.CreateTeam("group1 name", "test1@example.org", testOrgID)
|
||||||
require.NoError(t, errCreateTeam)
|
require.NoError(t, errCreateTeam)
|
||||||
team2, errCreateTeam := teamSvc.CreateTeam("group2 name", "test2@example.org", testOrgID)
|
team2, errCreateTeam := teamSvc.CreateTeam("group2 name", "test2@example.org", testOrgID)
|
||||||
require.NoError(t, errCreateTeam)
|
require.NoError(t, errCreateTeam)
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(store, cfg)
|
||||||
orgSvc, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgSvc, err := orgimpl.ProvideService(store, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
userSvc, err := userimpl.ProvideService(store, orgSvc, store.Cfg, teamSvc, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
userSvc, err := userimpl.ProvideService(store, orgSvc, cfg, teamSvc, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
@@ -561,7 +561,7 @@ func TestIntegrationSQLStore_GetTeamMembers_ACFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
store := db.InitTestDB(t, db.InitTestDBOpt{})
|
store := db.InitTestDB(t, db.InitTestDBOpt{})
|
||||||
setup(store)
|
setup(store, store.Cfg)
|
||||||
teamSvc, err := ProvideService(store, store.Cfg)
|
teamSvc, err := ProvideService(store, store.Cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ func TestIntegrationAdminConfiguration_SendingToExternalAlertmanagers(t *testing
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, s := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
orgService, err := orgimpl.ProvideService(s, s.Cfg, quotatest.New(false, nil))
|
orgService, err := orgimpl.ProvideService(env.SQLStore, env.Cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
userID := createUser(t, s, user.CreateUserCommand{
|
userID := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -63,7 +63,7 @@ func TestIntegrationAdminConfiguration_SendingToExternalAlertmanagers(t *testing
|
|||||||
require.Equal(t, disableOrgID, orgID)
|
require.Equal(t, disableOrgID, orgID)
|
||||||
|
|
||||||
// create user under different organisation
|
// create user under different organisation
|
||||||
createUser(t, s, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin-42",
|
Password: "admin-42",
|
||||||
Login: "admin-42",
|
Login: "admin-42",
|
||||||
@@ -362,8 +362,8 @@ func TestIntegrationAdminConfiguration_CannotCreateInhibitionRules(t *testing.T)
|
|||||||
EnableUnifiedAlerting: true,
|
EnableUnifiedAlerting: true,
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ func TestIntegrationAlertmanagerConfiguration(t *testing.T) {
|
|||||||
EnableUnifiedAlerting: true,
|
EnableUnifiedAlerting: true,
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -283,16 +283,16 @@ func TestIntegrationAlertmanagerConfigurationIsTransactional(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotatest.New(false, nil))
|
orgService, err := orgimpl.ProvideService(env.SQLStore, env.Cfg, quotatest.New(false, nil))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// editor from main organisation requests configuration
|
// editor from main organisation requests configuration
|
||||||
alertConfigURL := fmt.Sprintf("http://editor:editor@%s/api/alertmanager/grafana/config/api/v1/alerts", grafanaListedAddr)
|
alertConfigURL := fmt.Sprintf("http://editor:editor@%s/api/alertmanager/grafana/config/api/v1/alerts", grafanaListedAddr)
|
||||||
|
|
||||||
// create user under main organisation
|
// create user under main organisation
|
||||||
userID := createUser(t, store, user.CreateUserCommand{
|
userID := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
@@ -304,7 +304,7 @@ func TestIntegrationAlertmanagerConfigurationIsTransactional(t *testing.T) {
|
|||||||
orgID := newOrg.ID
|
orgID := newOrg.ID
|
||||||
|
|
||||||
// create user under different organisation
|
// create user under different organisation
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor-42",
|
Password: "editor-42",
|
||||||
Login: "editor-42",
|
Login: "editor-42",
|
||||||
@@ -401,10 +401,10 @@ func TestIntegrationAlertmanagerConfigurationPersistSecrets(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
alertConfigURL := fmt.Sprintf("http://editor:editor@%s/api/alertmanager/grafana/config/api/v1/alerts", grafanaListedAddr)
|
alertConfigURL := fmt.Sprintf("http://editor:editor@%s/api/alertmanager/grafana/config/api/v1/alerts", grafanaListedAddr)
|
||||||
|
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/expr"
|
"github.com/grafana/grafana/pkg/expr"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||||
ngstore "github.com/grafana/grafana/pkg/services/ngalert/store"
|
ngstore "github.com/grafana/grafana/pkg/services/ngalert/store"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
@@ -50,20 +50,20 @@ func TestIntegrationAMConfigAccess(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a users to make authenticated requests
|
// Create a users to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleViewer),
|
DefaultOrgRole: string(org.RoleViewer),
|
||||||
Password: "viewer",
|
Password: "viewer",
|
||||||
Login: "viewer",
|
Login: "viewer",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -425,7 +425,7 @@ func TestIntegrationAlertAndGroupsQuery(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// unauthenticated request to get the alerts should fail
|
// unauthenticated request to get the alerts should fail
|
||||||
{
|
{
|
||||||
@@ -444,7 +444,7 @@ func TestIntegrationAlertAndGroupsQuery(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -587,20 +587,20 @@ func TestIntegrationRulerAccess(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a users to make authenticated requests
|
// Create a users to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleViewer),
|
DefaultOrgRole: string(org.RoleViewer),
|
||||||
Password: "viewer",
|
Password: "viewer",
|
||||||
Login: "viewer",
|
Login: "viewer",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -704,14 +704,14 @@ func TestIntegrationDeleteFolderWithRules(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleViewer),
|
DefaultOrgRole: string(org.RoleViewer),
|
||||||
Password: "viewer",
|
Password: "viewer",
|
||||||
Login: "viewer",
|
Login: "viewer",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
@@ -868,9 +868,9 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -1865,8 +1865,8 @@ func TestIntegrationAlertmanagerCreateSilence(t *testing.T) {
|
|||||||
EnableUnifiedAlerting: true,
|
EnableUnifiedAlerting: true,
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -2018,20 +2018,19 @@ func TestIntegrationAlertmanagerStatus(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a users to make authenticated requests
|
// Create a users to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleViewer),
|
DefaultOrgRole: string(org.RoleViewer),
|
||||||
Password: "viewer",
|
Password: "viewer",
|
||||||
Login: "viewer",
|
Login: "viewer",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -2154,10 +2153,10 @@ func TestIntegrationQuota(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
// needs permission to update org quota
|
// needs permission to update org quota
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
@@ -2355,9 +2354,9 @@ func TestIntegrationEval(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -2641,16 +2640,16 @@ func rulesNamespaceWithoutVariableValues(t *testing.T, b []byte) (string, map[st
|
|||||||
return string(json), m
|
return string(json), m
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) int64 {
|
func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = 1
|
cfg.AutoAssignOrgId = 1
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.Create(context.Background(), &cmd)
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ func TestIntegrationAvailableChannels(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestBacktesting(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
userId := createUser(t, env.SQLStore, user.CreateUserCommand{
|
userId := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -92,7 +92,7 @@ func TestBacktesting(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("if user does not have permissions", func(t *testing.T) {
|
t.Run("if user does not have permissions", func(t *testing.T) {
|
||||||
testUserId := createUser(t, env.SQLStore, user.CreateUserCommand{
|
testUserId := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(roletype.RoleNone),
|
DefaultOrgRole: string(roletype.RoleNone),
|
||||||
Password: "test",
|
Password: "test",
|
||||||
Login: "test",
|
Login: "test",
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func TestIntegrationTestReceivers(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -86,7 +86,7 @@ func TestIntegrationTestReceivers(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -169,7 +169,7 @@ func TestIntegrationTestReceivers(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -249,7 +249,7 @@ func TestIntegrationTestReceivers(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -350,7 +350,7 @@ func TestIntegrationTestReceivers(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -429,7 +429,7 @@ func TestIntegrationTestReceivers(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -516,7 +516,7 @@ func TestIntegrationTestReceivers(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -633,7 +633,7 @@ func TestIntegrationTestReceiversAlertCustomization(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -726,7 +726,7 @@ func TestIntegrationTestReceiversAlertCustomization(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -814,7 +814,7 @@ func TestIntegrationTestReceiversAlertCustomization(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -943,7 +943,7 @@ func TestIntegrationNotificationChannels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, env.SQLStore, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ func TestTimeInterval(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ func TestIntegrationPrometheusRules(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -347,10 +347,10 @@ func TestIntegrationPrometheusRulesFilterByDashboard(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -657,10 +657,10 @@ func TestIntegrationPrometheusRulesPermissions(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
userID := createUser(t, store, user.CreateUserCommand{
|
userID := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -669,7 +669,7 @@ func TestIntegrationPrometheusRulesPermissions(t *testing.T) {
|
|||||||
apiClient := newAlertingApiClient(grafanaListedAddr, "grafana", "password")
|
apiClient := newAlertingApiClient(grafanaListedAddr, "grafana", "password")
|
||||||
|
|
||||||
// access control permissions store
|
// access control permissions store
|
||||||
permissionsStore := resourcepermissions.NewStore(store, featuremgmt.WithFeatures())
|
permissionsStore := resourcepermissions.NewStore(env.SQLStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
// Create the namespace we'll save our alerts to.
|
// Create the namespace we'll save our alerts to.
|
||||||
apiClient.CreateFolder(t, "folder1", "folder1")
|
apiClient.CreateFolder(t, "folder1", "folder1")
|
||||||
|
|||||||
@@ -34,20 +34,20 @@ func TestIntegrationProvisioning(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a users to make authenticated requests
|
// Create a users to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleViewer),
|
DefaultOrgRole: string(org.RoleViewer),
|
||||||
Password: "viewer",
|
Password: "viewer",
|
||||||
Login: "viewer",
|
Login: "viewer",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
})
|
})
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -385,9 +385,9 @@ func TestMuteTimings(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ func TestIntegrationAlertRulePermissions(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, p)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, p)
|
||||||
permissionsStore := resourcepermissions.NewStore(store, featuremgmt.WithFeatures())
|
permissionsStore := resourcepermissions.NewStore(env.SQLStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
userID := createUser(t, store, user.CreateUserCommand{
|
userID := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -335,11 +335,11 @@ func TestIntegrationAlertRuleNestedPermissions(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, p)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, p)
|
||||||
permissionsStore := resourcepermissions.NewStore(store, featuremgmt.WithFeatures())
|
permissionsStore := resourcepermissions.NewStore(env.SQLStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
userID := createUser(t, store, user.CreateUserCommand{
|
userID := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -731,11 +731,11 @@ func TestAlertRulePostExport(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, p)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, p)
|
||||||
permissionsStore := resourcepermissions.NewStore(store, featuremgmt.WithFeatures())
|
permissionsStore := resourcepermissions.NewStore(env.SQLStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
userID := createUser(t, store, user.CreateUserCommand{
|
userID := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -811,10 +811,10 @@ func TestIntegrationAlertRuleConflictingTitle(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create user
|
// Create user
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -901,10 +901,10 @@ func TestIntegrationRulerRulesFilterByDashboard(t *testing.T) {
|
|||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -1241,10 +1241,10 @@ func TestIntegrationRuleGroupSequence(t *testing.T) {
|
|||||||
DisableAnonymous: true,
|
DisableAnonymous: true,
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -1338,8 +1338,8 @@ func TestIntegrationRuleCreate(t *testing.T) {
|
|||||||
EnableUnifiedAlerting: true,
|
EnableUnifiedAlerting: true,
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -1411,11 +1411,11 @@ func TestIntegrationRuleUpdate(t *testing.T) {
|
|||||||
DisableAnonymous: true,
|
DisableAnonymous: true,
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
permissionsStore := resourcepermissions.NewStore(store, featuremgmt.WithFeatures())
|
permissionsStore := resourcepermissions.NewStore(env.SQLStore, featuremgmt.WithFeatures())
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
userID := createUser(t, store, user.CreateUserCommand{
|
userID := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -1438,7 +1438,7 @@ func TestIntegrationRuleUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -1628,10 +1628,10 @@ func TestIntegrationRulePause(t *testing.T) {
|
|||||||
DisableAnonymous: true,
|
DisableAnonymous: true,
|
||||||
AppModeProduction: true,
|
AppModeProduction: true,
|
||||||
})
|
})
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -1758,10 +1758,10 @@ func TestIntegrationHysteresisRule(t *testing.T) {
|
|||||||
EnableFeatureToggles: []string{featuremgmt.FlagConfigurableSchedulerTick, featuremgmt.FlagRecoveryThreshold},
|
EnableFeatureToggles: []string{featuremgmt.FlagConfigurableSchedulerTick, featuremgmt.FlagRecoveryThreshold},
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, p)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, p)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
@@ -1832,10 +1832,10 @@ func TestIntegrationRuleNotificationSettings(t *testing.T) {
|
|||||||
EnableFeatureToggles: []string{featuremgmt.FlagConfigurableSchedulerTick, featuremgmt.FlagAlertingSimplifiedRouting},
|
EnableFeatureToggles: []string{featuremgmt.FlagConfigurableSchedulerTick, featuremgmt.FlagAlertingSimplifiedRouting},
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, p)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, p)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "password",
|
Password: "password",
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func TestGrafanaRuleConfig(t *testing.T) {
|
|||||||
|
|
||||||
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
userId := createUser(t, env.SQLStore, user.CreateUserCommand{
|
userId := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -260,7 +260,7 @@ func TestGrafanaRuleConfig(t *testing.T) {
|
|||||||
|
|
||||||
t.Skip("flakey tests - skipping") //TODO: Fix tests and remove skip.
|
t.Skip("flakey tests - skipping") //TODO: Fix tests and remove skip.
|
||||||
|
|
||||||
testUserId := createUser(t, env.SQLStore, user.CreateUserCommand{
|
testUserId := createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: "DOESNOTEXIST", // Needed so that the SignedInUser has OrgId=1. Otherwise, datasource will not be found.
|
DefaultOrgRole: "DOESNOTEXIST", // Needed so that the SignedInUser has OrgId=1. Otherwise, datasource will not be found.
|
||||||
Password: "test",
|
Password: "test",
|
||||||
Login: "test",
|
Login: "test",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestIntegrationAzureMonitor(t *testing.T) {
|
|||||||
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -142,9 +142,9 @@ func (c TestContext) getURL(url string, user User) string {
|
|||||||
func (c TestContext) createOrg(name string) int64 {
|
func (c TestContext) createOrg(name string) int64 {
|
||||||
c.t.Helper()
|
c.t.Helper()
|
||||||
store := c.env.SQLStore
|
store := c.env.SQLStore
|
||||||
store.Cfg.AutoAssignOrg = false
|
c.env.Cfg.AutoAssignOrg = false
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(store, c.env.Cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
orgId, err := orgService.GetOrCreate(context.Background(), name)
|
orgId, err := orgService.GetOrCreate(context.Background(), name)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
@@ -154,13 +154,13 @@ func (c TestContext) createOrg(name string) int64 {
|
|||||||
func (c TestContext) createUser(cmd user.CreateUserCommand) User {
|
func (c TestContext) createUser(cmd user.CreateUserCommand) User {
|
||||||
c.t.Helper()
|
c.t.Helper()
|
||||||
store := c.env.SQLStore
|
store := c.env.SQLStore
|
||||||
store.Cfg.AutoAssignOrg = true
|
c.env.Cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = 1
|
c.env.Cfg.AutoAssignOrgId = 1
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(store, c.env.Cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, c.env.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
user, err := usrSvc.Create(context.Background(), &cmd)
|
user, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboardimport"
|
"github.com/grafana/grafana/pkg/services/dashboardimport"
|
||||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/folder"
|
"github.com/grafana/grafana/pkg/services/folder"
|
||||||
@@ -25,10 +26,10 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/plugindashboards"
|
"github.com/grafana/grafana/pkg/services/plugindashboards"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/search/model"
|
"github.com/grafana/grafana/pkg/services/search/model"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
@@ -52,9 +53,10 @@ func TestIntegrationDashboardQuota(t *testing.T) {
|
|||||||
DashboardOrgQuota: &dashboardQuota,
|
DashboardOrgQuota: &dashboardQuota,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
store, cfg := env.SQLStore, env.Cfg
|
||||||
// Create user
|
// Create user
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, store, cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -110,16 +112,16 @@ func TestIntegrationDashboardQuota(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) int64 {
|
func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = 1
|
cfg.AutoAssignOrgId = 1
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.Create(context.Background(), &cmd)
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
@@ -155,9 +157,10 @@ providers:
|
|||||||
provDashboardFile := filepath.Join(provDashboardsDir, "home.json")
|
provDashboardFile := filepath.Join(provDashboardsDir, "home.json")
|
||||||
err = os.WriteFile(provDashboardFile, input, 0644)
|
err = os.WriteFile(provDashboardFile, input, 0644)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
store, cfg := env.SQLStore, env.Cfg
|
||||||
// Create user
|
// Create user
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, store, cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -291,9 +294,10 @@ func TestIntegrationCreate(t *testing.T) {
|
|||||||
DisableAnonymous: true,
|
DisableAnonymous: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
store, cfg := env.SQLStore, env.Cfg
|
||||||
// Create user
|
// Create user
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, store, cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestIntegrationElasticsearch(t *testing.T) {
|
|||||||
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -9,14 +9,15 @@ import (
|
|||||||
"github.com/go-openapi/runtime"
|
"github.com/go-openapi/runtime"
|
||||||
"github.com/grafana/grafana-openapi-client-go/client/folders"
|
"github.com/grafana/grafana-openapi-client-go/client/folders"
|
||||||
"github.com/grafana/grafana-openapi-client-go/models"
|
"github.com/grafana/grafana-openapi-client-go/models"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tests"
|
"github.com/grafana/grafana/pkg/tests"
|
||||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -35,9 +36,10 @@ func TestIntegrationUpdateFolder(t *testing.T) {
|
|||||||
EnableQuota: true,
|
EnableQuota: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
store, cfg := env.SQLStore, env.Cfg
|
||||||
// Create user
|
// Create user
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, store, cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -71,9 +73,10 @@ func TestIntegrationCreateFolder(t *testing.T) {
|
|||||||
EnableQuota: true,
|
EnableQuota: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
store, cfg := env.SQLStore, env.Cfg
|
||||||
// Create user
|
// Create user
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, store, cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -111,9 +114,10 @@ func TestIntegrationNestedFoldersOn(t *testing.T) {
|
|||||||
EnableFeatureToggles: []string{featuremgmt.FlagNestedFolders},
|
EnableFeatureToggles: []string{featuremgmt.FlagNestedFolders},
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
store, cfg := env.SQLStore, env.Cfg
|
||||||
// Create user
|
// Create user
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, store, cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -202,16 +206,16 @@ func TestIntegrationNestedFoldersOn(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) int64 {
|
func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = orgID
|
cfg.AutoAssignOrgId = orgID
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.Create(context.Background(), &cmd)
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
|
|||||||
@@ -35,24 +35,25 @@ func TestGetFolders(t *testing.T) {
|
|||||||
EnableFeatureToggles: []string{featuremgmt.FlagNestedFolders},
|
EnableFeatureToggles: []string{featuremgmt.FlagNestedFolders},
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, p)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, p)
|
||||||
|
store, cfg := env.SQLStore, env.Cfg
|
||||||
|
|
||||||
orgID := int64(1)
|
orgID := int64(1)
|
||||||
|
|
||||||
// Create a users to make authenticated requests
|
// Create a users to make authenticated requests
|
||||||
tests.CreateUser(t, store, user.CreateUserCommand{
|
tests.CreateUser(t, store, cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleViewer),
|
DefaultOrgRole: string(org.RoleViewer),
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
Password: "viewer",
|
Password: "viewer",
|
||||||
Login: "viewer",
|
Login: "viewer",
|
||||||
})
|
})
|
||||||
tests.CreateUser(t, store, user.CreateUserCommand{
|
tests.CreateUser(t, store, cfg, user.CreateUserCommand{
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
Password: "editor",
|
Password: "editor",
|
||||||
Login: "editor",
|
Login: "editor",
|
||||||
})
|
})
|
||||||
tests.CreateUser(t, store, user.CreateUserCommand{
|
tests.CreateUser(t, store, cfg, user.CreateUserCommand{
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestIntegrationGraphite(t *testing.T) {
|
|||||||
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestIntegrationInflux(t *testing.T) {
|
|||||||
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestIntegrationLoki(t *testing.T) {
|
|||||||
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TestIntegrationOpenTSDB(t *testing.T) {
|
|||||||
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/plugins"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
@@ -56,7 +56,8 @@ func TestIntegrationPlugins(t *testing.T) {
|
|||||||
setting.BuildVersion = origBuildVersion
|
setting.BuildVersion = origBuildVersion
|
||||||
})
|
})
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, cfgPath)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, cfgPath)
|
||||||
|
store := env.SQLStore
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
desc string
|
desc string
|
||||||
@@ -66,8 +67,8 @@ func TestIntegrationPlugins(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Install", func(t *testing.T) {
|
t.Run("Install", func(t *testing.T) {
|
||||||
createUser(t, store, user.CreateUserCommand{Login: usernameNonAdmin, Password: defaultPassword, IsAdmin: false})
|
createUser(t, store, env.Cfg, user.CreateUserCommand{Login: usernameNonAdmin, Password: defaultPassword, IsAdmin: false})
|
||||||
createUser(t, store, user.CreateUserCommand{Login: usernameAdmin, Password: defaultPassword, IsAdmin: true})
|
createUser(t, store, env.Cfg, user.CreateUserCommand{Login: usernameAdmin, Password: defaultPassword, IsAdmin: true})
|
||||||
|
|
||||||
t.Run("Request is forbidden if not from an admin", func(t *testing.T) {
|
t.Run("Request is forbidden if not from an admin", func(t *testing.T) {
|
||||||
status, body := makePostRequest(t, grafanaAPIURL(usernameNonAdmin, grafanaListedAddr, "plugins/grafana-plugin/install"))
|
status, body := makePostRequest(t, grafanaAPIURL(usernameNonAdmin, grafanaListedAddr, "plugins/grafana-plugin/install"))
|
||||||
@@ -191,16 +192,16 @@ func TestIntegrationPluginAssets(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) {
|
func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = 1
|
cfg.AutoAssignOrgId = 1
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = usrSvc.Create(context.Background(), &cmd)
|
_, err = usrSvc.Create(context.Background(), &cmd)
|
||||||
|
|||||||
@@ -482,11 +482,11 @@ func newTestScenario(t *testing.T, name string, opts []testScenarioOption, callb
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
tsCtx.grafanaListeningAddr = grafanaListeningAddr
|
tsCtx.grafanaListeningAddr = grafanaListeningAddr
|
||||||
testEnv.SQLStore.Cfg.LoginCookieName = loginCookieName
|
testEnv.Cfg.LoginCookieName = loginCookieName
|
||||||
tsCtx.testEnv = testEnv
|
tsCtx.testEnv = testEnv
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@@ -646,7 +646,7 @@ func (tsCtx *testScenarioContext) runQueryDataTest(t *testing.T, mr dtos.MetricR
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.NotEmpty(t, tsCtx.outgoingRequest.Header.Get("Accept-Encoding"))
|
require.NotEmpty(t, tsCtx.outgoingRequest.Header.Get("Accept-Encoding"))
|
||||||
require.Equal(t, fmt.Sprintf("Grafana/%s", tsCtx.testEnv.SQLStore.Cfg.BuildVersion), tsCtx.outgoingRequest.Header.Get("User-Agent"))
|
require.Equal(t, fmt.Sprintf("Grafana/%s", tsCtx.testEnv.Cfg.BuildVersion), tsCtx.outgoingRequest.Header.Get("User-Agent"))
|
||||||
|
|
||||||
callback(received)
|
callback(received)
|
||||||
})
|
})
|
||||||
@@ -704,7 +704,7 @@ func (tsCtx *testScenarioContext) runCheckHealthTest(t *testing.T, callback func
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.NotEmpty(t, tsCtx.outgoingRequest.Header.Get("Accept-Encoding"))
|
require.NotEmpty(t, tsCtx.outgoingRequest.Header.Get("Accept-Encoding"))
|
||||||
require.Equal(t, fmt.Sprintf("Grafana/%s", tsCtx.testEnv.SQLStore.Cfg.BuildVersion), tsCtx.outgoingRequest.Header.Get("User-Agent"))
|
require.Equal(t, fmt.Sprintf("Grafana/%s", tsCtx.testEnv.Cfg.BuildVersion), tsCtx.outgoingRequest.Header.Get("User-Agent"))
|
||||||
|
|
||||||
callback(received)
|
callback(received)
|
||||||
})
|
})
|
||||||
@@ -779,7 +779,7 @@ func (tsCtx *testScenarioContext) runCallResourceTest(t *testing.T, callback fun
|
|||||||
require.Empty(t, tsCtx.outgoingRequest.Header.Get("X-Some-Conn-Header"))
|
require.Empty(t, tsCtx.outgoingRequest.Header.Get("X-Some-Conn-Header"))
|
||||||
require.Empty(t, tsCtx.outgoingRequest.Header.Get("Proxy-Connection"))
|
require.Empty(t, tsCtx.outgoingRequest.Header.Get("Proxy-Connection"))
|
||||||
require.NotEmpty(t, tsCtx.outgoingRequest.Header.Get("Accept-Encoding"))
|
require.NotEmpty(t, tsCtx.outgoingRequest.Header.Get("Accept-Encoding"))
|
||||||
require.Equal(t, fmt.Sprintf("Grafana/%s", tsCtx.testEnv.SQLStore.Cfg.BuildVersion), tsCtx.outgoingRequest.Header.Get("User-Agent"))
|
require.Equal(t, fmt.Sprintf("Grafana/%s", tsCtx.testEnv.Cfg.BuildVersion), tsCtx.outgoingRequest.Header.Get("User-Agent"))
|
||||||
|
|
||||||
callback(received, resp)
|
callback(received, resp)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func TestIntegrationPrometheus(t *testing.T) {
|
|||||||
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
grafanaListeningAddr, testEnv := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, testEnv.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||||
)
|
)
|
||||||
@@ -66,10 +67,10 @@ func grafanaSetup(t *testing.T, opts testinfra.GrafanaOpts) string {
|
|||||||
// Setup Grafana and its Database
|
// Setup Grafana and its Database
|
||||||
dir, path := testinfra.CreateGrafDir(t, opts)
|
dir, path := testinfra.CreateGrafDir(t, opts)
|
||||||
|
|
||||||
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, path)
|
grafanaListedAddr, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||||
|
|
||||||
// Create a user to make authenticated requests
|
// Create a user to make authenticated requests
|
||||||
createUser(t, store, user.CreateUserCommand{
|
createUser(t, env.SQLStore, env.Cfg, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Login: "grafana",
|
Login: "grafana",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -79,16 +80,16 @@ func grafanaSetup(t *testing.T, opts testinfra.GrafanaOpts) string {
|
|||||||
return fmt.Sprintf("http://%s:%s@%s/api/admin/stats", "grafana", "password", grafanaListedAddr)
|
return fmt.Sprintf("http://%s:%s@%s/api/admin/stats", "grafana", "password", grafanaListedAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) int64 {
|
func createUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = 1
|
cfg.AutoAssignOrgId = 1
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.Create(context.Background(), &cmd)
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
|
|||||||
@@ -375,13 +375,13 @@ func (c K8sTestHelper) createTestUsers(orgName string) OrgUsers {
|
|||||||
|
|
||||||
store := c.env.SQLStore
|
store := c.env.SQLStore
|
||||||
defer func() {
|
defer func() {
|
||||||
store.Cfg.AutoAssignOrg = false
|
c.env.Cfg.AutoAssignOrg = false
|
||||||
store.Cfg.AutoAssignOrgId = 1 // the default
|
c.env.Cfg.AutoAssignOrgId = 1 // the default
|
||||||
}()
|
}()
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(store, c.env.Cfg)
|
||||||
|
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(store, c.env.Cfg, quotaService)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
orgId := int64(1)
|
orgId := int64(1)
|
||||||
@@ -389,15 +389,15 @@ func (c K8sTestHelper) createTestUsers(orgName string) OrgUsers {
|
|||||||
orgId, err = orgService.GetOrCreate(context.Background(), orgName)
|
orgId, err = orgService.GetOrCreate(context.Background(), orgName)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
}
|
}
|
||||||
store.Cfg.AutoAssignOrg = true
|
c.env.Cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = int(orgId)
|
c.env.Cfg.AutoAssignOrgId = int(orgId)
|
||||||
|
|
||||||
teamSvc, err := teamimpl.ProvideService(store, store.Cfg)
|
teamSvc, err := teamimpl.ProvideService(store, c.env.Cfg)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
cache := localcache.ProvideService()
|
cache := localcache.ProvideService()
|
||||||
userSvc, err := userimpl.ProvideService(store,
|
userSvc, err := userimpl.ProvideService(store,
|
||||||
orgService, store.Cfg, teamSvc, cache, quotaService,
|
orgService, c.env.Cfg, teamSvc, cache, quotaService,
|
||||||
supportbundlestest.NewFakeBundleService())
|
supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
@@ -33,7 +32,7 @@ import (
|
|||||||
|
|
||||||
// StartGrafana starts a Grafana server.
|
// StartGrafana starts a Grafana server.
|
||||||
// The server address is returned.
|
// The server address is returned.
|
||||||
func StartGrafana(t *testing.T, grafDir, cfgPath string) (string, *sqlstore.SQLStore) {
|
func StartGrafana(t *testing.T, grafDir, cfgPath string) (string, db.DB) {
|
||||||
addr, env := StartGrafanaEnv(t, grafDir, cfgPath)
|
addr, env := StartGrafanaEnv(t, grafDir, cfgPath)
|
||||||
return addr, env.SQLStore
|
return addr, env.SQLStore
|
||||||
}
|
}
|
||||||
@@ -53,8 +52,8 @@ func StartGrafanaEnv(t *testing.T, grafDir, cfgPath string) (string, *server.Tes
|
|||||||
env, err := server.InitializeForTest(t, cfg, serverOpts, apiServerOpts)
|
env, err := server.InitializeForTest(t, cfg, serverOpts, apiServerOpts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.NotNil(t, env.SQLStore.Cfg)
|
require.NotNil(t, env.Cfg)
|
||||||
dbSec, err := env.SQLStore.Cfg.Raw.GetSection("database")
|
dbSec, err := env.Cfg.Raw.GetSection("database")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Greater(t, dbSec.Key("query_retries").MustInt(), 0)
|
assert.Greater(t, dbSec.Key("query_retries").MustInt(), 0)
|
||||||
|
|
||||||
@@ -250,6 +249,7 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
|
|||||||
return section, err
|
return section, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queryRetries := 3
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if o.EnableCSP {
|
if o.EnableCSP {
|
||||||
securitySect, err := cfg.NewSection("security")
|
securitySect, err := cfg.NewSection("security")
|
||||||
@@ -364,14 +364,9 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
// retry queries 3 times by default
|
// retry queries 3 times by default
|
||||||
queryRetries := 3
|
|
||||||
if o.QueryRetries != 0 {
|
if o.QueryRetries != 0 {
|
||||||
queryRetries = int(o.QueryRetries)
|
queryRetries = int(o.QueryRetries)
|
||||||
}
|
}
|
||||||
logSection, err := getOrCreateSection("database")
|
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = logSection.NewKey("query_retries", fmt.Sprintf("%d", queryRetries))
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
if o.NGAlertSchedulerBaseInterval > 0 {
|
if o.NGAlertSchedulerBaseInterval > 0 {
|
||||||
unifiedAlertingSection, err := getOrCreateSection("unified_alerting")
|
unifiedAlertingSection, err := getOrCreateSection("unified_alerting")
|
||||||
@@ -382,6 +377,10 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logSection, err := getOrCreateSection("database")
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = logSection.NewKey("query_retries", fmt.Sprintf("%d", queryRetries))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
cfgPath := filepath.Join(cfgDir, "test.ini")
|
cfgPath := filepath.Join(cfgDir, "test.ini")
|
||||||
err = cfg.SaveTo(cfgPath)
|
err = cfg.SaveTo(cfgPath)
|
||||||
@@ -425,17 +424,17 @@ type GrafanaOpts struct {
|
|||||||
APIServerStorageType string
|
APIServerStorageType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) *user.User {
|
func CreateUser(t *testing.T, store db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) *user.User {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = 1
|
cfg.AutoAssignOrgId = 1
|
||||||
cmd.OrgID = 1
|
cmd.OrgID = 1
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(store, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(store, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
o, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: fmt.Sprintf("test org %d", time.Now().UnixNano())})
|
o, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: fmt.Sprintf("test org %d", time.Now().UnixNano())})
|
||||||
|
|||||||
@@ -9,27 +9,28 @@ import (
|
|||||||
|
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
goapi "github.com/grafana/grafana-openapi-client-go/client"
|
goapi "github.com/grafana/grafana-openapi-client-go/client"
|
||||||
|
"github.com/grafana/grafana/pkg/infra/db"
|
||||||
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
|
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
||||||
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
|
||||||
"github.com/grafana/grafana/pkg/services/user"
|
"github.com/grafana/grafana/pkg/services/user"
|
||||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) int64 {
|
func CreateUser(t *testing.T, db db.DB, cfg *setting.Cfg, cmd user.CreateUserCommand) int64 {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
cfg.AutoAssignOrg = true
|
||||||
store.Cfg.AutoAssignOrgId = 1
|
cfg.AutoAssignOrgId = 1
|
||||||
|
|
||||||
quotaService := quotaimpl.ProvideService(store, store.Cfg)
|
quotaService := quotaimpl.ProvideService(db, cfg)
|
||||||
orgService, err := orgimpl.ProvideService(store, store.Cfg, quotaService)
|
orgService, err := orgimpl.ProvideService(db, cfg, quotaService)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(db, orgService, cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.Create(context.Background(), &cmd)
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
|
|||||||
@@ -125,8 +125,9 @@ func TestIntegrationIndexViewAnalytics(t *testing.T) {
|
|||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{})
|
grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{})
|
||||||
addr, store := testinfra.StartGrafana(t, grafDir, cfgPath)
|
addr, env := testinfra.StartGrafanaEnv(t, grafDir, cfgPath)
|
||||||
createdUser := testinfra.CreateUser(t, store, user.CreateUserCommand{
|
store := env.SQLStore
|
||||||
|
createdUser := testinfra.CreateUser(t, store, env.Cfg, user.CreateUserCommand{
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Email: "admin@grafana.com",
|
Email: "admin@grafana.com",
|
||||||
|
|||||||
Reference in New Issue
Block a user