Add the Loki query UI, access policies, ingress insights, alert and registry settings, and their backend APIs. Include the related Kubernetes deployment and collector updates required by the integrated application. Validated with go test ./..., npm run build, and npm run lint.
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package services
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"opsxloki/repository"
|
|
)
|
|
|
|
func TestStorageUpdateReplacesBothCredentials(t *testing.T) {
|
|
t.Setenv("DATA_DIR", t.TempDir())
|
|
t.Setenv("JWT_SECRET", "test-jwt-secret-with-at-least-32-characters")
|
|
t.Setenv("ENCRYPTION_KEY", "test-encryption-key-with-at-least-32-characters")
|
|
if err := repository.InitDB(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = repository.Shutdown() })
|
|
svc := NewStorageService()
|
|
storage, err := svc.Create("test", "minio", "http://localhost:9000", "loki", "", "old-access", "old-secret", "", true, true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := svc.Update(storage.ID, map[string]interface{}{"accessKey": "new-access", "secretKey": "new-secret"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
updated, err := svc.Get(storage.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
access, accessErr := DecryptCred(updated.AccessKey)
|
|
secret, secretErr := DecryptCred(updated.SecretKey)
|
|
if accessErr != nil || secretErr != nil || access != "new-access" || secret != "new-secret" {
|
|
t.Fatal("storage credentials were not both updated and decryptable")
|
|
}
|
|
}
|