From 79ad98f19872ac10c42f0270b26ee767ac788b16 Mon Sep 17 00:00:00 2001 From: Jacky Hu Date: Fri, 24 May 2024 08:55:00 -0700 Subject: [PATCH] Add more test and fix lint Signed-off-by: Jacky Hu --- connector.go | 4 ++-- connector_test.go | 24 ++++++++++++++++++++++++ internal/client/client.go | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/connector.go b/connector.go index aacb6b5..bab81fd 100644 --- a/connector.go +++ b/connector.go @@ -241,9 +241,9 @@ func WithSessionParams(params map[string]string) connOption { func WithSkipTLSHostVerify() connOption { return func(c *config.Config) { if c.TLSConfig == nil { - c.TLSConfig = &tls.Config{MinVersion: tls.VersionTLS12, InsecureSkipVerify: true} + c.TLSConfig = &tls.Config{MinVersion: tls.VersionTLS12, InsecureSkipVerify: true} // #nosec G402 } else { - c.TLSConfig.InsecureSkipVerify = true + c.TLSConfig.InsecureSkipVerify = true // #nosec G402 } } } diff --git a/connector_test.go b/connector_test.go index cfcbcf6..8e0c7cb 100644 --- a/connector_test.go +++ b/connector_test.go @@ -6,7 +6,9 @@ import ( "time" "github.com/databricks/databricks-sql-go/auth/pat" + "github.com/databricks/databricks-sql-go/internal/client" "github.com/databricks/databricks-sql-go/internal/config" + "github.com/hashicorp/go-retryablehttp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -186,6 +188,28 @@ func TestNewConnector(t *testing.T) { } }) + + t.Run("Connector test WithSkipTLSHostVerify with PoolClient", func(t *testing.T) { + hostname := "databricks-host" + con, err := NewConnector( + WithServerHostname(hostname), + WithSkipTLSHostVerify(), + ) + assert.Nil(t, err) + + coni, ok := con.(*connector) + require.True(t, ok) + userConfig := coni.cfg.UserConfig + require.Equal(t, hostname, userConfig.Host) + + httpClient, ok := coni.client.Transport.(*retryablehttp.RoundTripper) + require.True(t, ok) + poolClient, ok := httpClient.Client.HTTPClient.Transport.(*client.Transport) + require.True(t, ok) + internalClient, ok := poolClient.Base.(*http.Transport) + require.True(t, ok) + require.True(t, internalClient.TLSClientConfig.InsecureSkipVerify) + }) } type mockRoundTripper struct{} diff --git a/internal/client/client.go b/internal/client/client.go index 6204819..febab52 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -549,7 +549,7 @@ func RetryableClient(cfg *config.Config) *http.Client { func PooledTransport(cfg *config.Config) *http.Transport { var tlsConfig *tls.Config if (cfg.TLSConfig != nil) && cfg.TLSConfig.InsecureSkipVerify { - tlsConfig = &tls.Config{InsecureSkipVerify: true} + tlsConfig = cfg.TLSConfig } transport := &http.Transport{