From cbcb8635a474ba807cdabd61d521ad13cccb6450 Mon Sep 17 00:00:00 2001 From: Brian Kassouf Date: Wed, 3 May 2017 16:34:09 -0700 Subject: [PATCH] Update databse backend tests to use the APIClientMeta for the plugin conns --- builtin/logical/database/backend_test.go | 23 ++++++++++++++++--- .../logical/database/dbplugin/plugin_test.go | 9 ++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/builtin/logical/database/backend_test.go b/builtin/logical/database/backend_test.go index 70ec22ee2..27c20d332 100644 --- a/builtin/logical/database/backend_test.go +++ b/builtin/logical/database/backend_test.go @@ -3,6 +3,7 @@ package database import ( "database/sql" "fmt" + "io/ioutil" "log" stdhttp "net/http" "os" @@ -10,7 +11,6 @@ import ( "sync" "testing" - "github.com/hashicorp/vault/api" "github.com/hashicorp/vault/builtin/logical/database/dbplugin" "github.com/hashicorp/vault/helper/pluginutil" "github.com/hashicorp/vault/http" @@ -109,11 +109,28 @@ func TestBackend_PluginMain(t *testing.T) { return } - err := postgresql.Run(&api.TLSConfig{Insecure: true}) + content := []byte(vault.TestClusterCACert) + tmpfile, err := ioutil.TempFile("", "example") if err != nil { t.Fatal(err) } - t.Fatal("We shouldn't get here") + + defer os.Remove(tmpfile.Name()) // clean up + + if _, err := tmpfile.Write(content); err != nil { + t.Fatal(err) + } + if err := tmpfile.Close(); err != nil { + t.Fatal(err) + } + + args := []string{"--ca-cert=" + tmpfile.Name()} + + apiClientMeta := &pluginutil.APIClientMeta{} + flags := apiClientMeta.FlagSet() + flags.Parse(args) + + postgresql.Run(apiClientMeta.GetTLSConfig()) } func TestBackend_config_connection(t *testing.T) { diff --git a/builtin/logical/database/dbplugin/plugin_test.go b/builtin/logical/database/dbplugin/plugin_test.go index c38d85ed3..c95e119e0 100644 --- a/builtin/logical/database/dbplugin/plugin_test.go +++ b/builtin/logical/database/dbplugin/plugin_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - "github.com/hashicorp/vault/api" "github.com/hashicorp/vault/builtin/logical/database/dbplugin" "github.com/hashicorp/vault/helper/pluginutil" "github.com/hashicorp/vault/http" @@ -107,7 +106,13 @@ func TestPlugin_Main(t *testing.T) { users: make(map[string][]string), } - plugins.Serve(plugin, &api.TLSConfig{Insecure: true}) + args := []string{"--tls-skip-verify=true"} + + apiClientMeta := &pluginutil.APIClientMeta{} + flags := apiClientMeta.FlagSet() + flags.Parse(args) + + plugins.Serve(plugin, apiClientMeta.GetTLSConfig()) } func TestPlugin_Initialize(t *testing.T) {