@@ -42,8 +42,8 @@ var testDSNs = []struct {
42
42
"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" ,
43
43
& 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 },
44
44
}, {
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 },
47
47
}, {
48
48
"user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local" ,
49
49
& 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) {
82
82
}
83
83
84
84
// pointer not static
85
- cfg .tls = nil
85
+ cfg .TLS = nil
86
86
87
87
if ! reflect .DeepEqual (cfg , tst .out ) {
88
88
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) {
100
100
"User:pass@tcp(1.2.3.4:3306)" , // no trailing slash
101
101
"net()/" , // unknown default addr
102
102
"user:pass@tcp(127.0.0.1:3306)/db/name" , // invalid dbname
103
+ "user:password@/dbname?allowFallbackToPlaintext=PREFERRED" , // wrong bool flag
103
104
//"/dbname?arg=/some/unescaped/path",
104
105
}
105
106
@@ -118,7 +119,7 @@ func TestDSNReformat(t *testing.T) {
118
119
t .Error (err .Error ())
119
120
continue
120
121
}
121
- cfg1 .tls = nil // pointer not static
122
+ cfg1 .TLS = nil // pointer not static
122
123
res1 := fmt .Sprintf ("%+v" , cfg1 )
123
124
124
125
dsn2 := cfg1 .FormatDSN ()
@@ -127,7 +128,7 @@ func TestDSNReformat(t *testing.T) {
127
128
t .Error (err .Error ())
128
129
continue
129
130
}
130
- cfg2 .tls = nil // pointer not static
131
+ cfg2 .TLS = nil // pointer not static
131
132
res2 := fmt .Sprintf ("%+v" , cfg2 )
132
133
133
134
if res1 != res2 {
@@ -203,7 +204,7 @@ func TestDSNWithCustomTLS(t *testing.T) {
203
204
204
205
if err != nil {
205
206
t .Error (err .Error ())
206
- } else if cfg .tls .ServerName != name {
207
+ } else if cfg .TLS .ServerName != name {
207
208
t .Errorf ("did not get the correct TLS ServerName (%s) parsing DSN (%s)." , name , tst )
208
209
}
209
210
@@ -214,7 +215,7 @@ func TestDSNWithCustomTLS(t *testing.T) {
214
215
215
216
if err != nil {
216
217
t .Error (err .Error ())
217
- } else if cfg .tls .ServerName != name {
218
+ } else if cfg .TLS .ServerName != name {
218
219
t .Errorf ("did not get the correct ServerName (%s) parsing DSN (%s)." , name , tst )
219
220
} else if tlsCfg .ServerName != "" {
220
221
t .Errorf ("tlsCfg was mutated ServerName (%s) should be empty parsing DSN (%s)." , name , tst )
@@ -229,23 +230,23 @@ func TestDSNTLSConfig(t *testing.T) {
229
230
if err != nil {
230
231
t .Error (err .Error ())
231
232
}
232
- if cfg .tls == nil {
233
+ if cfg .TLS == nil {
233
234
t .Error ("cfg.tls should not be nil" )
234
235
}
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 )
237
238
}
238
239
239
240
dsn = "tcp(example.com)/?tls=true"
240
241
cfg , err = ParseDSN (dsn )
241
242
if err != nil {
242
243
t .Error (err .Error ())
243
244
}
244
- if cfg .tls == nil {
245
+ if cfg .TLS == nil {
245
246
t .Error ("cfg.tls should not be nil" )
246
247
}
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 )
249
250
}
250
251
}
251
252
@@ -262,7 +263,7 @@ func TestDSNWithCustomTLSQueryEscape(t *testing.T) {
262
263
263
264
if err != nil {
264
265
t .Error (err .Error ())
265
- } else if cfg .tls .ServerName != name {
266
+ } else if cfg .TLS .ServerName != name {
266
267
t .Errorf ("did not get the correct TLS ServerName (%s) parsing DSN (%s)." , name , dsn )
267
268
}
268
269
}
@@ -335,12 +336,12 @@ func TestCloneConfig(t *testing.T) {
335
336
t .Errorf ("Config.Clone did not create a separate config struct" )
336
337
}
337
338
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 )
340
341
}
341
342
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 {
344
345
t .Errorf ("changed cfg.tls.Server name should not propagate to original Config" )
345
346
}
346
347
@@ -384,20 +385,20 @@ func TestNormalizeTLSConfig(t *testing.T) {
384
385
385
386
cfg .normalize ()
386
387
387
- if cfg .tls == nil {
388
+ if cfg .TLS == nil {
388
389
if tc .want != nil {
389
390
t .Fatal ("wanted a tls config but got nil instead" )
390
391
}
391
392
return
392
393
}
393
394
394
- if cfg .tls .ServerName != tc .want .ServerName {
395
+ if cfg .TLS .ServerName != tc .want .ServerName {
395
396
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 )
397
398
}
398
- if cfg .tls .InsecureSkipVerify != tc .want .InsecureSkipVerify {
399
+ if cfg .TLS .InsecureSkipVerify != tc .want .InsecureSkipVerify {
399
400
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 )
401
402
}
402
403
})
403
404
}
0 commit comments