grafana/pkg/services/secrets/test_helper.go
Tania B 62689ec804
Security: Add secrets service (#39418)
* Add secrets service

* Revert accidental changes in util encryption

* Make minor changes

Move functional options to models

Revert renaming types to models

* Add context

* Minor change in GetDataKey

* Use CreateDataKeyWithDBSession in CreateDataKey

* Handle empty DEK name in DeleteDataKey

* Rename defaultProvider

* Remove secrets store service
2021-10-01 15:39:57 +03:00

33 lines
746 B
Go

package secrets
import (
"testing"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/services/encryption/ossencryption"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/require"
"gopkg.in/ini.v1"
)
func SetupTestService(t *testing.T) SecretsService {
t.Helper()
defaultKey := "SdlklWklckeLS"
if len(setting.SecretKey) > 0 {
defaultKey = setting.SecretKey
}
raw, err := ini.Load([]byte(`
[security]
secret_key = ` + defaultKey))
require.NoError(t, err)
settings := &setting.OSSImpl{Cfg: &setting.Cfg{Raw: raw}}
return ProvideSecretsService(
sqlstore.InitTestDB(t),
bus.New(),
ossencryption.ProvideService(),
settings,
)
}