Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mysql/awsmysql/awsmysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (uo *URLOpener) OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB, err
if err != nil {
return nil, err
}
cfg.AllowCleartextPasswords = true
c := &connector{
cfg: cfg,
iam: iam,
Expand Down
4 changes: 3 additions & 1 deletion mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func ConfigFromURL(u *url.URL) (cfg *mysql.Config, err error) {
cfg.User = u.User.Username()
cfg.Passwd, _ = u.User.Password()
cfg.DBName = dbName
cfg.AllowCleartextPasswords = true
if _, ok := u.Query()["allowCleartextPasswords"]; !ok {
cfg.AllowCleartextPasswords = true
}
cfg.AllowNativePasswords = true
return cfg, nil
}
Expand Down
38 changes: 38 additions & 0 deletions mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,41 @@ func TestConfigFromURL(t *testing.T) {
}
}
}

func TestConfigFromURLCleartextPasswords(t *testing.T) {
for _, tc := range []struct {
name string
url string
want bool
}{
{
name: "default",
url: "mysql://user:password@localhost/db",
want: true,
},
{
name: "explicit false",
url: "mysql://user:password@localhost/db?allowCleartextPasswords=false",
want: false,
},
{
name: "explicit true",
url: "mysql://user:password@localhost/db?allowCleartextPasswords=true",
want: true,
},
} {
t.Run(tc.name, func(t *testing.T) {
u, err := url.Parse(tc.url)
if err != nil {
t.Fatal(err)
}
cfg, err := ConfigFromURL(u)
if err != nil {
t.Fatal(err)
}
if got := cfg.AllowCleartextPasswords; got != tc.want {
t.Errorf("AllowCleartextPasswords = %v; want %v", got, tc.want)
}
})
}
}