|
@@ -13,6 +13,7 @@ import (
|
|
|
"crypto/tls"
|
|
"crypto/tls"
|
|
|
"encoding/binary"
|
|
"encoding/binary"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "net/url"
|
|
|
"testing"
|
|
"testing"
|
|
|
"time"
|
|
"time"
|
|
|
)
|
|
)
|
|
@@ -116,6 +117,23 @@ func TestDSNWithCustomTLS(t *testing.T) {
|
|
|
DeregisterTLSConfig("utils_test")
|
|
DeregisterTLSConfig("utils_test")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestDSNWithCustomTLS_queryEscape(t *testing.T) {
|
|
|
|
|
+ const configKey = "&%!:"
|
|
|
|
|
+ dsn := "user:password@tcp(localhost:5555)/dbname?tls=" + url.QueryEscape(configKey)
|
|
|
|
|
+ name := "foohost"
|
|
|
|
|
+ tlsCfg := tls.Config{ServerName: name}
|
|
|
|
|
+
|
|
|
|
|
+ RegisterTLSConfig(configKey, &tlsCfg)
|
|
|
|
|
+
|
|
|
|
|
+ cfg, err := parseDSN(dsn)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Error(err.Error())
|
|
|
|
|
+ } else if cfg.tls.ServerName != name {
|
|
|
|
|
+ t.Errorf("Did not get the correct TLS ServerName (%s) parsing DSN (%s).", name, dsn)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestDSNUnsafeCollation(t *testing.T) {
|
|
func TestDSNUnsafeCollation(t *testing.T) {
|
|
|
_, err := parseDSN("/dbname?collation=gbk_chinese_ci&interpolateParams=true")
|
|
_, err := parseDSN("/dbname?collation=gbk_chinese_ci&interpolateParams=true")
|
|
|
if err != errInvalidDSNUnsafeCollation {
|
|
if err != errInvalidDSNUnsafeCollation {
|