@@ -42,8 +42,8 @@ var testDSNs = []struct {
4242 "user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci&maxAllowedPacket=16777216&tls=false&allowCleartextPasswords=true&parseTime=true&rejectReadOnly=true" ,
4343 & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8mb4_unicode_ci" , Loc : time .UTC , TLSConfig : "false" , AllowCleartextPasswords : true , AllowNativePasswords : true , Timeout : 30 * time .Second , ReadTimeout : time .Second , WriteTimeout : time .Second , AllowAllFiles : true , AllowOldPasswords : true , CheckConnLiveness : true , ClientFoundRows : true , MaxAllowedPacket : 16777216 , ParseTime : true , RejectReadOnly : true },
4444}, {
45- "user:password@/dbname?allowNativePasswords=false&checkConnLiveness=false&maxAllowedPacket=0" ,
46- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8mb4_general_ci" , Loc : time .UTC , MaxAllowedPacket : 0 , AllowNativePasswords : false , CheckConnLiveness : false },
45+ "user:password@/dbname?allowNativePasswords=false&checkConnLiveness=false&maxAllowedPacket=0&allowFallbackToPlaintext=true " ,
46+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8mb4_general_ci" , Loc : time .UTC , MaxAllowedPacket : 0 , AllowFallbackToPlaintext : true , AllowNativePasswords : false , CheckConnLiveness : false },
4747}, {
4848 "user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local" ,
4949 & Config {User : "user" , Passwd : "p@ss(word)" , Net : "tcp" , Addr : "[de:ad:be:ef::ca:fe]:80" , DBName : "dbname" , Collation : "utf8mb4_general_ci" , Loc : time .Local , MaxAllowedPacket : defaultMaxAllowedPacket , AllowNativePasswords : true , CheckConnLiveness : true },
@@ -82,7 +82,7 @@ func TestDSNParser(t *testing.T) {
8282 }
8383
8484 // pointer not static
85- cfg .tls = nil
85+ cfg .TLS = nil
8686
8787 if ! reflect .DeepEqual (cfg , tst .out ) {
8888 t .Errorf ("%d. ParseDSN(%q) mismatch:\n got %+v\n want %+v" , i , tst .in , cfg , tst .out )
@@ -100,6 +100,7 @@ func TestDSNParserInvalid(t *testing.T) {
100100 "User:pass@tcp(1.2.3.4:3306)" , // no trailing slash
101101 "net()/" , // unknown default addr
102102 "user:pass@tcp(127.0.0.1:3306)/db/name" , // invalid dbname
103+ "user:password@/dbname?allowFallbackToPlaintext=PREFERRED" , // wrong bool flag
103104 //"/dbname?arg=/some/unescaped/path",
104105 }
105106
@@ -118,7 +119,7 @@ func TestDSNReformat(t *testing.T) {
118119 t .Error (err .Error ())
119120 continue
120121 }
121- cfg1 .tls = nil // pointer not static
122+ cfg1 .TLS = nil // pointer not static
122123 res1 := fmt .Sprintf ("%+v" , cfg1 )
123124
124125 dsn2 := cfg1 .FormatDSN ()
@@ -127,7 +128,7 @@ func TestDSNReformat(t *testing.T) {
127128 t .Error (err .Error ())
128129 continue
129130 }
130- cfg2 .tls = nil // pointer not static
131+ cfg2 .TLS = nil // pointer not static
131132 res2 := fmt .Sprintf ("%+v" , cfg2 )
132133
133134 if res1 != res2 {
@@ -203,7 +204,7 @@ func TestDSNWithCustomTLS(t *testing.T) {
203204
204205 if err != nil {
205206 t .Error (err .Error ())
206- } else if cfg .tls .ServerName != name {
207+ } else if cfg .TLS .ServerName != name {
207208 t .Errorf ("did not get the correct TLS ServerName (%s) parsing DSN (%s)." , name , tst )
208209 }
209210
@@ -214,7 +215,7 @@ func TestDSNWithCustomTLS(t *testing.T) {
214215
215216 if err != nil {
216217 t .Error (err .Error ())
217- } else if cfg .tls .ServerName != name {
218+ } else if cfg .TLS .ServerName != name {
218219 t .Errorf ("did not get the correct ServerName (%s) parsing DSN (%s)." , name , tst )
219220 } else if tlsCfg .ServerName != "" {
220221 t .Errorf ("tlsCfg was mutated ServerName (%s) should be empty parsing DSN (%s)." , name , tst )
@@ -229,23 +230,23 @@ func TestDSNTLSConfig(t *testing.T) {
229230 if err != nil {
230231 t .Error (err .Error ())
231232 }
232- if cfg .tls == nil {
233+ if cfg .TLS == nil {
233234 t .Error ("cfg.tls should not be nil" )
234235 }
235- if cfg .tls .ServerName != expectedServerName {
236- t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .tls .ServerName )
236+ if cfg .TLS .ServerName != expectedServerName {
237+ t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .TLS .ServerName )
237238 }
238239
239240 dsn = "tcp(example.com)/?tls=true"
240241 cfg , err = ParseDSN (dsn )
241242 if err != nil {
242243 t .Error (err .Error ())
243244 }
244- if cfg .tls == nil {
245+ if cfg .TLS == nil {
245246 t .Error ("cfg.tls should not be nil" )
246247 }
247- if cfg .tls .ServerName != expectedServerName {
248- t .Errorf ("cfg.tls.ServerName should be %q, got %q (host without port)" , expectedServerName , cfg .tls .ServerName )
248+ if cfg .TLS .ServerName != expectedServerName {
249+ t .Errorf ("cfg.tls.ServerName should be %q, got %q (host without port)" , expectedServerName , cfg .TLS .ServerName )
249250 }
250251}
251252
@@ -262,7 +263,7 @@ func TestDSNWithCustomTLSQueryEscape(t *testing.T) {
262263
263264 if err != nil {
264265 t .Error (err .Error ())
265- } else if cfg .tls .ServerName != name {
266+ } else if cfg .TLS .ServerName != name {
266267 t .Errorf ("did not get the correct TLS ServerName (%s) parsing DSN (%s)." , name , dsn )
267268 }
268269}
@@ -335,12 +336,12 @@ func TestCloneConfig(t *testing.T) {
335336 t .Errorf ("Config.Clone did not create a separate config struct" )
336337 }
337338
338- if cfg2 .tls .ServerName != expectedServerName {
339- t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .tls .ServerName )
339+ if cfg2 .TLS .ServerName != expectedServerName {
340+ t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .TLS .ServerName )
340341 }
341342
342- cfg2 .tls .ServerName = "example2.com"
343- if cfg .tls .ServerName == cfg2 .tls .ServerName {
343+ cfg2 .TLS .ServerName = "example2.com"
344+ if cfg .TLS .ServerName == cfg2 .TLS .ServerName {
344345 t .Errorf ("changed cfg.tls.Server name should not propagate to original Config" )
345346 }
346347
@@ -384,20 +385,20 @@ func TestNormalizeTLSConfig(t *testing.T) {
384385
385386 cfg .normalize ()
386387
387- if cfg .tls == nil {
388+ if cfg .TLS == nil {
388389 if tc .want != nil {
389390 t .Fatal ("wanted a tls config but got nil instead" )
390391 }
391392 return
392393 }
393394
394- if cfg .tls .ServerName != tc .want .ServerName {
395+ if cfg .TLS .ServerName != tc .want .ServerName {
395396 t .Errorf ("tls.ServerName doesn't match (want: '%s', got: '%s')" ,
396- tc .want .ServerName , cfg .tls .ServerName )
397+ tc .want .ServerName , cfg .TLS .ServerName )
397398 }
398- if cfg .tls .InsecureSkipVerify != tc .want .InsecureSkipVerify {
399+ if cfg .TLS .InsecureSkipVerify != tc .want .InsecureSkipVerify {
399400 t .Errorf ("tls.InsecureSkipVerify doesn't match (want: %T, got :%T)" ,
400- tc .want .InsecureSkipVerify , cfg .tls .InsecureSkipVerify )
401+ tc .want .InsecureSkipVerify , cfg .TLS .InsecureSkipVerify )
401402 }
402403 })
403404 }
0 commit comments