Skip to content

Commit 17ee918

Browse files
committed
Add test for RegisterTLSConfig
1 parent b18f20a commit 17ee918

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

driver_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mysql
22

33
import (
4+
"crypto/tls"
45
"database/sql"
56
"fmt"
67
"io"
@@ -840,7 +841,7 @@ func TestStrict(t *testing.T) {
840841
}
841842

842843
func TestTLS(t *testing.T) {
843-
runTests(t, dsn+"&tls=skip-verify", func(dbt *DBTest) {
844+
tlsTest := func(dbt *DBTest) {
844845
if err := dbt.db.Ping(); err != nil {
845846
if err == errNoTLS {
846847
dbt.Skip("Server does not support TLS")
@@ -861,7 +862,15 @@ func TestTLS(t *testing.T) {
861862
dbt.Fatal("No Cipher")
862863
}
863864
}
865+
}
866+
867+
runTests(t, dsn+"&tls=skip-verify", tlsTest)
868+
869+
// Verify that registering / using a custom cfg works
870+
RegisterTLSConfig("custom-skip-verify", &tls.Config{
871+
InsecureSkipVerify: true,
864872
})
873+
runTests(t, dsn+"&tls=custom-skip-verify", tlsTest)
865874
}
866875

867876
// Special cases

utils.go

+11-15
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,20 @@ var tlsConfigMap map[string]*tls.Config
8383
// Use the key as a value in the DSN where tls=value.
8484
//
8585
// rootCertPool := x509.NewCertPool()
86-
// {
87-
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
88-
// if err != nil {
89-
// log.Fatal(err)
90-
// }
91-
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
92-
// log.Fatal("Failed to append PEM.")
93-
// }
86+
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
87+
// if err != nil {
88+
// log.Fatal(err)
89+
// }
90+
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
91+
// log.Fatal("Failed to append PEM.")
9492
// }
9593
// clientCert := make([]tls.Certificate, 0, 1)
96-
// {
97-
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
98-
// if err != nil {
99-
// log.Fatal(err)
100-
// }
101-
// clientCert = append(clientCert, certs)
94+
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
95+
// if err != nil {
96+
// log.Fatal(err)
10297
// }
103-
// mysql.RegisterTLSConfig("custom", tls.Config{
98+
// clientCert = append(clientCert, certs)
99+
// mysql.RegisterTLSConfig("custom", &tls.Config{
104100
// RootCAs: rootCertPool,
105101
// Certificates: clientCert,
106102
// })

0 commit comments

Comments
 (0)