Skip to content

Commit

Permalink
Add more test and fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Jacky Hu <[email protected]>
  • Loading branch information
jackyhu-db committed May 28, 2024
1 parent 44fbf9c commit 79ad98f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 79ad98f

Please sign in to comment.