Skip to content

Commit 716ddc4

Browse files
committed
Explicit special character password tests
1 parent 3c947f2 commit 716ddc4

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

plugins/database/mysql/connection_producer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/hashicorp/vault/sdk/database/helper/connutil"
14-
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
15-
"github.com/hashicorp/vault/sdk/helper/parseutil"
16-
1713
"github.com/go-sql-driver/mysql"
1814
"github.com/hashicorp/errwrap"
1915
"github.com/hashicorp/go-uuid"
16+
"github.com/hashicorp/vault/sdk/database/helper/connutil"
17+
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
18+
"github.com/hashicorp/vault/sdk/helper/parseutil"
2019
"github.com/mitchellh/mapstructure"
2120
)
2221

@@ -108,6 +107,7 @@ func (c *mySQLConnectionProducer) Init(ctx context.Context, conf map[string]inte
108107
mysql.RegisterTLSConfig(c.tlsConfigName, tlsConfig)
109108
}
110109

110+
// Set initialized to true at this point since all fields are set,
111111
// and the connection can be established at a later time.
112112
c.Initialized = true
113113

plugins/database/mysql/mysql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
mySQLTypeName = "mysql"
2828

2929
DefaultUserNameTemplate = `{{ printf "v-%s-%s-%s-%s" (.DisplayName | truncate 10) (.RoleName | truncate 10) (random 20) (unix_time) | truncate 32 }}`
30-
DefaultLegacyUserNameTemplate = `{{ printf "v-%s-%s-%s" (.RoleName | truncate 4) (random 20) (unix_time) | truncate 16 }}`
30+
DefaultLegacyUserNameTemplate = `{{ printf "v-%s-%s-%s" (.RoleName | truncate 4) (random 20) | truncate 16 }}`
3131
)
3232

3333
var _ dbplugin.Database = (*MySQL)(nil)

plugins/database/mysql/mysql_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
stdmysql "github.com/go-sql-driver/mysql"
1212
mysqlhelper "github.com/hashicorp/vault/helper/testhelpers/mysql"
1313
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
14+
dbtesting "github.com/hashicorp/vault/sdk/database/dbplugin/v5/testing"
1415
"github.com/hashicorp/vault/sdk/database/helper/credsutil"
1516
"github.com/hashicorp/vault/sdk/database/helper/dbutil"
1617
"github.com/hashicorp/vault/sdk/helper/strutil"
@@ -20,7 +21,27 @@ import (
2021
var _ dbplugin.Database = (*MySQL)(nil)
2122

2223
func TestMySQL_Initialize(t *testing.T) {
23-
rootPassword := "#secret!%25#{@}"
24+
type testCase struct {
25+
rootPassword string
26+
}
27+
28+
tests := map[string]testCase{
29+
"non-special characters in root password": {
30+
rootPassword: "B44a30c4C04D0aAaE140",
31+
},
32+
"special characters in root password": {
33+
rootPassword: "#secret!%25#{@}",
34+
},
35+
}
36+
37+
for name, test := range tests {
38+
t.Run(name, func(t *testing.T) {
39+
testInitialize(t, test.rootPassword)
40+
})
41+
}
42+
}
43+
44+
func testInitialize(t *testing.T, rootPassword string) {
2445
cleanup, connURL := mysqlhelper.PrepareTestContainer(t, false, rootPassword)
2546
defer cleanup()
2647

@@ -131,7 +152,7 @@ func TestMySQL_Initialize(t *testing.T) {
131152
for name, test := range tests {
132153
t.Run(name, func(t *testing.T) {
133154
db := newMySQL(DefaultUserNameTemplate)
134-
defer db.Close()
155+
defer dbtesting.AssertClose(t, db)
135156
initResp, err := db.Initialize(context.Background(), test.initRequest)
136157
if test.expectErr && err == nil {
137158
t.Fatalf("err expected, got nil")

0 commit comments

Comments
 (0)