From 49eac0e22bfb7132e03fbc9ae2663b3dffdc237c Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Tue, 12 Jun 2018 11:56:25 -0400 Subject: [PATCH 1/2] fixing default rotate statement for MSSQL --- plugins/database/mssql/mssql.go | 2 +- plugins/database/mssql/mssql_test.go | 38 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/plugins/database/mssql/mssql.go b/plugins/database/mssql/mssql.go index 9b0a78c0ae38..62b415af8bea 100644 --- a/plugins/database/mssql/mssql.go +++ b/plugins/database/mssql/mssql.go @@ -387,5 +387,5 @@ END ` const rotateRootCredentialsSQL = ` -ALTER LOGIN [%s] WITH PASSWORD = '%s' +ALTER LOGIN [{{username}}] WITH PASSWORD = '{{password}}' ` diff --git a/plugins/database/mssql/mssql_test.go b/plugins/database/mssql/mssql_test.go index f2ad54c993e6..2b7b224d9e64 100644 --- a/plugins/database/mssql/mssql_test.go +++ b/plugins/database/mssql/mssql_test.go @@ -95,6 +95,44 @@ func TestMSSQL_CreateUser(t *testing.T) { } } +func TestMSSQL_RotateRootCredentials(t *testing.T) { + // if os.Getenv("MSSQL_URL") == "" || os.Getenv("VAULT_ACC") != "1" { + // return + // } + connURL := os.Getenv("MSSQL_URL") + connectionDetails := map[string]interface{}{ + "connection_url": connURL, + "username": "sa", + "password": "yourStrong(!)Password", + } + + db := new() + + connProducer := db.SQLConnectionProducer + + _, err := db.Init(context.Background(), connectionDetails, true) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !connProducer.Initialized { + t.Fatal("Database should be initalized") + } + + newConf, err := db.RotateRootCredentials(context.Background(), nil) + if err != nil { + t.Fatalf("err: %v", err) + } + if newConf["password"] == "yourStrong(!)Password" { + t.Fatal("password was not updated") + } + + err = db.Close() + if err != nil { + t.Fatalf("err: %s", err) + } +} + func TestMSSQL_RevokeUser(t *testing.T) { if os.Getenv("MSSQL_URL") == "" || os.Getenv("VAULT_ACC") != "1" { return From a9b3f2d3f180d6ff79a957e3628bbc2abf75949f Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Tue, 12 Jun 2018 11:57:10 -0400 Subject: [PATCH 2/2] only run with ACC --- plugins/database/mssql/mssql_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/database/mssql/mssql_test.go b/plugins/database/mssql/mssql_test.go index 2b7b224d9e64..cea5430eedd8 100644 --- a/plugins/database/mssql/mssql_test.go +++ b/plugins/database/mssql/mssql_test.go @@ -96,9 +96,9 @@ func TestMSSQL_CreateUser(t *testing.T) { } func TestMSSQL_RotateRootCredentials(t *testing.T) { - // if os.Getenv("MSSQL_URL") == "" || os.Getenv("VAULT_ACC") != "1" { - // return - // } + if os.Getenv("MSSQL_URL") == "" || os.Getenv("VAULT_ACC") != "1" { + return + } connURL := os.Getenv("MSSQL_URL") connectionDetails := map[string]interface{}{ "connection_url": connURL,