2023-02-08 06:03:54 -05:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/kms/gcp"
|
2023-03-02 09:08:31 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/storage/gcs"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/storage/memfs"
|
2023-02-08 06:03:54 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/uri"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGCPKMS(t *testing.T) {
|
|
|
|
if !*runGcpKms {
|
|
|
|
t.Skip("Skipping Google KMS test")
|
|
|
|
}
|
|
|
|
if *gcpProjectID == "" || *gcpLocation == "" || *gcpKeyRing == "" || *kekID == "" {
|
|
|
|
flag.Usage()
|
|
|
|
t.Fatal("Required flags not set: --gcp-project, --gcp-location, --gcp-keyring, --kek-id")
|
|
|
|
}
|
|
|
|
require := require.New(t)
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
store := memfs.New()
|
2023-02-08 06:03:54 -05:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
cfg := uri.GCPConfig{
|
|
|
|
CredentialsPath: *gcpCredentialsPath,
|
|
|
|
ProjectID: *gcpProjectID,
|
|
|
|
Location: *gcpLocation,
|
|
|
|
KeyRing: *gcpKeyRing,
|
|
|
|
KeyName: *kekID,
|
|
|
|
}
|
|
|
|
kmsClient, err := gcp.New(ctx, store, cfg)
|
|
|
|
require.NoError(err)
|
|
|
|
defer kmsClient.Close()
|
|
|
|
|
|
|
|
runKMSTest(t, kmsClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGcpStorage(t *testing.T) {
|
|
|
|
if !*runGcpStorage {
|
|
|
|
t.Skip("Skipping Google Storage test")
|
|
|
|
}
|
2023-03-02 09:08:31 -05:00
|
|
|
if *gcpProjectID == "" || *gcpBucket == "" || *gcpCredentialsPath == "" {
|
2023-02-08 06:03:54 -05:00
|
|
|
flag.Usage()
|
|
|
|
t.Fatal("Required flags not set: --gcp-project, --gcp-bucket ")
|
|
|
|
}
|
2023-03-02 09:08:31 -05:00
|
|
|
require := require.New(t)
|
2023-02-08 06:03:54 -05:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
|
|
|
defer cancel()
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
cfg := uri.GoogleCloudStorageConfig{
|
|
|
|
CredentialsPath: *gcpCredentialsPath,
|
|
|
|
ProjectID: *gcpProjectID,
|
|
|
|
Bucket: *gcpBucket,
|
|
|
|
}
|
|
|
|
store, err := gcs.New(ctx, cfg)
|
|
|
|
require.NoError(err)
|
2023-02-08 06:03:54 -05:00
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
runStorageTest(t, store)
|
2023-02-08 06:03:54 -05:00
|
|
|
}
|