mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove CreateUserForTests() (#64125)
* Chore: Remove CreateUserForTests * Apply suggestion from code review
This commit is contained in:
parent
a52999a886
commit
e6e8351ee9
@ -65,7 +65,7 @@ func setUpGetTeamMembersHandler(t *testing.T, sqlStore *sqlstore.SQLStore) {
|
|||||||
Login: fmt.Sprint("loginuser", i),
|
Login: fmt.Sprint("loginuser", i),
|
||||||
}
|
}
|
||||||
// user
|
// user
|
||||||
user, err := usrSvc.CreateUserForTests(context.Background(), &userCmd)
|
user, err := usrSvc.Create(context.Background(), &userCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = teamSvc.AddTeamMember(user.ID, testOrgID, team.ID, false, 1)
|
err = teamSvc.AddTeamMember(user.ID, testOrgID, team.ID, false, 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -78,7 +78,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
|||||||
Login: "loginuser",
|
Login: "loginuser",
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
}
|
}
|
||||||
usr, err := userSvc.CreateUserForTests(context.Background(), &createUserCmd)
|
usr, err := userSvc.Create(context.Background(), &createUserCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
sc.handlerFunc = hs.GetUserByID
|
sc.handlerFunc = hs.GetUserByID
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -107,17 +108,20 @@ func TestBuildConflictBlock(t *testing.T) {
|
|||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
// Restore after destructive operation
|
// Restore after destructive operation
|
||||||
sqlStore := db.InitTestDB(t)
|
sqlStore := db.InitTestDB(t)
|
||||||
usrSvc := setupTestUserService(t, sqlStore)
|
|
||||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||||
|
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||||
for _, u := range tc.users {
|
for _, u := range tc.users {
|
||||||
cmd := user.CreateUserCommand{
|
u := user.User{
|
||||||
Email: u.Email,
|
Email: u.Email,
|
||||||
Name: u.Name,
|
Name: u.Name,
|
||||||
Login: u.Login,
|
Login: u.Login,
|
||||||
OrgID: int64(testOrgID),
|
OrgID: int64(testOrgID),
|
||||||
|
Created: time.Now(),
|
||||||
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
_, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
// call user store instead of user service so as not to prevent conflicting users
|
||||||
require.NoError(t, err)
|
_, err := userStore.Insert(context.Background(), &u)
|
||||||
|
require.NoError(t, err, u)
|
||||||
}
|
}
|
||||||
m, err := GetUsersWithConflictingEmailsOrLogins(&cli.Context{Context: context.Background()}, sqlStore)
|
m, err := GetUsersWithConflictingEmailsOrLogins(&cli.Context{Context: context.Background()}, sqlStore)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -212,16 +216,19 @@ conflict: test2
|
|||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
// Restore after destructive operation
|
// Restore after destructive operation
|
||||||
sqlStore := db.InitTestDB(t)
|
sqlStore := db.InitTestDB(t)
|
||||||
usrSvc := setupTestUserService(t, sqlStore)
|
|
||||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||||
|
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||||
for _, u := range tc.users {
|
for _, u := range tc.users {
|
||||||
cmd := user.CreateUserCommand{
|
u := user.User{
|
||||||
Email: u.Email,
|
Email: u.Email,
|
||||||
Name: u.Name,
|
Name: u.Name,
|
||||||
Login: u.Login,
|
Login: u.Login,
|
||||||
OrgID: int64(testOrgID),
|
OrgID: int64(testOrgID),
|
||||||
|
Created: time.Now(),
|
||||||
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
_, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
// call user store instead of user service so as not to prevent conflicting users
|
||||||
|
_, err := userStore.Insert(context.Background(), &u)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,17 +397,20 @@ func TestGetConflictingUsers(t *testing.T) {
|
|||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
// Restore after destructive operation
|
// Restore after destructive operation
|
||||||
sqlStore := db.InitTestDB(t)
|
sqlStore := db.InitTestDB(t)
|
||||||
usrSvc := setupTestUserService(t, sqlStore)
|
|
||||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||||
|
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||||
for _, u := range tc.users {
|
for _, u := range tc.users {
|
||||||
cmd := user.CreateUserCommand{
|
u := user.User{
|
||||||
Email: u.Email,
|
Email: u.Email,
|
||||||
Name: u.Name,
|
Name: u.Name,
|
||||||
Login: u.Login,
|
Login: u.Login,
|
||||||
OrgID: int64(testOrgID),
|
OrgID: int64(testOrgID),
|
||||||
IsServiceAccount: u.IsServiceAccount,
|
IsServiceAccount: u.IsServiceAccount,
|
||||||
|
Created: time.Now(),
|
||||||
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
_, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
// call user store instead of user service so as not to prevent conflicting users
|
||||||
|
_, err := userStore.Insert(context.Background(), &u)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
m, err := GetUsersWithConflictingEmailsOrLogins(&cli.Context{Context: context.Background()}, sqlStore)
|
m, err := GetUsersWithConflictingEmailsOrLogins(&cli.Context{Context: context.Background()}, sqlStore)
|
||||||
@ -499,16 +509,19 @@ func TestGenerateConflictingUsersFile(t *testing.T) {
|
|||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
// Restore after destructive operation
|
// Restore after destructive operation
|
||||||
sqlStore := db.InitTestDB(t)
|
sqlStore := db.InitTestDB(t)
|
||||||
usrSvc := setupTestUserService(t, sqlStore)
|
|
||||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||||
|
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||||
for _, u := range tc.users {
|
for _, u := range tc.users {
|
||||||
cmd := user.CreateUserCommand{
|
cmd := user.User{
|
||||||
Email: u.Email,
|
Email: u.Email,
|
||||||
Name: u.Name,
|
Name: u.Name,
|
||||||
Login: u.Login,
|
Login: u.Login,
|
||||||
OrgID: int64(testOrgID),
|
OrgID: int64(testOrgID),
|
||||||
|
Created: time.Now(),
|
||||||
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
_, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
// call user store instead of user service so as not to prevent conflicting users
|
||||||
|
_, err := userStore.Insert(context.Background(), &cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
m, err := GetUsersWithConflictingEmailsOrLogins(&cli.Context{Context: context.Background()}, sqlStore)
|
m, err := GetUsersWithConflictingEmailsOrLogins(&cli.Context{Context: context.Background()}, sqlStore)
|
||||||
@ -756,16 +769,19 @@ conflict: test2
|
|||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
// Restore after destructive operation
|
// Restore after destructive operation
|
||||||
sqlStore := db.InitTestDB(t)
|
sqlStore := db.InitTestDB(t)
|
||||||
usrSvc := setupTestUserService(t, sqlStore)
|
|
||||||
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
if sqlStore.GetDialect().DriverName() != ignoredDatabase {
|
||||||
|
userStore := userimpl.ProvideStore(sqlStore, sqlStore.Cfg)
|
||||||
for _, u := range tc.users {
|
for _, u := range tc.users {
|
||||||
cmd := user.CreateUserCommand{
|
cmd := user.User{
|
||||||
Email: u.Email,
|
Email: u.Email,
|
||||||
Name: u.Name,
|
Name: u.Name,
|
||||||
Login: u.Login,
|
Login: u.Login,
|
||||||
OrgID: int64(testOrgID),
|
OrgID: int64(testOrgID),
|
||||||
|
Created: time.Now(),
|
||||||
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
_, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
// call user store instead of user service so as not to prevent conflicting users
|
||||||
|
_, err := userStore.Insert(context.Background(), &cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
// add additional user with conflicting login where DOMAIN is upper case
|
// add additional user with conflicting login where DOMAIN is upper case
|
||||||
|
@ -2,7 +2,9 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
var savedFolder, childDash *dashboards.Dashboard
|
var savedFolder, childDash *dashboards.Dashboard
|
||||||
var dashboardStore dashboards.Store
|
var dashboardStore dashboards.Store
|
||||||
|
|
||||||
setup := func(t *testing.T) {
|
setup := func(t *testing.T) int64 {
|
||||||
sqlStore = db.InitTestDB(t)
|
sqlStore = db.InitTestDB(t)
|
||||||
quotaService := quotatest.New(false, nil)
|
quotaService := quotatest.New(false, nil)
|
||||||
var err error
|
var err error
|
||||||
@ -38,12 +40,13 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
currentUser = createUser(t, sqlStore, "viewer", "Viewer", false)
|
currentUser = createUser(t, sqlStore, "viewer", "Viewer", false)
|
||||||
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
savedFolder = insertTestDashboard(t, dashboardStore, "1 test dash folder", 1, 0, true, "prod", "webapp")
|
||||||
childDash = insertTestDashboard(t, dashboardStore, "2 test dash", 1, savedFolder.ID, false, "prod", "webapp")
|
childDash = insertTestDashboard(t, dashboardStore, "2 test dash", 1, savedFolder.ID, false, "prod", "webapp")
|
||||||
|
return currentUser.OrgID
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Dashboard permission with userId and teamId set to 0", func(t *testing.T) {
|
t.Run("Dashboard permission with userId and teamId set to 0", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
err := updateDashboardACL(t, dashboardStore, savedFolder.ID, dashboards.DashboardACL{
|
err := updateDashboardACL(t, dashboardStore, savedFolder.ID, dashboards.DashboardACL{
|
||||||
OrgID: 1,
|
OrgID: orgID,
|
||||||
DashboardID: savedFolder.ID,
|
DashboardID: savedFolder.ID,
|
||||||
Permission: dashboards.PERMISSION_EDIT,
|
Permission: dashboards.PERMISSION_EDIT,
|
||||||
})
|
})
|
||||||
@ -51,8 +54,8 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Folder acl should include default acl", func(t *testing.T) {
|
t.Run("Folder acl should include default acl", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: orgID}
|
||||||
|
|
||||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -68,8 +71,8 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Dashboard acl should include acl for parent folder", func(t *testing.T) {
|
t.Run("Dashboard acl should include acl for parent folder", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: 1}
|
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: orgID}
|
||||||
|
|
||||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -85,11 +88,11 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Folder with removed default permissions returns no acl items", func(t *testing.T) {
|
t.Run("Folder with removed default permissions returns no acl items", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
err := dashboardStore.UpdateDashboardACL(context.Background(), savedFolder.ID, nil)
|
err := dashboardStore.UpdateDashboardACL(context.Background(), savedFolder.ID, nil)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: 1}
|
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: orgID}
|
||||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
@ -98,9 +101,9 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Given a dashboard folder and a user", func(t *testing.T) {
|
t.Run("Given a dashboard folder and a user", func(t *testing.T) {
|
||||||
t.Run("Given dashboard folder permission", func(t *testing.T) {
|
t.Run("Given dashboard folder permission", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
err := updateDashboardACL(t, dashboardStore, savedFolder.ID, dashboards.DashboardACL{
|
err := updateDashboardACL(t, dashboardStore, savedFolder.ID, dashboards.DashboardACL{
|
||||||
OrgID: 1,
|
OrgID: orgID,
|
||||||
UserID: currentUser.ID,
|
UserID: currentUser.ID,
|
||||||
DashboardID: savedFolder.ID,
|
DashboardID: savedFolder.ID,
|
||||||
Permission: dashboards.PERMISSION_EDIT,
|
Permission: dashboards.PERMISSION_EDIT,
|
||||||
@ -108,7 +111,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
t.Run("When reading dashboard acl should include acl for parent folder", func(t *testing.T) {
|
t.Run("When reading dashboard acl should include acl for parent folder", func(t *testing.T) {
|
||||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: 1}
|
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: orgID}
|
||||||
|
|
||||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -119,7 +122,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Given child dashboard permission", func(t *testing.T) {
|
t.Run("Given child dashboard permission", func(t *testing.T) {
|
||||||
err := updateDashboardACL(t, dashboardStore, childDash.ID, dashboards.DashboardACL{
|
err := updateDashboardACL(t, dashboardStore, childDash.ID, dashboards.DashboardACL{
|
||||||
OrgID: 1,
|
OrgID: orgID,
|
||||||
UserID: currentUser.ID,
|
UserID: currentUser.ID,
|
||||||
DashboardID: childDash.ID,
|
DashboardID: childDash.ID,
|
||||||
Permission: dashboards.PERMISSION_EDIT,
|
Permission: dashboards.PERMISSION_EDIT,
|
||||||
@ -127,7 +130,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
t.Run("When reading dashboard acl should include acl for parent folder and child", func(t *testing.T) {
|
t.Run("When reading dashboard acl should include acl for parent folder and child", func(t *testing.T) {
|
||||||
query := dashboards.GetDashboardACLInfoListQuery{OrgID: 1, DashboardID: childDash.ID}
|
query := dashboards.GetDashboardACLInfoListQuery{OrgID: orgID, DashboardID: childDash.ID}
|
||||||
|
|
||||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -142,7 +145,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Reading dashboard acl should include default acl for parent folder and the child acl", func(t *testing.T) {
|
t.Run("Reading dashboard acl should include default acl for parent folder and the child acl", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
err := updateDashboardACL(t, dashboardStore, childDash.ID, dashboards.DashboardACL{
|
err := updateDashboardACL(t, dashboardStore, childDash.ID, dashboards.DashboardACL{
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
UserID: currentUser.ID,
|
UserID: currentUser.ID,
|
||||||
@ -151,7 +154,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
query := dashboards.GetDashboardACLInfoListQuery{OrgID: 1, DashboardID: childDash.ID}
|
query := dashboards.GetDashboardACLInfoListQuery{OrgID: orgID, DashboardID: childDash.ID}
|
||||||
|
|
||||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -169,7 +172,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Add and delete dashboard permission", func(t *testing.T) {
|
t.Run("Add and delete dashboard permission", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
err := updateDashboardACL(t, dashboardStore, savedFolder.ID, dashboards.DashboardACL{
|
err := updateDashboardACL(t, dashboardStore, savedFolder.ID, dashboards.DashboardACL{
|
||||||
OrgID: 1,
|
OrgID: 1,
|
||||||
UserID: currentUser.ID,
|
UserID: currentUser.ID,
|
||||||
@ -178,7 +181,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
q1 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
q1 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: orgID}
|
||||||
q1Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
q1Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
@ -192,14 +195,14 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
err = updateDashboardACL(t, dashboardStore, savedFolder.ID)
|
err = updateDashboardACL(t, dashboardStore, savedFolder.ID)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
q3 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
q3 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: orgID}
|
||||||
q3Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
q3Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, 0, len(q3Result))
|
require.Equal(t, 0, len(q3Result))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should be able to add a user permission for a team", func(t *testing.T) {
|
t.Run("Should be able to add a user permission for a team", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
teamSvc := teamimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
teamSvc := teamimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
||||||
team1, err := teamSvc.CreateTeam("group1 name", "", 1)
|
team1, err := teamSvc.CreateTeam("group1 name", "", 1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -212,7 +215,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
q1 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
q1 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: orgID}
|
||||||
q1Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
q1Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, savedFolder.ID, q1Result[0].DashboardID)
|
require.Equal(t, savedFolder.ID, q1Result[0].DashboardID)
|
||||||
@ -221,7 +224,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should be able to update an existing permission for a team", func(t *testing.T) {
|
t.Run("Should be able to update an existing permission for a team", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
teamSvc := teamimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
teamSvc := teamimpl.ProvideService(sqlStore, sqlStore.Cfg)
|
||||||
team1, err := teamSvc.CreateTeam("group1 name", "", 1)
|
team1, err := teamSvc.CreateTeam("group1 name", "", 1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -233,7 +236,7 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
q3 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
q3 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: orgID}
|
||||||
q3Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
q3Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, 1, len(q3Result))
|
require.Equal(t, 1, len(q3Result))
|
||||||
@ -244,11 +247,11 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Default permissions for root folder dashboards", func(t *testing.T) {
|
t.Run("Default permissions for root folder dashboards", func(t *testing.T) {
|
||||||
setup(t)
|
orgID := setup(t)
|
||||||
var rootFolderId int64 = 0
|
var rootFolderId int64 = 0
|
||||||
//sqlStore := db.InitTestDB(t)
|
//sqlStore := db.InitTestDB(t)
|
||||||
|
|
||||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: rootFolderId, OrgID: 1}
|
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: rootFolderId, OrgID: orgID}
|
||||||
|
|
||||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -282,11 +285,15 @@ func createUser(t *testing.T, sqlStore *sqlstore.SQLStore, name string, role str
|
|||||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, qs, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
currentUserCmd := user.CreateUserCommand{Login: name, Email: name + "@test.com", Name: "a " + name, IsAdmin: isAdmin}
|
o, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: fmt.Sprintf("test org %d", time.Now().UnixNano())})
|
||||||
currentUser, err := usrSvc.CreateUserForTests(context.Background(), ¤tUserCmd)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
currentUserCmd := user.CreateUserCommand{Login: name, Email: name + "@test.com", Name: "a " + name, IsAdmin: isAdmin, OrgID: o.ID}
|
||||||
|
currentUser, err := usrSvc.Create(context.Background(), ¤tUserCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
orgs, err := orgService.GetUserOrgList(context.Background(), &org.GetUserOrgListQuery{UserID: currentUser.ID})
|
orgs, err := orgService.GetUserOrgList(context.Background(), &org.GetUserOrgListQuery{UserID: currentUser.ID})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, org.RoleType(role), orgs[0].Role)
|
require.Equal(t, org.RoleType(role), orgs[0].Role)
|
||||||
|
require.Equal(t, o.ID, orgs[0].OrgID)
|
||||||
return *currentUser
|
return *currentUser
|
||||||
}
|
}
|
||||||
|
@ -309,9 +309,9 @@ func TestIntegrationOrgUserDataAccess(t *testing.T) {
|
|||||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||||
ac1cmd := &user.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
ac1cmd := &user.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
||||||
ac2cmd := &user.CreateUserCommand{Login: "ac2", Email: "ac2@test.com", Name: "ac2 name", IsAdmin: true}
|
ac2cmd := &user.CreateUserCommand{Login: "ac2", Email: "ac2@test.com", Name: "ac2 name", IsAdmin: true}
|
||||||
ac1, err := usrSvc.CreateUserForTests(context.Background(), ac1cmd)
|
ac1, err := usrSvc.Create(context.Background(), ac1cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ac2, err := usrSvc.CreateUserForTests(context.Background(), ac2cmd)
|
ac2, err := usrSvc.Create(context.Background(), ac2cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cmd := org.AddOrgUserCommand{
|
cmd := org.AddOrgUserCommand{
|
||||||
OrgID: ac1.OrgID,
|
OrgID: ac1.OrgID,
|
||||||
@ -419,7 +419,7 @@ func TestIntegrationOrgUserDataAccess(t *testing.T) {
|
|||||||
ss.Cfg.AutoAssignOrgId = 1
|
ss.Cfg.AutoAssignOrgId = 1
|
||||||
ss.Cfg.AutoAssignOrgRole = "Viewer"
|
ss.Cfg.AutoAssignOrgRole = "Viewer"
|
||||||
|
|
||||||
_, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
orgSvc, usrSvc := createOrgAndUserSvc(t, ss, ss.Cfg)
|
||||||
|
|
||||||
testUser := &user.SignedInUser{
|
testUser := &user.SignedInUser{
|
||||||
Permissions: map[int64]map[string][]string{
|
Permissions: map[int64]map[string][]string{
|
||||||
@ -427,10 +427,14 @@ func TestIntegrationOrgUserDataAccess(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ac1cmd := &user.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||||
ac2cmd := &user.CreateUserCommand{Login: "ac2", Email: "ac2@test.com", Name: "ac2 name"}
|
require.NoError(t, err)
|
||||||
|
|
||||||
ac1, err := usrSvc.CreateUserForTests(context.Background(), ac1cmd)
|
ac1cmd := &user.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name", OrgID: o.ID}
|
||||||
|
ac2cmd := &user.CreateUserCommand{Login: "ac2", Email: "ac2@test.com", Name: "ac2 name", OrgID: o.ID}
|
||||||
|
|
||||||
|
ac1, err := usrSvc.Create(context.Background(), ac1cmd)
|
||||||
|
require.NoError(t, err)
|
||||||
testUser.OrgID = ac1.OrgID
|
testUser.OrgID = ac1.OrgID
|
||||||
require.Equal(t, int64(1), ac1.OrgID)
|
require.Equal(t, int64(1), ac1.OrgID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -479,16 +483,20 @@ func TestIntegrationSQLStore_AddOrgUser(t *testing.T) {
|
|||||||
dialect: store.GetDialect(),
|
dialect: store.GetDialect(),
|
||||||
cfg: setting.NewCfg(),
|
cfg: setting.NewCfg(),
|
||||||
}
|
}
|
||||||
_, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
orgSvc, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||||
|
|
||||||
|
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// create org and admin
|
// create org and admin
|
||||||
u, err := usrSvc.CreateUserForTests(context.Background(), &user.CreateUserCommand{
|
u, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
|
OrgID: o.ID,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// create a service account with no org
|
// create a service account with no org
|
||||||
sa, err := usrSvc.CreateUserForTests(context.Background(), &user.CreateUserCommand{
|
sa, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||||
Login: "sa-no-org",
|
Login: "sa-no-org",
|
||||||
IsServiceAccount: true,
|
IsServiceAccount: true,
|
||||||
SkipOrgSetup: true,
|
SkipOrgSetup: true,
|
||||||
@ -534,49 +542,6 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
|||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
tests := []struct {
|
|
||||||
desc string
|
|
||||||
query *org.SearchOrgUsersQuery
|
|
||||||
expectedNumUsers int
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
desc: "should return all users",
|
|
||||||
query: &org.SearchOrgUsersQuery{
|
|
||||||
OrgID: 1,
|
|
||||||
User: &user.SignedInUser{
|
|
||||||
OrgID: 1,
|
|
||||||
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {accesscontrol.ScopeUsersAll}}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedNumUsers: 10,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "should return no users",
|
|
||||||
query: &org.SearchOrgUsersQuery{
|
|
||||||
OrgID: 1,
|
|
||||||
User: &user.SignedInUser{
|
|
||||||
OrgID: 1,
|
|
||||||
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {""}}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedNumUsers: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "should return some users",
|
|
||||||
query: &org.SearchOrgUsersQuery{
|
|
||||||
OrgID: 1,
|
|
||||||
User: &user.SignedInUser{
|
|
||||||
OrgID: 1,
|
|
||||||
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {
|
|
||||||
"users:id:1",
|
|
||||||
"users:id:5",
|
|
||||||
"users:id:9",
|
|
||||||
}}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expectedNumUsers: 3,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
store := db.InitTestDB(t)
|
store := db.InitTestDB(t)
|
||||||
orgUserStore := sqlStore{
|
orgUserStore := sqlStore{
|
||||||
@ -589,7 +554,57 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
|||||||
orgUserStore.cfg.IsEnterprise = false
|
orgUserStore.cfg.IsEnterprise = false
|
||||||
}()
|
}()
|
||||||
store.Cfg = setting.NewCfg()
|
store.Cfg = setting.NewCfg()
|
||||||
seedOrgUsers(t, &orgUserStore, store, 10)
|
|
||||||
|
orgSvc, userSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||||
|
|
||||||
|
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
seedOrgUsers(t, &orgUserStore, store, 10, userSvc, o.ID)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
desc string
|
||||||
|
query *org.SearchOrgUsersQuery
|
||||||
|
expectedNumUsers int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "should return all users",
|
||||||
|
query: &org.SearchOrgUsersQuery{
|
||||||
|
OrgID: o.ID,
|
||||||
|
User: &user.SignedInUser{
|
||||||
|
OrgID: o.ID,
|
||||||
|
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {accesscontrol.ScopeUsersAll}}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedNumUsers: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "should return no users",
|
||||||
|
query: &org.SearchOrgUsersQuery{
|
||||||
|
OrgID: o.ID,
|
||||||
|
User: &user.SignedInUser{
|
||||||
|
OrgID: o.ID,
|
||||||
|
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {""}}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedNumUsers: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "should return some users",
|
||||||
|
query: &org.SearchOrgUsersQuery{
|
||||||
|
OrgID: o.ID,
|
||||||
|
User: &user.SignedInUser{
|
||||||
|
OrgID: o.ID,
|
||||||
|
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {
|
||||||
|
"users:id:1",
|
||||||
|
"users:id:5",
|
||||||
|
"users:id:9",
|
||||||
|
}}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedNumUsers: 3,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
@ -606,26 +621,27 @@ func TestIntegration_SQLStore_GetOrgUsers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func seedOrgUsers(t *testing.T, orgUserStore store, store *sqlstore.SQLStore, numUsers int) {
|
func seedOrgUsers(t *testing.T, orgUserStore store, store *sqlstore.SQLStore, numUsers int, usrSvc user.Service, orgID int64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
_, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
|
||||||
|
|
||||||
// Seed users
|
// Seed users
|
||||||
for i := 1; i <= numUsers; i++ {
|
for i := 1; i <= numUsers; i++ {
|
||||||
user, err := usrSvc.CreateUserForTests(context.Background(), &user.CreateUserCommand{
|
user, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||||
Login: fmt.Sprintf("user-%d", i),
|
Login: fmt.Sprintf("user-%d", i),
|
||||||
OrgID: 1,
|
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if i != 1 {
|
role := org.RoleViewer
|
||||||
err = orgUserStore.AddOrgUser(context.Background(), &org.AddOrgUserCommand{
|
if i == 1 {
|
||||||
Role: "Viewer",
|
role = org.RoleAdmin
|
||||||
OrgID: 1,
|
|
||||||
UserID: user.ID,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = orgUserStore.AddOrgUser(context.Background(), &org.AddOrgUserCommand{
|
||||||
|
Role: role,
|
||||||
|
OrgID: orgID,
|
||||||
|
UserID: user.ID,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,7 +679,7 @@ func TestIntegration_SQLStore_GetOrgUsers_PopulatesCorrectly(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
newUser, err := usrSvc.CreateUserForTests(context.Background(), &user.CreateUserCommand{
|
newUser, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||||
Login: "Viewer",
|
Login: "Viewer",
|
||||||
Email: "viewer@localhost",
|
Email: "viewer@localhost",
|
||||||
OrgID: id,
|
OrgID: id,
|
||||||
@ -708,6 +724,21 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
|||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("skipping integration test")
|
t.Skip("skipping integration test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store := db.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
||||||
|
orgUserStore := sqlStore{
|
||||||
|
db: store,
|
||||||
|
dialect: store.GetDialect(),
|
||||||
|
cfg: setting.NewCfg(),
|
||||||
|
}
|
||||||
|
// orgUserStore.cfg.Skip
|
||||||
|
orgSvc, userSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||||
|
|
||||||
|
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: "test org"})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
seedOrgUsers(t, &orgUserStore, store, 10, userSvc, o.ID)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
desc string
|
desc string
|
||||||
query *org.SearchOrgUsersQuery
|
query *org.SearchOrgUsersQuery
|
||||||
@ -716,9 +747,9 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "should return all users",
|
desc: "should return all users",
|
||||||
query: &org.SearchOrgUsersQuery{
|
query: &org.SearchOrgUsersQuery{
|
||||||
OrgID: 1,
|
OrgID: o.ID,
|
||||||
User: &user.SignedInUser{
|
User: &user.SignedInUser{
|
||||||
OrgID: 1,
|
OrgID: o.ID,
|
||||||
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {accesscontrol.ScopeUsersAll}}},
|
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {accesscontrol.ScopeUsersAll}}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -727,9 +758,9 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "should return no users",
|
desc: "should return no users",
|
||||||
query: &org.SearchOrgUsersQuery{
|
query: &org.SearchOrgUsersQuery{
|
||||||
OrgID: 1,
|
OrgID: o.ID,
|
||||||
User: &user.SignedInUser{
|
User: &user.SignedInUser{
|
||||||
OrgID: 1,
|
OrgID: o.ID,
|
||||||
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {""}}},
|
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {""}}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -738,9 +769,9 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
|||||||
{
|
{
|
||||||
desc: "should return some users",
|
desc: "should return some users",
|
||||||
query: &org.SearchOrgUsersQuery{
|
query: &org.SearchOrgUsersQuery{
|
||||||
OrgID: 1,
|
OrgID: o.ID,
|
||||||
User: &user.SignedInUser{
|
User: &user.SignedInUser{
|
||||||
OrgID: 1,
|
OrgID: o.ID,
|
||||||
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {
|
Permissions: map[int64]map[string][]string{1: {accesscontrol.ActionOrgUsersRead: {
|
||||||
"users:id:1",
|
"users:id:1",
|
||||||
"users:id:5",
|
"users:id:5",
|
||||||
@ -752,15 +783,6 @@ func TestIntegration_SQLStore_SearchOrgUsers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
store := db.InitTestDB(t, sqlstore.InitTestDBOpt{})
|
|
||||||
orgUserStore := sqlStore{
|
|
||||||
db: store,
|
|
||||||
dialect: store.GetDialect(),
|
|
||||||
cfg: setting.NewCfg(),
|
|
||||||
}
|
|
||||||
// orgUserStore.cfg.Skip
|
|
||||||
seedOrgUsers(t, &orgUserStore, store, 10)
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.desc, func(t *testing.T) {
|
t.Run(tt.desc, func(t *testing.T) {
|
||||||
result, err := orgUserStore.SearchOrgUsers(context.Background(), tt.query)
|
result, err := orgUserStore.SearchOrgUsers(context.Background(), tt.query)
|
||||||
@ -786,11 +808,15 @@ func TestIntegration_SQLStore_RemoveOrgUser(t *testing.T) {
|
|||||||
dialect: store.GetDialect(),
|
dialect: store.GetDialect(),
|
||||||
cfg: setting.NewCfg(),
|
cfg: setting.NewCfg(),
|
||||||
}
|
}
|
||||||
_, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
orgSvc, usrSvc := createOrgAndUserSvc(t, store, store.Cfg)
|
||||||
|
|
||||||
|
o, err := orgSvc.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: MainOrgName})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// create org and admin
|
// create org and admin
|
||||||
_, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
_, err = usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
OrgID: 1,
|
OrgID: o.ID,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ func createServiceAccountAdminToken(t *testing.T, name string, env *server.TestE
|
|||||||
Role: string(org.RoleAdmin),
|
Role: string(org.RoleAdmin),
|
||||||
Login: name,
|
Login: name,
|
||||||
IsServiceAccount: true,
|
IsServiceAccount: true,
|
||||||
OrgID: 1,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
keyGen, err := apikeygenprefix.New(saAPI.ServiceID)
|
keyGen, err := apikeygenprefix.New(saAPI.ServiceID)
|
||||||
|
@ -26,7 +26,6 @@ type TestUser struct {
|
|||||||
Role string
|
Role string
|
||||||
Login string
|
Login string
|
||||||
IsServiceAccount bool
|
IsServiceAccount bool
|
||||||
OrgID int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestApiKey struct {
|
type TestApiKey struct {
|
||||||
@ -50,12 +49,17 @@ func SetupUserServiceAccount(t *testing.T, sqlStore *sqlstore.SQLStore, testUser
|
|||||||
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u1, err := usrSvc.CreateUserForTests(context.Background(), &user.CreateUserCommand{
|
org, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{
|
||||||
|
Name: "test org",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
u1, err := usrSvc.Create(context.Background(), &user.CreateUserCommand{
|
||||||
Login: testUser.Login,
|
Login: testUser.Login,
|
||||||
IsServiceAccount: testUser.IsServiceAccount,
|
IsServiceAccount: testUser.IsServiceAccount,
|
||||||
DefaultOrgRole: role,
|
DefaultOrgRole: role,
|
||||||
Name: testUser.Name,
|
Name: testUser.Name,
|
||||||
OrgID: testUser.OrgID,
|
OrgID: org.ID,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return u1
|
return u1
|
||||||
|
@ -84,7 +84,7 @@ func populateDB(t *testing.T, sqlStore *sqlstore.SQLStore) {
|
|||||||
Login: fmt.Sprintf("user_test_%v_login", i),
|
Login: fmt.Sprintf("user_test_%v_login", i),
|
||||||
OrgName: fmt.Sprintf("Org #%v", i),
|
OrgName: fmt.Sprintf("Org #%v", i),
|
||||||
}
|
}
|
||||||
user, err := userSvc.CreateUserForTests(context.Background(), &cmd)
|
user, err := userSvc.Create(context.Background(), &cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
users[i] = *user
|
users[i] = *user
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) (string,
|
|||||||
Role: string(org.RoleAdmin),
|
Role: string(org.RoleAdmin),
|
||||||
Login: "grpc-server-sa",
|
Login: "grpc-server-sa",
|
||||||
IsServiceAccount: true,
|
IsServiceAccount: true,
|
||||||
OrgID: 1,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
keyGen, err := apikeygenprefix.New(saAPI.ServiceID)
|
keyGen, err := apikeygenprefix.New(saAPI.ServiceID)
|
||||||
|
@ -396,7 +396,7 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) {
|
|||||||
Login: fmt.Sprint("login-sa", 1),
|
Login: fmt.Sprint("login-sa", 1),
|
||||||
IsServiceAccount: true,
|
IsServiceAccount: true,
|
||||||
}
|
}
|
||||||
serviceAccount, err := userSvc.CreateUserForTests(context.Background(), &userCmd)
|
serviceAccount, err := userSvc.Create(context.Background(), &userCmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
groupId := team2.ID
|
groupId := team2.ID
|
||||||
|
@ -24,7 +24,4 @@ type Service interface {
|
|||||||
UpdatePermissions(context.Context, int64, bool) error
|
UpdatePermissions(context.Context, int64, bool) error
|
||||||
SetUserHelpFlag(context.Context, *SetUserHelpFlagCommand) error
|
SetUserHelpFlag(context.Context, *SetUserHelpFlagCommand) error
|
||||||
GetProfile(context.Context, *GetUserProfileQuery) (*UserProfileDTO, error)
|
GetProfile(context.Context, *GetUserProfileQuery) (*UserProfileDTO, error)
|
||||||
|
|
||||||
// TEST ONLY METHOD
|
|
||||||
CreateUserForTests(context.Context, *CreateUserCommand) (*User, error)
|
|
||||||
}
|
}
|
||||||
|
@ -809,7 +809,7 @@ func createFiveTestUsers(t *testing.T, svc user.Service, fn func(i int) *user.Cr
|
|||||||
users := make([]user.User, 5)
|
users := make([]user.User, 5)
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
cmd := fn(i)
|
cmd := fn(i)
|
||||||
user, err := svc.CreateUserForTests(context.Background(), cmd)
|
user, err := svc.Create(context.Background(), cmd)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
users[i] = *user
|
users[i] = *user
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -113,9 +112,9 @@ func (s *Service) Create(ctx context.Context, cmd *user.CreateUserCommand) (*use
|
|||||||
IsDisabled: cmd.IsDisabled,
|
IsDisabled: cmd.IsDisabled,
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
EmailVerified: cmd.EmailVerified,
|
EmailVerified: cmd.EmailVerified,
|
||||||
Created: time.Now(),
|
Created: timeNow(),
|
||||||
Updated: time.Now(),
|
Updated: timeNow(),
|
||||||
LastSeenAt: time.Now().AddDate(-10, 0, 0),
|
LastSeenAt: timeNow().AddDate(-10, 0, 0),
|
||||||
IsServiceAccount: cmd.IsServiceAccount,
|
IsServiceAccount: cmd.IsServiceAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,115 +361,6 @@ func readQuotaConfig(cfg *setting.Cfg) (*quota.Map, error) {
|
|||||||
return limits, nil
|
return limits, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUserForTests creates a test user and optionally an organization. Unlike
|
|
||||||
// Create, `cmd.SkipOrgSetup` toggles whether or not to create an org for the
|
|
||||||
// test user if there isn't already an existing org. This must only be used in tests.
|
|
||||||
func (s *Service) CreateUserForTests(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
|
||||||
var orgID int64 = -1
|
|
||||||
var err error
|
|
||||||
if !cmd.SkipOrgSetup {
|
|
||||||
orgID, err = s.getOrgIDForNewUser(ctx, cmd)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.Email == "" {
|
|
||||||
cmd.Email = cmd.Login
|
|
||||||
}
|
|
||||||
|
|
||||||
usr, err := s.GetByLogin(ctx, &user.GetUserByLoginQuery{LoginOrEmail: cmd.Login})
|
|
||||||
if err != nil && !errors.Is(err, user.ErrUserNotFound) {
|
|
||||||
return usr, err
|
|
||||||
} else if err == nil { // user exists
|
|
||||||
return usr, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// create user
|
|
||||||
usr = &user.User{
|
|
||||||
Email: cmd.Email,
|
|
||||||
Name: cmd.Name,
|
|
||||||
Login: cmd.Login,
|
|
||||||
Company: cmd.Company,
|
|
||||||
IsAdmin: cmd.IsAdmin,
|
|
||||||
IsDisabled: cmd.IsDisabled,
|
|
||||||
OrgID: orgID,
|
|
||||||
EmailVerified: cmd.EmailVerified,
|
|
||||||
Created: timeNow(),
|
|
||||||
Updated: timeNow(),
|
|
||||||
LastSeenAt: timeNow().AddDate(-10, 0, 0),
|
|
||||||
IsServiceAccount: cmd.IsServiceAccount,
|
|
||||||
}
|
|
||||||
|
|
||||||
salt, err := util.GetRandomString(10)
|
|
||||||
if err != nil {
|
|
||||||
return usr, err
|
|
||||||
}
|
|
||||||
usr.Salt = salt
|
|
||||||
rands, err := util.GetRandomString(10)
|
|
||||||
if err != nil {
|
|
||||||
return usr, err
|
|
||||||
}
|
|
||||||
usr.Rands = rands
|
|
||||||
|
|
||||||
if len(cmd.Password) > 0 {
|
|
||||||
encodedPassword, err := util.EncodePassword(cmd.Password, usr.Salt)
|
|
||||||
if err != nil {
|
|
||||||
return usr, err
|
|
||||||
}
|
|
||||||
usr.Password = encodedPassword
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = s.store.Insert(ctx, usr)
|
|
||||||
if err != nil {
|
|
||||||
return usr, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// create org user link
|
|
||||||
if !cmd.SkipOrgSetup {
|
|
||||||
orgCmd := &org.AddOrgUserCommand{
|
|
||||||
OrgID: orgID,
|
|
||||||
UserID: usr.ID,
|
|
||||||
Role: org.RoleAdmin,
|
|
||||||
AllowAddingServiceAccount: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.cfg.AutoAssignOrg && !usr.IsAdmin {
|
|
||||||
if len(cmd.DefaultOrgRole) > 0 {
|
|
||||||
orgCmd.Role = org.RoleType(cmd.DefaultOrgRole)
|
|
||||||
} else {
|
|
||||||
orgCmd.Role = org.RoleType(s.cfg.AutoAssignOrgRole)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = s.orgService.AddOrgUser(ctx, orgCmd); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return usr, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) getOrgIDForNewUser(ctx context.Context, cmd *user.CreateUserCommand) (int64, error) {
|
|
||||||
if s.cfg.AutoAssignOrg && cmd.OrgID != 0 {
|
|
||||||
if _, err := s.orgService.GetByID(ctx, &org.GetOrgByIDQuery{ID: cmd.OrgID}); err != nil {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
return cmd.OrgID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
orgName := cmd.OrgName
|
|
||||||
if orgName == "" {
|
|
||||||
orgName = util.StringsFallback2(cmd.Email, cmd.Login)
|
|
||||||
}
|
|
||||||
|
|
||||||
orgID, err := s.orgService.GetOrCreate(ctx, orgName)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return orgID, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateServiceAccount creates a service account in the user table and adds service account to an organisation in the org_user table
|
// CreateServiceAccount creates a service account in the user table and adds service account to an organisation in the org_user table
|
||||||
func (s *Service) CreateServiceAccount(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
func (s *Service) CreateServiceAccount(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
||||||
cmd.Email = cmd.Login
|
cmd.Email = cmd.Login
|
||||||
|
@ -34,10 +34,6 @@ func (f *FakeUserService) Create(ctx context.Context, cmd *user.CreateUserComman
|
|||||||
return f.ExpectedUser, f.ExpectedError
|
return f.ExpectedUser, f.ExpectedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeUserService) CreateUserForTests(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
|
||||||
return f.ExpectedUser, f.ExpectedError
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FakeUserService) CreateServiceAccount(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
func (f *FakeUserService) CreateServiceAccount(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
||||||
return f.ExpectedUser, f.ExpectedError
|
return f.ExpectedUser, f.ExpectedError
|
||||||
}
|
}
|
||||||
|
@ -2569,7 +2569,7 @@ func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserComma
|
|||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return u.ID
|
return u.ID
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,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()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -65,7 +65,7 @@ func TestIntegrationAzureMonitor(t *testing.T) {
|
|||||||
|
|
||||||
uid := "azuremonitor"
|
uid := "azuremonitor"
|
||||||
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "Azure Monitor",
|
Name: "Azure Monitor",
|
||||||
Type: datasources.DS_AZURE_MONITOR,
|
Type: datasources.DS_AZURE_MONITOR,
|
||||||
|
@ -145,7 +145,7 @@ func (c TestContext) createUser(cmd user.CreateUserCommand) User {
|
|||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
user, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
user, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
return User{
|
return User{
|
||||||
|
@ -114,7 +114,7 @@ func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserComma
|
|||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return u.ID
|
return u.ID
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,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()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -57,7 +57,7 @@ func TestIntegrationElasticsearch(t *testing.T) {
|
|||||||
|
|
||||||
uid := "es"
|
uid := "es"
|
||||||
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "Elasticsearch",
|
Name: "Elasticsearch",
|
||||||
Type: datasources.DS_ES,
|
Type: datasources.DS_ES,
|
||||||
|
@ -31,7 +31,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()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -55,7 +55,7 @@ func TestIntegrationGraphite(t *testing.T) {
|
|||||||
|
|
||||||
uid := "graphite"
|
uid := "graphite"
|
||||||
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "graphite",
|
Name: "graphite",
|
||||||
Type: datasources.DS_GRAPHITE,
|
Type: datasources.DS_GRAPHITE,
|
||||||
|
@ -31,7 +31,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()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -55,7 +55,7 @@ func TestIntegrationInflux(t *testing.T) {
|
|||||||
|
|
||||||
uid := "influxdb"
|
uid := "influxdb"
|
||||||
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "InfluxDB",
|
Name: "InfluxDB",
|
||||||
Type: datasources.DS_INFLUXDB,
|
Type: datasources.DS_INFLUXDB,
|
||||||
|
@ -31,7 +31,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()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -55,7 +55,7 @@ func TestIntegrationLoki(t *testing.T) {
|
|||||||
|
|
||||||
uid := "loki"
|
uid := "loki"
|
||||||
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "Loki",
|
Name: "Loki",
|
||||||
Type: datasources.DS_LOKI,
|
Type: datasources.DS_LOKI,
|
||||||
|
@ -31,7 +31,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()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -55,7 +55,7 @@ func TestIntegrationOpenTSDB(t *testing.T) {
|
|||||||
|
|
||||||
uid := "influxdb"
|
uid := "influxdb"
|
||||||
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "opentsdb",
|
Name: "opentsdb",
|
||||||
Type: datasources.DS_OPENTSDB,
|
Type: datasources.DS_OPENTSDB,
|
||||||
|
@ -129,7 +129,7 @@ func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserComma
|
|||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = usrSvc.CreateUserForTests(context.Background(), &cmd)
|
_, err = usrSvc.Create(context.Background(), &cmd)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ func newTestScenario(t *testing.T, name string, opts []testScenarioOption, callb
|
|||||||
tsCtx.testEnv = testEnv
|
tsCtx.testEnv = testEnv
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -284,7 +284,7 @@ func newTestScenario(t *testing.T, name string, opts []testScenarioOption, callb
|
|||||||
|
|
||||||
tsCtx.uid = "test-plugin"
|
tsCtx.uid = "test-plugin"
|
||||||
cmd := &datasources.AddDataSourceCommand{
|
cmd := &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "TestPlugin",
|
Name: "TestPlugin",
|
||||||
Type: tsCtx.testPluginID,
|
Type: tsCtx.testPluginID,
|
||||||
@ -306,7 +306,7 @@ func newTestScenario(t *testing.T, name string, opts []testScenarioOption, callb
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
getDataSourceQuery := &datasources.GetDataSourceQuery{
|
getDataSourceQuery := &datasources.GetDataSourceQuery{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
UID: tsCtx.uid,
|
UID: tsCtx.uid,
|
||||||
}
|
}
|
||||||
dataSource, err := testEnv.Server.HTTPServer.DataSourcesService.GetDataSource(ctx, getDataSourceQuery)
|
dataSource, err := testEnv.Server.HTTPServer.DataSourcesService.GetDataSource(ctx, getDataSourceQuery)
|
||||||
|
@ -31,7 +31,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()
|
||||||
|
|
||||||
testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
u := testinfra.CreateUser(t, testEnv.SQLStore, user.CreateUserCommand{
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: "admin",
|
Password: "admin",
|
||||||
Login: "admin",
|
Login: "admin",
|
||||||
@ -56,7 +56,7 @@ func TestIntegrationPrometheus(t *testing.T) {
|
|||||||
|
|
||||||
uid := "prometheus"
|
uid := "prometheus"
|
||||||
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
_, err := testEnv.Server.HTTPServer.DataSourcesService.AddDataSource(ctx, &datasources.AddDataSourceCommand{
|
||||||
OrgID: 1,
|
OrgID: u.OrgID,
|
||||||
Access: datasources.DS_ACCESS_PROXY,
|
Access: datasources.DS_ACCESS_PROXY,
|
||||||
Name: "Prometheus",
|
Name: "Prometheus",
|
||||||
Type: datasources.DS_PROMETHEUS,
|
Type: datasources.DS_PROMETHEUS,
|
||||||
|
@ -376,7 +376,7 @@ type GrafanaOpts struct {
|
|||||||
QueryRetries int64
|
QueryRetries int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) int64 {
|
func CreateUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) *user.User {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
store.Cfg.AutoAssignOrg = true
|
store.Cfg.AutoAssignOrg = true
|
||||||
@ -389,7 +389,12 @@ func CreateUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserComma
|
|||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
u, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
o, err := orgService.CreateWithMember(context.Background(), &org.CreateOrgCommand{Name: fmt.Sprintf("test org %d", time.Now().UnixNano())})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return u.ID
|
|
||||||
|
cmd.OrgID = o.ID
|
||||||
|
|
||||||
|
u, err := usrSvc.Create(context.Background(), &cmd)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return u
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user