[QT-309] Ensure creds are available for OCI and S3 (#18602)

* Ensure OCI creds are set for acc test

* Ensure AWS creds are resolvable before testing

Co-authored-by: Michael Anthony <5498095+manthonygfp@users.noreply.github.com>
This commit is contained in:
Mike Palmiotto 2023-01-17 14:15:40 -05:00 committed by GitHub
parent 19b863404c
commit 41f8d2edc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View File

@ -16,6 +16,11 @@ func TestOCIHABackend(t *testing.T) {
if os.Getenv("VAULT_ACC") == "" {
t.SkipNow()
}
if !hasOCICredentials() {
t.Skip("Skipping because OCI credentials could not be resolved. See https://pkg.go.dev/github.com/oracle/oci-go-sdk/common#DefaultConfigProvider for information on how to set up OCI credentials.")
}
bucketName, _ := uuid.GenerateUUID()
configProvider := common.DefaultConfigProvider()
objectStorageClient, _ := objectstorage.NewObjectStorageClientWithConfigurationProvider(configProvider)

View File

@ -19,6 +19,11 @@ func TestOCIBackend(t *testing.T) {
if os.Getenv("VAULT_ACC") == "" {
t.SkipNow()
}
if !hasOCICredentials() {
t.Skip("Skipping because OCI credentials could not be resolved. See https://pkg.go.dev/github.com/oracle/oci-go-sdk/common#DefaultConfigProvider for information on how to set up OCI credentials.")
}
bucketName, _ := uuid.GenerateUUID()
configProvider := common.DefaultConfigProvider()
objectStorageClient, _ := objectstorage.NewObjectStorageClientWithConfigurationProvider(configProvider)
@ -87,3 +92,14 @@ func getNamespaceName(objectStorageClient objectstorage.ObjectStorageClient, t *
nameSpaceName := *response.Value
return nameSpaceName
}
func hasOCICredentials() bool {
configProvider := common.DefaultConfigProvider()
_, err := configProvider.KeyID()
if err != nil {
return false
}
return true
}

View File

@ -1,12 +1,14 @@
package s3
import (
"context"
"fmt"
"math/rand"
"os"
"testing"
"time"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
@ -29,6 +31,10 @@ func DoS3BackendTest(t *testing.T, kmsKeyId string) {
t.Skip()
}
if !hasAWSCredentials() {
t.Skip("Skipping because AWS credentials could not be resolved. See https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials for information on how to set up AWS credentials.")
}
logger := logging.NewVaultLogger(log.Debug)
credsConfig := &awsutil.CredentialsConfig{Logger: logger}
@ -109,3 +115,20 @@ func DoS3BackendTest(t *testing.T, kmsKeyId string) {
physical.ExerciseBackend(t, b)
physical.ExerciseBackend_ListPrefix(t, b)
}
func hasAWSCredentials() bool {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
return false
}
creds, err := cfg.Credentials.Retrieve(ctx)
if err != nil {
return false
}
return creds.HasKeys()
}