2017-08-03 17:24:27 +00:00
|
|
|
package etcd
|
2017-01-03 19:43:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2021-09-29 18:28:13 +00:00
|
|
|
"github.com/hashicorp/vault/helper/testhelpers/etcd"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/logging"
|
|
|
|
"github.com/hashicorp/vault/sdk/physical"
|
2017-01-03 19:43:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEtcd3Backend(t *testing.T) {
|
2021-09-29 18:28:13 +00:00
|
|
|
cleanup, config := etcd.PrepareTestContainer(t, "v3.5.0")
|
|
|
|
defer cleanup()
|
2017-01-03 19:43:46 +00:00
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
logger := logging.NewVaultLogger(log.Debug)
|
2021-09-29 18:28:13 +00:00
|
|
|
configMap := map[string]string{
|
|
|
|
"address": config.URL().String(),
|
2017-01-03 19:43:46 +00:00
|
|
|
"path": fmt.Sprintf("/vault-%d", time.Now().Unix()),
|
|
|
|
"etcd_api": "3",
|
2021-09-29 18:28:13 +00:00
|
|
|
"username": "root",
|
|
|
|
"password": "insecure",
|
|
|
|
|
|
|
|
// Syncing adverticed client urls should be disabled since docker port mapping confuses the client.
|
|
|
|
"sync": "false",
|
2018-11-01 17:31:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 18:28:13 +00:00
|
|
|
b, err := NewEtcdBackend(configMap, logger)
|
2018-11-01 17:31:09 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-09-29 18:28:13 +00:00
|
|
|
b2, err := NewEtcdBackend(configMap, logger)
|
2017-01-03 19:43:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2017-08-03 17:24:27 +00:00
|
|
|
physical.ExerciseBackend(t, b)
|
|
|
|
physical.ExerciseBackend_ListPrefix(t, b)
|
2018-11-01 17:31:09 +00:00
|
|
|
physical.ExerciseHABackend(t, b.(physical.HABackend), b2.(physical.HABackend))
|
2017-01-03 19:43:46 +00:00
|
|
|
}
|