Skip to content

Commit

Permalink
Fix MSSQL Root Rotation Statement (#4748)
Browse files Browse the repository at this point in the history
* fixing default rotate statement for MSSQL

* only run with ACC
  • Loading branch information
chrishoffman authored Jun 12, 2018
1 parent 1b5b204 commit 2d132a1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/database/mssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,5 @@ END
`

const rotateRootCredentialsSQL = `
ALTER LOGIN [%s] WITH PASSWORD = '%s'
ALTER LOGIN [{{username}}] WITH PASSWORD = '{{password}}'
`
38 changes: 38 additions & 0 deletions plugins/database/mssql/mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d132a1

Please sign in to comment.