@@ -22,46 +22,49 @@ var testDSNs = []struct {
22
22
out * Config
23
23
}{{
24
24
"username:password@protocol(address)/dbname?param=value" ,
25
- & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Collation : "utf8_general_ci" , Loc : time .UTC },
25
+ & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
26
26
}, {
27
27
"username:password@protocol(address)/dbname?param=value&columnsWithAlias=true" ,
28
- & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Collation : "utf8_general_ci" , Loc : time .UTC , ColumnsWithAlias : true },
28
+ & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true , ColumnsWithAlias : true },
29
29
}, {
30
30
"username:password@protocol(address)/dbname?param=value&columnsWithAlias=true&multiStatements=true" ,
31
- & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Collation : "utf8_general_ci" , Loc : time .UTC , ColumnsWithAlias : true , MultiStatements : true },
31
+ & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true , ColumnsWithAlias : true , MultiStatements : true },
32
32
}, {
33
33
"user@unix(/path/to/socket)/dbname?charset=utf8" ,
34
- & Config {User : "user" , Net : "unix" , Addr : "/path/to/socket" , DBName : "dbname" , Params : map [string ]string {"charset" : "utf8" }, Collation : "utf8_general_ci" , Loc : time .UTC },
34
+ & Config {User : "user" , Net : "unix" , Addr : "/path/to/socket" , DBName : "dbname" , Params : map [string ]string {"charset" : "utf8" }, Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
35
35
}, {
36
36
"user:password@tcp(localhost:5555)/dbname?charset=utf8&tls=true" ,
37
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , Params : map [string ]string {"charset" : "utf8" }, Collation : "utf8_general_ci" , Loc : time .UTC , TLSConfig : "true" },
37
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , Params : map [string ]string {"charset" : "utf8" }, Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true , TLSConfig : "true" },
38
38
}, {
39
39
"user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify" ,
40
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , Params : map [string ]string {"charset" : "utf8mb4,utf8" }, Collation : "utf8_general_ci" , Loc : time .UTC , TLSConfig : "skip-verify" },
40
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , Params : map [string ]string {"charset" : "utf8mb4,utf8" }, Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true , TLSConfig : "skip-verify" },
41
41
}, {
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" ,
43
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8mb4_unicode_ci" , Loc : time .UTC , Timeout : 30 * time .Second , ReadTimeout : time .Second , WriteTimeout : time .Second , AllowAllFiles : true , AllowOldPasswords : true , ClientFoundRows : true , MaxAllowedPacket : 16777216 },
43
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8mb4_unicode_ci" , Loc : time .UTC , AllowNativePasswords : true , Timeout : 30 * time .Second , ReadTimeout : time .Second , WriteTimeout : time .Second , AllowAllFiles : true , AllowOldPasswords : true , ClientFoundRows : true , MaxAllowedPacket : 16777216 },
44
+ }, {
45
+ "user:password@/dbname?allowNativePasswords=false" ,
46
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : false },
44
47
}, {
45
48
"user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local" ,
46
- & Config {User : "user" , Passwd : "p@ss(word)" , Net : "tcp" , Addr : "[de:ad:be:ef::ca:fe]:80" , DBName : "dbname" , Collation : "utf8_general_ci" , Loc : time .Local },
49
+ & Config {User : "user" , Passwd : "p@ss(word)" , Net : "tcp" , Addr : "[de:ad:be:ef::ca:fe]:80" , DBName : "dbname" , Collation : "utf8_general_ci" , Loc : time .Local , AllowNativePasswords : true },
47
50
}, {
48
51
"/dbname" ,
49
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8_general_ci" , Loc : time .UTC },
52
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
50
53
}, {
51
54
"@/" ,
52
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC },
55
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
53
56
}, {
54
57
"/" ,
55
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC },
58
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
56
59
}, {
57
60
"" ,
58
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC },
61
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
59
62
}, {
60
63
"user:p@/ssword@/" ,
61
- & Config {User : "user" , Passwd : "p@/ssword" , Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC },
64
+ & Config {User : "user" , Passwd : "p@/ssword" , Net : "tcp" , Addr : "127.0.0.1:3306" , Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
62
65
}, {
63
66
"unix/?arg=%2Fsome%2Fpath.ext" ,
64
- & Config {Net : "unix" , Addr : "/tmp/mysql.sock" , Params : map [string ]string {"arg" : "/some/path.ext" }, Collation : "utf8_general_ci" , Loc : time .UTC },
67
+ & Config {Net : "unix" , Addr : "/tmp/mysql.sock" , Params : map [string ]string {"arg" : "/some/path.ext" }, Collation : "utf8_general_ci" , Loc : time .UTC , AllowNativePasswords : true },
65
68
}}
66
69
67
70
func TestDSNParser (t * testing.T ) {
@@ -223,8 +226,9 @@ func TestDSNUnsafeCollation(t *testing.T) {
223
226
func TestParamsAreSorted (t * testing.T ) {
224
227
expected := "/dbname?interpolateParams=true&foobar=baz&quux=loo"
225
228
dsn := & Config {
226
- DBName : "dbname" ,
227
- InterpolateParams : true ,
229
+ DBName : "dbname" ,
230
+ InterpolateParams : true ,
231
+ AllowNativePasswords : true ,
228
232
Params : map [string ]string {
229
233
"quux" : "loo" ,
230
234
"foobar" : "baz" ,
0 commit comments