Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully parse secure and skip_verify DSN params #862

Merged
merged 1 commit into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions clickhouse_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"context"
"crypto/tls"
"fmt"
"github.com/ClickHouse/ch-go/compress"
"github.com/pkg/errors"
"net"
"net/url"
"strconv"
"strings"
"time"

"github.com/ClickHouse/ch-go/compress"
"github.com/pkg/errors"
)

type CompressionMethod byte
Expand Down Expand Up @@ -229,9 +230,25 @@ func (o *Options) fromDSN(in string) error {
}
o.ReadTimeout = duration
case "secure":
secure = true
secureParam := params.Get(v)
if secureParam == "" {
secure = true
} else {
secure, err = strconv.ParseBool(secureParam)
if err != nil {
return fmt.Errorf("clickhouse [dsn parse]:secure: %s", err)
}
}
case "skip_verify":
skipVerify = true
skipVerifyParam := params.Get(v)
if skipVerifyParam == "" {
skipVerify = true
} else {
skipVerify, err = strconv.ParseBool(skipVerifyParam)
if err != nil {
return fmt.Errorf("clickhouse [dsn parse]:verify: %s", err)
}
}
case "connection_open_strategy":
switch params.Get(v) {
case "in_order":
Expand Down
84 changes: 83 additions & 1 deletion clickhouse_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package clickhouse

import (
"github.com/stretchr/testify/assert"
"crypto/tls"
"testing"

"github.com/stretchr/testify/assert"
)

// TestParseDSN does not implement all use cases yet
Expand Down Expand Up @@ -127,6 +129,86 @@ func TestParseDSN(t *testing.T) {
},
"",
},
{
"native protocol with secure",
"clickhouse://127.0.0.1/test_database?secure=true",
&Options{
Protocol: Native,
TLS: &tls.Config{
InsecureSkipVerify: false,
},
Addr: []string{"127.0.0.1"},
Settings: Settings{},
Auth: Auth{
Database: "test_database",
},
scheme: "clickhouse",
},
"",
},
{
"native protocol with skip_verify",
"clickhouse://127.0.0.1/test_database?secure=true&skip_verify=true",
&Options{
Protocol: Native,
TLS: &tls.Config{
InsecureSkipVerify: true,
},
Addr: []string{"127.0.0.1"},
Settings: Settings{},
Auth: Auth{
Database: "test_database",
},
scheme: "clickhouse",
},
"",
},
{
"native protocol with secure (legacy)",
"clickhouse://127.0.0.1/test_database?secure",
&Options{
Protocol: Native,
TLS: &tls.Config{
InsecureSkipVerify: false,
},
Addr: []string{"127.0.0.1"},
Settings: Settings{},
Auth: Auth{
Database: "test_database",
},
scheme: "clickhouse",
},
"",
},
{
"native protocol with skip_verify (legacy)",
"clickhouse://127.0.0.1/test_database?secure&skip_verify",
&Options{
Protocol: Native,
TLS: &tls.Config{
InsecureSkipVerify: true,
},
Addr: []string{"127.0.0.1"},
Settings: Settings{},
Auth: Auth{
Database: "test_database",
},
scheme: "clickhouse",
},
"",
},
{
"native protocol with secure (bad)",
"clickhouse://127.0.0.1/test_database?secure=ture",
nil,
"clickhouse [dsn parse]:secure: strconv.ParseBool: parsing \"ture\": invalid syntax",
},
{
"native protocol with skip_verify (bad)",
"clickhouse://127.0.0.1/test_database?secure&skip_verify=ture",
nil,
"clickhouse [dsn parse]:verify: strconv.ParseBool: parsing \"ture\": invalid syntax",
},
{
"native protocol with default lz4 compression",
"clickhouse://127.0.0.1/test_database?compress=true",
Expand Down