Skip to content

Commit

Permalink
test: Fix stream tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym-tousek-keboola committed Dec 6, 2024
1 parent 73c48a2 commit 64bc260
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/pkg/service/stream/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/service/common/configpatch"
"github.com/keboola/keboola-as-code/internal/pkg/service/common/ptr"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/config"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/encryption"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/level"
local "github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/level/local/config"
Expand Down Expand Up @@ -302,7 +303,7 @@ storage:
expiration: 30m0s
encryption:
# Encryption provider. Validation rules: required,oneof=none native gcp aws azure
provider: native
provider: none
native:
# Secret key for local encryption. Do not use in production.
secretKey: '*****'
Expand All @@ -329,6 +330,7 @@ encryption:
cfg.Source.HTTP.PublicURL, _ = url.Parse("https://stream-in.keboola.local")
cfg.Etcd.Endpoint = "test-etcd"
cfg.Etcd.Namespace = "test-namespace"
cfg.Encryption.Provider = encryption.ProviderNative
cfg.Encryption.Native.SecretKey = []byte("12345678901234567890123456789012")
cfg.Encryption.Normalize()
require.NoError(t, validator.New().Validate(context.Background(), cfg))
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/service/stream/dependencies/mocked.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/service/common/configmap"
"github.com/keboola/keboola-as-code/internal/pkg/service/common/dependencies"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/config"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/encryption"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/test/dummy"
"github.com/keboola/keboola-as-code/internal/pkg/utils/netutils"
)
Expand Down Expand Up @@ -66,6 +67,7 @@ func testConfig(tb testing.TB, d dependencies.Mocked) config.Config {
secretKey := make([]byte, 32)
_, err := rand.Read(secretKey)
require.NoError(tb, err)
cfg.Encryption.Provider = encryption.ProviderNative
cfg.Encryption.Native.SecretKey = secretKey

// Validate configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bridge_test
import (
"bytes"
"context"
"crypto/rand"
"testing"
"time"

Expand All @@ -22,6 +23,7 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/config"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/definition/key"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/dependencies"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/encryption"
keboolasink "github.com/keboola/keboola-as-code/internal/pkg/service/stream/sink/type/tablesink/keboola"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/model/schema"
bridgeTest "github.com/keboola/keboola-as-code/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/test"
Expand All @@ -48,6 +50,9 @@ func TestBridge_MigrateTokens(t *testing.T) {
sourceKey := key.SourceKey{BranchKey: branchKey, SourceID: "my-source"}
sinkKey := key.SinkKey{SourceKey: sourceKey, SinkID: "my-sink"}
ignoredKeys := etcdhelper.WithIgnoredKeyPattern("^definition/|storage/file/all/|storage/slice/all/|storage/volume/")
secretKey := make([]byte, 32)
_, err := rand.Read(secretKey)
require.NoError(t, err)

// Get services
d, mocked := dependencies.NewMockedAPIScopeWithConfig(t, ctx, func(cfg *config.Config) {
Expand All @@ -64,6 +69,10 @@ func TestBridge_MigrateTokens(t *testing.T) {
SlicesCount: 100,
Expiration: duration.From(30 * time.Minute),
}
cfg.Encryption.Provider = encryption.ProviderNative
cfg.Encryption.Native = &encryption.NativeConfig{
SecretKey: secretKey,
}
}, deps.WithClock(clk))
client := mocked.TestEtcdClient()
defRepo := d.DefinitionRepository()
Expand Down
3 changes: 2 additions & 1 deletion test/stream/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package api
import (
"context"
"crypto/rand"
"encoding/base64"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestStreamApiE2E(t *testing.T) {
"STREAM_ETCD_USERNAME": etcdCfg.Username,
"STREAM_ETCD_PASSWORD": etcdCfg.Password,
"STREAM_ENCRYPTION_PROVIDER": "native",
"STREAM_ENCRYPTION_NATIVE_SECRET_KEY": string(secretKey),
"STREAM_ENCRYPTION_NATIVE_SECRET_KEY": base64.StdEncoding.EncodeToString(secretKey),
})

// Run the test
Expand Down
2 changes: 2 additions & 0 deletions test/stream/bridge/keboola/guest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/api"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/config"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/dependencies"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/encryption"
"github.com/keboola/keboola-as-code/internal/pkg/utils/errors"
"github.com/keboola/keboola-as-code/internal/pkg/utils/netutils"
)
Expand All @@ -33,6 +34,7 @@ func TestGuestUserWorkflow(t *testing.T) {
require.NoError(t, err)

modifyConfig := func(cfg *config.Config) {
cfg.Encryption.Provider = encryption.ProviderNative
cfg.Encryption.Native.SecretKey = secretKey
apiPort := netutils.FreePortForTest(t)
cfg.API.Listen = "0.0.0.0:" + strconv.FormatInt(int64(apiPort), 10)
Expand Down
2 changes: 2 additions & 0 deletions test/stream/bridge/keboola/keboola_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/encoding/json"
"github.com/keboola/keboola-as-code/internal/pkg/service/common/duration"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/config"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/encryption"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/level/local/diskwriter/network"
stagingConfig "github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/level/staging/config"
targetConfig "github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/level/target/config"
Expand All @@ -40,6 +41,7 @@ func TestKeboolaBridgeWorkflow(t *testing.T) {
// Update configuration to make the cluster testable
configFn := func(cfg *config.Config) {
// Setup encryption
cfg.Encryption.Provider = encryption.ProviderNative
cfg.Encryption.Native.SecretKey = secretKey
// Enable metadata cleanup for removing storage jobs
cfg.Storage.MetadataCleanup.Enabled = true
Expand Down

0 comments on commit 64bc260

Please sign in to comment.