2017-04-13 20:48:32 +00:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
2017-12-14 22:03:11 +00:00
|
|
|
"context"
|
2017-04-13 20:48:32 +00:00
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-07-05 18:52:56 +00:00
|
|
|
stdmysql "github.com/go-sql-driver/mysql"
|
2019-04-22 16:26:10 +00:00
|
|
|
"github.com/hashicorp/vault/helper/testhelpers/docker"
|
2019-04-15 18:10:07 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/database/dbplugin"
|
2019-04-22 16:26:10 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/database/helper/credsutil"
|
2019-07-05 18:52:56 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
|
|
|
|
"github.com/hashicorp/vault/sdk/helper/strutil"
|
2018-07-11 21:49:13 +00:00
|
|
|
"github.com/ory/dockertest"
|
2017-04-13 20:48:32 +00:00
|
|
|
)
|
|
|
|
|
2019-07-05 18:52:56 +00:00
|
|
|
var _ dbplugin.Database = (*MySQL)(nil)
|
|
|
|
|
2018-04-23 17:03:02 +00:00
|
|
|
func prepareMySQLTestContainer(t *testing.T, legacy bool) (cleanup func(), retURL string) {
|
2017-04-13 20:48:32 +00:00
|
|
|
if os.Getenv("MYSQL_URL") != "" {
|
|
|
|
return func() {}, os.Getenv("MYSQL_URL")
|
|
|
|
}
|
|
|
|
|
|
|
|
pool, err := dockertest.NewPool("")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to connect to docker: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-04-23 17:03:02 +00:00
|
|
|
imageVersion := "5.7"
|
|
|
|
if legacy {
|
|
|
|
imageVersion = "5.6"
|
2017-08-11 01:28:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 17:03:02 +00:00
|
|
|
resource, err := pool.Run("mysql", imageVersion, []string{"MYSQL_ROOT_PASSWORD=secret"})
|
2017-08-11 01:28:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not start local MySQL docker container: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup = func() {
|
2019-04-22 16:26:10 +00:00
|
|
|
docker.CleanupResource(t, pool, resource)
|
2017-08-11 01:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retURL = fmt.Sprintf("root:secret@(localhost:%s)/mysql?parseTime=true", resource.GetPort("3306/tcp"))
|
|
|
|
|
|
|
|
// exponential backoff-retry
|
|
|
|
if err = pool.Retry(func() error {
|
|
|
|
var err error
|
|
|
|
var db *sql.DB
|
|
|
|
db, err = sql.Open("mysql", retURL)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-26 15:28:58 +00:00
|
|
|
defer db.Close()
|
2017-08-11 01:28:18 +00:00
|
|
|
return db.Ping()
|
|
|
|
}); err != nil {
|
2018-04-23 17:03:02 +00:00
|
|
|
cleanup()
|
2017-08-11 01:28:18 +00:00
|
|
|
t.Fatalf("Could not connect to MySQL docker container: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-04-13 20:48:32 +00:00
|
|
|
func TestMySQL_Initialize(t *testing.T) {
|
2018-04-23 17:03:02 +00:00
|
|
|
cleanup, connURL := prepareMySQLTestContainer(t, false)
|
2017-04-13 20:48:32 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
connectionDetails := map[string]interface{}{
|
|
|
|
"connection_url": connURL,
|
|
|
|
}
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
db := new(MetadataLen, MetadataLen, UsernameLen)
|
|
|
|
_, err := db.Init(context.Background(), connectionDetails, true)
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
if !db.Initialized {
|
2019-03-19 13:32:45 +00:00
|
|
|
t.Fatal("Database should be initialized")
|
2017-04-13 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = db.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2017-06-15 01:59:27 +00:00
|
|
|
|
|
|
|
// Test decoding a string value for max_open_connections
|
|
|
|
connectionDetails = map[string]interface{}{
|
|
|
|
"connection_url": connURL,
|
|
|
|
"max_open_connections": "5",
|
|
|
|
}
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
_, err = db.Init(context.Background(), connectionDetails, true)
|
2017-06-15 01:59:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2017-04-13 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMySQL_CreateUser(t *testing.T) {
|
2018-04-23 17:03:02 +00:00
|
|
|
cleanup, connURL := prepareMySQLTestContainer(t, false)
|
2017-04-13 20:48:32 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
connectionDetails := map[string]interface{}{
|
|
|
|
"connection_url": connURL,
|
|
|
|
}
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
db := new(MetadataLen, MetadataLen, UsernameLen)
|
|
|
|
_, err := db.Init(context.Background(), connectionDetails, true)
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2017-06-06 13:49:49 +00:00
|
|
|
usernameConfig := dbplugin.UsernameConfig{
|
2017-08-11 01:28:18 +00:00
|
|
|
DisplayName: "test-long-displayname",
|
|
|
|
RoleName: "test-long-rolename",
|
2017-06-06 13:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
// Test with no configured Creation Statement
|
2017-12-14 22:03:11 +00:00
|
|
|
_, _, err = db.CreateUser(context.Background(), dbplugin.Statements{}, usernameConfig, time.Now().Add(time.Minute))
|
2017-04-13 20:48:32 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error when no creation statement is provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
statements := dbplugin.Statements{
|
2018-03-21 19:05:56 +00:00
|
|
|
Creation: []string{testMySQLRoleWildCard},
|
2017-04-13 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 22:03:11 +00:00
|
|
|
username, password, err := db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
2017-08-11 01:28:18 +00:00
|
|
|
|
|
|
|
// Test a second time to make sure usernames don't collide
|
2017-12-14 22:03:11 +00:00
|
|
|
username, password, err = db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
|
2017-08-11 01:28:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
2017-11-28 18:19:49 +00:00
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
// Test with a manually prepare statement
|
2018-03-21 19:05:56 +00:00
|
|
|
statements.Creation = []string{testMySQLRolePreparedStmt}
|
2017-11-28 18:19:49 +00:00
|
|
|
|
2017-12-14 22:03:11 +00:00
|
|
|
username, password, err = db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
|
2017-11-28 18:19:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
|
|
|
|
2017-08-11 01:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMySQL_CreateUser_Legacy(t *testing.T) {
|
2018-04-23 17:03:02 +00:00
|
|
|
cleanup, connURL := prepareMySQLTestContainer(t, true)
|
2017-08-11 01:28:18 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
connectionDetails := map[string]interface{}{
|
|
|
|
"connection_url": connURL,
|
|
|
|
}
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
db := new(credsutil.NoneLength, LegacyMetadataLen, LegacyUsernameLen)
|
|
|
|
_, err := db.Init(context.Background(), connectionDetails, true)
|
2017-08-11 01:28:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
usernameConfig := dbplugin.UsernameConfig{
|
|
|
|
DisplayName: "test-long-displayname",
|
|
|
|
RoleName: "test-long-rolename",
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
// Test with no configured Creation Statement
|
2017-12-14 22:03:11 +00:00
|
|
|
_, _, err = db.CreateUser(context.Background(), dbplugin.Statements{}, usernameConfig, time.Now().Add(time.Minute))
|
2017-08-11 01:28:18 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected error when no creation statement is provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
statements := dbplugin.Statements{
|
2018-03-21 19:05:56 +00:00
|
|
|
Creation: []string{testMySQLRoleWildCard},
|
2017-08-11 01:28:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 22:03:11 +00:00
|
|
|
username, password, err := db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
|
2017-08-11 01:28:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a second time to make sure usernames don't collide
|
2017-12-14 22:03:11 +00:00
|
|
|
username, password, err = db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
|
2017-08-11 01:28:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
2017-04-13 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
func TestMySQL_RotateRootCredentials(t *testing.T) {
|
2018-04-23 17:03:02 +00:00
|
|
|
cleanup, connURL := prepareMySQLTestContainer(t, false)
|
2017-04-13 20:48:32 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
connURL = strings.Replace(connURL, "root:secret", `{{username}}:{{password}}`, -1)
|
|
|
|
|
2017-04-13 20:48:32 +00:00
|
|
|
connectionDetails := map[string]interface{}{
|
|
|
|
"connection_url": connURL,
|
2018-03-21 19:05:56 +00:00
|
|
|
"username": "root",
|
|
|
|
"password": "secret",
|
|
|
|
}
|
|
|
|
|
|
|
|
db := new(MetadataLen, MetadataLen, UsernameLen)
|
|
|
|
_, err := db.Init(context.Background(), connectionDetails, true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !db.Initialized {
|
2019-03-19 13:32:45 +00:00
|
|
|
t.Fatal("Database should be initialized")
|
2018-03-21 19:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newConf, err := db.RotateRootCredentials(context.Background(), nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if newConf["password"] == "secret" {
|
|
|
|
t.Fatal("password was not updated")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
2017-04-13 20:48:32 +00:00
|
|
|
}
|
2018-03-21 19:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMySQL_RevokeUser(t *testing.T) {
|
2018-04-23 17:03:02 +00:00
|
|
|
cleanup, connURL := prepareMySQLTestContainer(t, false)
|
2018-03-21 19:05:56 +00:00
|
|
|
defer cleanup()
|
2017-04-13 20:48:32 +00:00
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
connectionDetails := map[string]interface{}{
|
|
|
|
"connection_url": connURL,
|
|
|
|
}
|
2017-04-13 20:48:32 +00:00
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
db := new(MetadataLen, MetadataLen, UsernameLen)
|
|
|
|
_, err := db.Init(context.Background(), connectionDetails, true)
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
statements := dbplugin.Statements{
|
2018-03-21 19:05:56 +00:00
|
|
|
Creation: []string{testMySQLRoleWildCard},
|
2017-04-13 20:48:32 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 13:49:49 +00:00
|
|
|
usernameConfig := dbplugin.UsernameConfig{
|
|
|
|
DisplayName: "test",
|
|
|
|
RoleName: "test",
|
|
|
|
}
|
|
|
|
|
2017-12-14 22:03:11 +00:00
|
|
|
username, password, err := db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
// Test default revoke statements
|
2017-12-14 22:03:11 +00:00
|
|
|
err = db.RevokeUser(context.Background(), statements, username)
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err == nil {
|
|
|
|
t.Fatal("Credentials were not revoked")
|
|
|
|
}
|
|
|
|
|
2018-03-21 19:05:56 +00:00
|
|
|
statements.Creation = []string{testMySQLRoleWildCard}
|
2017-12-14 22:03:11 +00:00
|
|
|
username, password, err = db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test custom revoke statements
|
2018-03-21 19:05:56 +00:00
|
|
|
statements.Revocation = []string{testMySQLRevocationSQL}
|
2017-12-14 22:03:11 +00:00
|
|
|
err = db.RevokeUser(context.Background(), statements, username)
|
2017-04-13 20:48:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, username, password); err == nil {
|
|
|
|
t.Fatal("Credentials were not revoked")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-05 18:52:56 +00:00
|
|
|
func TestMySQL_SetCredentials(t *testing.T) {
|
|
|
|
cleanup, connURL := prepareMySQLTestContainer(t, false)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
// create the database user and verify we can access
|
|
|
|
dbUser := "vaultstatictest"
|
|
|
|
createTestMySQLUser(t, connURL, dbUser, "password", testRoleStaticCreate)
|
|
|
|
if err := testCredsExist(t, connURL, dbUser, "password"); err != nil {
|
|
|
|
t.Fatalf("Could not connect with credentials: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
connectionDetails := map[string]interface{}{
|
|
|
|
"connection_url": connURL,
|
|
|
|
}
|
|
|
|
|
|
|
|
db := new(MetadataLen, MetadataLen, UsernameLen)
|
|
|
|
_, err := db.Init(context.Background(), connectionDetails, true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
newPassword, err := db.GenerateCredentials(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
userConfig := dbplugin.StaticUserConfig{
|
|
|
|
Username: dbUser,
|
|
|
|
Password: newPassword,
|
|
|
|
}
|
|
|
|
|
|
|
|
statements := dbplugin.Statements{
|
|
|
|
Rotation: []string{testRoleStaticRotate},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = db.SetCredentials(context.Background(), statements, userConfig)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify new password works
|
|
|
|
if err := testCredsExist(t, connURL, dbUser, newPassword); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// call SetCredentials again, password will change
|
|
|
|
newPassword, _ = db.GenerateCredentials(context.Background())
|
|
|
|
userConfig.Password = newPassword
|
|
|
|
_, _, err = db.SetCredentials(context.Background(), statements, userConfig)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := testCredsExist(t, connURL, dbUser, newPassword); err != nil {
|
|
|
|
t.Fatalf("Could not connect with new credentials: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-13 20:48:32 +00:00
|
|
|
func testCredsExist(t testing.TB, connURL, username, password string) error {
|
|
|
|
// Log in with the new creds
|
|
|
|
connURL = strings.Replace(connURL, "root:secret", fmt.Sprintf("%s:%s", username, password), 1)
|
|
|
|
db, err := sql.Open("mysql", connURL)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
return db.Ping()
|
|
|
|
}
|
|
|
|
|
2019-07-05 18:52:56 +00:00
|
|
|
func createTestMySQLUser(t *testing.T, connURL, username, password, query string) {
|
|
|
|
t.Helper()
|
|
|
|
db, err := sql.Open("mysql", connURL)
|
|
|
|
defer db.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a transaction
|
|
|
|
ctx := context.Background()
|
|
|
|
tx, err := db.BeginTx(ctx, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
_ = tx.Rollback()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// copied from mysql.go
|
|
|
|
for _, query := range strutil.ParseArbitraryStringSlice(query, ";") {
|
|
|
|
query = strings.TrimSpace(query)
|
|
|
|
if len(query) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
query = dbutil.QueryHelper(query, map[string]string{
|
|
|
|
"name": username,
|
|
|
|
"password": password,
|
|
|
|
})
|
|
|
|
|
|
|
|
stmt, err := tx.PrepareContext(ctx, query)
|
|
|
|
if err != nil {
|
|
|
|
if e, ok := err.(*stdmysql.MySQLError); ok && e.Number == 1295 {
|
|
|
|
_, err = tx.ExecContext(ctx, query)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
stmt.Close()
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if _, err := stmt.ExecContext(ctx); err != nil {
|
|
|
|
stmt.Close()
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
stmt.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-28 18:19:49 +00:00
|
|
|
const testMySQLRolePreparedStmt = `
|
|
|
|
CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';
|
|
|
|
set @grants=CONCAT("GRANT SELECT ON ", "*", ".* TO '{{name}}'@'%'");
|
|
|
|
PREPARE grantStmt from @grants;
|
|
|
|
EXECUTE grantStmt;
|
|
|
|
DEALLOCATE PREPARE grantStmt;
|
|
|
|
`
|
2017-04-13 20:48:32 +00:00
|
|
|
const testMySQLRoleWildCard = `
|
|
|
|
CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';
|
|
|
|
GRANT SELECT ON *.* TO '{{name}}'@'%';
|
|
|
|
`
|
|
|
|
const testMySQLRevocationSQL = `
|
|
|
|
REVOKE ALL PRIVILEGES, GRANT OPTION FROM '{{name}}'@'%';
|
|
|
|
DROP USER '{{name}}'@'%';
|
|
|
|
`
|
2019-07-05 18:52:56 +00:00
|
|
|
|
|
|
|
const testRoleStaticCreate = `
|
|
|
|
CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';
|
|
|
|
GRANT SELECT ON *.* TO '{{name}}'@'%';
|
|
|
|
`
|
|
|
|
|
|
|
|
const testRoleStaticRotate = `
|
|
|
|
ALTER USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';
|
|
|
|
`
|