open-vault/vault/seal/azurekeyvault/azurekeyvault_acc_test.go

64 lines
1.3 KiB
Go

package azurekeyvault
import (
"context"
"os"
"reflect"
"testing"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/sdk/helper/logging"
)
func TestAzureKeyVault_SetConfig(t *testing.T) {
if os.Getenv("VAULT_ACC") == "" {
t.SkipNow()
}
seal := NewSeal(logging.NewVaultLogger(log.Trace))
tenantID := os.Getenv("AZURE_TENANT_ID")
os.Unsetenv("AZURE_TENANT_ID")
// Attempt to set config, expect failure due to missing config
_, err := seal.SetConfig(nil)
if err == nil {
t.Fatal("expected error when Azure Key Vault config values are not provided")
}
os.Setenv("AZURE_TENANT_ID", tenantID)
_, err = seal.SetConfig(nil)
if err != nil {
t.Fatal(err)
}
}
func TestAzureKeyVault_Lifecycle(t *testing.T) {
if os.Getenv("VAULT_ACC") == "" {
t.SkipNow()
}
s := NewSeal(logging.NewVaultLogger(log.Trace))
_, err := s.SetConfig(nil)
if err != nil {
t.Fatalf("err: %s", err.Error())
}
// Test Encrypt and Decrypt calls
input := []byte("foo")
swi, err := s.Encrypt(context.Background(), input)
if err != nil {
t.Fatalf("err: %s", err.Error())
}
pt, err := s.Decrypt(context.Background(), swi)
if err != nil {
t.Fatalf("err: %s", err.Error())
}
if !reflect.DeepEqual(input, pt) {
t.Fatalf("expected %s, got %s", input, pt)
}
}