ServiceAccounts: Don't create new orgs for service accounts (#51819)
* Org: use constants for status codes * ServiceAccounts: Avoid creating new orgs for service accounts * Document createUserBehavior * Update pkg/services/sqlstore/org_users_test.go * add doc string to flag
This commit is contained in:
@@ -13,12 +13,28 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestStore_CreateServiceAccount(t *testing.T) {
|
||||
// Service Account should not create an org on its own
|
||||
func TestStore_CreateServiceAccountOrgNonExistant(t *testing.T) {
|
||||
_, store := setupTestDatabase(t)
|
||||
t.Run("create service account", func(t *testing.T) {
|
||||
serviceAccountName := "new Service Account"
|
||||
serviceAccountOrgId := int64(1)
|
||||
|
||||
_, err := store.CreateServiceAccount(context.Background(), serviceAccountOrgId, serviceAccountName)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestStore_CreateServiceAccount(t *testing.T) {
|
||||
_, store := setupTestDatabase(t)
|
||||
orgQuery := &models.CreateOrgCommand{Name: sqlstore.MainOrgName}
|
||||
err := store.sqlStore.CreateOrg(context.Background(), orgQuery)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("create service account", func(t *testing.T) {
|
||||
serviceAccountName := "new Service Account"
|
||||
serviceAccountOrgId := orgQuery.Result.Id
|
||||
|
||||
saDTO, err := store.CreateServiceAccount(context.Background(), serviceAccountOrgId, serviceAccountName)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "sa-new-service-account", saDTO.Login)
|
||||
|
||||
Reference in New Issue
Block a user