From 0874761875dd74e1c1c06340aa28e68eb48fa715 Mon Sep 17 00:00:00 2001 From: Kevin Malachowski Date: Wed, 23 Dec 2015 16:32:48 -0800 Subject: [PATCH 1/2] QueryUnescape the tlsConfig name during DSN parsing. Also add unit test. --- utils.go | 2 ++ utils_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/utils.go b/utils.go index 6a26ad129..4bfc331e3 100644 --- a/utils.go +++ b/utils.go @@ -267,6 +267,8 @@ func parseDSNParams(cfg *config, params string) (err error) { if boolValue { cfg.tls = &tls.Config{} } + } else if value, err := url.QueryUnescape(value); err != nil { + return fmt.Errorf("Invalid value for tls config name: %v", err) } else { if strings.ToLower(value) == "skip-verify" { cfg.tls = &tls.Config{InsecureSkipVerify: true} diff --git a/utils_test.go b/utils_test.go index 79fbdd1eb..15e4d4b7a 100644 --- a/utils_test.go +++ b/utils_test.go @@ -13,6 +13,7 @@ import ( "crypto/tls" "encoding/binary" "fmt" + "net/url" "testing" "time" ) @@ -116,6 +117,23 @@ func TestDSNWithCustomTLS(t *testing.T) { 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) { _, err := parseDSN("/dbname?collation=gbk_chinese_ci&interpolateParams=true") if err != errInvalidDSNUnsafeCollation { From 5e93316731528fdcbf2b4c836eeefe37b7e9f5e4 Mon Sep 17 00:00:00 2001 From: Kevin Malachowski Date: Wed, 6 Jan 2016 11:23:08 -0800 Subject: [PATCH 2/2] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 6fc4c6f7b..f3364b99b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -26,6 +26,7 @@ Jian Zhen Joshua Prunier Julien Schmidt Kamil Dziedzic +Kevin Malachowski Leonardo YongUk Kim Lucas Liu Luke Scott