@@ -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&allowFallbackToNoTLS=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 , AllowFallbackToNoTLS : 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 )
@@ -118,7 +118,7 @@ func TestDSNReformat(t *testing.T) {
118
118
t .Error (err .Error ())
119
119
continue
120
120
}
121
- cfg1 .tls = nil // pointer not static
121
+ cfg1 .TLS = nil // pointer not static
122
122
res1 := fmt .Sprintf ("%+v" , cfg1 )
123
123
124
124
dsn2 := cfg1 .FormatDSN ()
@@ -127,7 +127,7 @@ func TestDSNReformat(t *testing.T) {
127
127
t .Error (err .Error ())
128
128
continue
129
129
}
130
- cfg2 .tls = nil // pointer not static
130
+ cfg2 .TLS = nil // pointer not static
131
131
res2 := fmt .Sprintf ("%+v" , cfg2 )
132
132
133
133
if res1 != res2 {
@@ -203,7 +203,7 @@ func TestDSNWithCustomTLS(t *testing.T) {
203
203
204
204
if err != nil {
205
205
t .Error (err .Error ())
206
- } else if cfg .tls .ServerName != name {
206
+ } else if cfg .TLS .ServerName != name {
207
207
t .Errorf ("did not get the correct TLS ServerName (%s) parsing DSN (%s)." , name , tst )
208
208
}
209
209
@@ -214,7 +214,7 @@ func TestDSNWithCustomTLS(t *testing.T) {
214
214
215
215
if err != nil {
216
216
t .Error (err .Error ())
217
- } else if cfg .tls .ServerName != name {
217
+ } else if cfg .TLS .ServerName != name {
218
218
t .Errorf ("did not get the correct ServerName (%s) parsing DSN (%s)." , name , tst )
219
219
} else if tlsCfg .ServerName != "" {
220
220
t .Errorf ("tlsCfg was mutated ServerName (%s) should be empty parsing DSN (%s)." , name , tst )
@@ -229,23 +229,23 @@ func TestDSNTLSConfig(t *testing.T) {
229
229
if err != nil {
230
230
t .Error (err .Error ())
231
231
}
232
- if cfg .tls == nil {
232
+ if cfg .TLS == nil {
233
233
t .Error ("cfg.tls should not be nil" )
234
234
}
235
- if cfg .tls .ServerName != expectedServerName {
236
- t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .tls .ServerName )
235
+ if cfg .TLS .ServerName != expectedServerName {
236
+ t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .TLS .ServerName )
237
237
}
238
238
239
239
dsn = "tcp(example.com)/?tls=true"
240
240
cfg , err = ParseDSN (dsn )
241
241
if err != nil {
242
242
t .Error (err .Error ())
243
243
}
244
- if cfg .tls == nil {
244
+ if cfg .TLS == nil {
245
245
t .Error ("cfg.tls should not be nil" )
246
246
}
247
- if cfg .tls .ServerName != expectedServerName {
248
- t .Errorf ("cfg.tls.ServerName should be %q, got %q (host without port)" , expectedServerName , cfg .tls .ServerName )
247
+ if cfg .TLS .ServerName != expectedServerName {
248
+ t .Errorf ("cfg.tls.ServerName should be %q, got %q (host without port)" , expectedServerName , cfg .TLS .ServerName )
249
249
}
250
250
}
251
251
@@ -262,7 +262,7 @@ func TestDSNWithCustomTLSQueryEscape(t *testing.T) {
262
262
263
263
if err != nil {
264
264
t .Error (err .Error ())
265
- } else if cfg .tls .ServerName != name {
265
+ } else if cfg .TLS .ServerName != name {
266
266
t .Errorf ("did not get the correct TLS ServerName (%s) parsing DSN (%s)." , name , dsn )
267
267
}
268
268
}
@@ -335,12 +335,12 @@ func TestCloneConfig(t *testing.T) {
335
335
t .Errorf ("Config.Clone did not create a separate config struct" )
336
336
}
337
337
338
- if cfg2 .tls .ServerName != expectedServerName {
339
- t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .tls .ServerName )
338
+ if cfg2 .TLS .ServerName != expectedServerName {
339
+ t .Errorf ("cfg.tls.ServerName should be %q, got %q (host with port)" , expectedServerName , cfg .TLS .ServerName )
340
340
}
341
341
342
- cfg2 .tls .ServerName = "example2.com"
343
- if cfg .tls .ServerName == cfg2 .tls .ServerName {
342
+ cfg2 .TLS .ServerName = "example2.com"
343
+ if cfg .TLS .ServerName == cfg2 .TLS .ServerName {
344
344
t .Errorf ("changed cfg.tls.Server name should not propagate to original Config" )
345
345
}
346
346
@@ -384,20 +384,20 @@ func TestNormalizeTLSConfig(t *testing.T) {
384
384
385
385
cfg .normalize ()
386
386
387
- if cfg .tls == nil {
387
+ if cfg .TLS == nil {
388
388
if tc .want != nil {
389
389
t .Fatal ("wanted a tls config but got nil instead" )
390
390
}
391
391
return
392
392
}
393
393
394
- if cfg .tls .ServerName != tc .want .ServerName {
394
+ if cfg .TLS .ServerName != tc .want .ServerName {
395
395
t .Errorf ("tls.ServerName doesn't match (want: '%s', got: '%s')" ,
396
- tc .want .ServerName , cfg .tls .ServerName )
396
+ tc .want .ServerName , cfg .TLS .ServerName )
397
397
}
398
- if cfg .tls .InsecureSkipVerify != tc .want .InsecureSkipVerify {
398
+ if cfg .TLS .InsecureSkipVerify != tc .want .InsecureSkipVerify {
399
399
t .Errorf ("tls.InsecureSkipVerify doesn't match (want: %T, got :%T)" ,
400
- tc .want .InsecureSkipVerify , cfg .tls .InsecureSkipVerify )
400
+ tc .want .InsecureSkipVerify , cfg .TLS .InsecureSkipVerify )
401
401
}
402
402
})
403
403
}
0 commit comments