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

Fix CI for current master #47

Merged
merged 3 commits into from
Jan 27, 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
4 changes: 2 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ func buildSnowflakeConn(ctx context.Context, config Config) (*snowflakeConn, err
if sc.cfg.DisableTelemetry {
sc.telemetry = &snowflakeTelemetry{enabled: false}
}
if sc.cfg.ConnectionId != "" {
sc.execRespCache = acquireExecRespCache(sc.cfg.ConnectionId)
if sc.cfg.ConnectionID != "" {
sc.execRespCache = acquireExecRespCache(sc.cfg.ConnectionID)
}

// authenticate
Expand Down
10 changes: 5 additions & 5 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type Config struct {
QueryMonitoringThreshold time.Duration
// An identifier for this Config. Used to associate multiple connection instances with
// a single logical sql.DB connection.
ConnectionId string
ConnectionID string
}

// ocspMode returns the OCSP mode in string INSECURE, FAIL_OPEN, FAIL_CLOSED
Expand Down Expand Up @@ -209,8 +209,8 @@ func DSN(cfg *Config) (dsn string, err error) {

params.Add("queryMonitoringThreshold", strconv.FormatInt(int64(cfg.QueryMonitoringThreshold/time.Second), 10))

if cfg.ConnectionId != "" {
params.Add("connectionId", cfg.ConnectionId)
if cfg.ConnectionID != "" {
params.Add("connectionId", cfg.ConnectionID)
}

dsn = fmt.Sprintf("%v:%v@%v:%v", url.QueryEscape(cfg.User), url.QueryEscape(cfg.Password), cfg.Host, cfg.Port)
Expand Down Expand Up @@ -440,8 +440,8 @@ func fillMissingConfigParameters(cfg *Config) error {
if cfg.QueryMonitoringThreshold == 0 {
cfg.QueryMonitoringThreshold = defaultQueryMonitoringThreshold
}
if cfg.ConnectionId == "" {
cfg.ConnectionId = uuid.New().String()
if cfg.ConnectionID == "" {
cfg.ConnectionID = uuid.New().String()
}

if strings.HasSuffix(cfg.Host, defaultDomain) && len(cfg.Host) == len(defaultDomain) {
Expand Down
185 changes: 107 additions & 78 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,115 +602,129 @@ type tcDSN struct {

func TestDSN(t *testing.T) {
tmfmt := "MM-DD-YYYY"
testConnectionID := "abcd-0123-4567-1234"

testcases := []tcDSN{
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a-aofnadsf.somewhere.azure",
User: "u",
Password: "p",
Account: "a-aofnadsf.somewhere.azure",
ConnectionID: testConnectionID,
},
dsn: "u:p@a-aofnadsf.somewhere.azure.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=somewhere.azure&validateDefaultParameters=true",
dsn: "u:p@a-aofnadsf.somewhere.azure.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=somewhere.azure&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a-aofnadsf.global",
User: "u",
Password: "p",
Account: "a-aofnadsf.global",
ConnectionID: testConnectionID,
},
dsn: "u:p@a-aofnadsf.global.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=global&validateDefaultParameters=true",
dsn: "u:p@a-aofnadsf.global.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=global&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a-aofnadsf.global",
Region: "us-west-2",
User: "u",
Password: "p",
Account: "a-aofnadsf.global",
Region: "us-west-2",
ConnectionID: testConnectionID,
},
dsn: "u:p@a-aofnadsf.global.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=global&validateDefaultParameters=true",
dsn: "u:p@a-aofnadsf.global.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=global&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a-aofnadsf.global",
Region: "r",
User: "u",
Password: "p",
Account: "a-aofnadsf.global",
Region: "r",
ConnectionID: testConnectionID,
},
err: ErrInvalidRegion,
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
User: "u",
Password: "p",
Account: "a",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
Region: "us-west-2",
User: "u",
Password: "p",
Account: "a",
Region: "us-west-2",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
Region: "r",
User: "u",
Password: "p",
Account: "a",
Region: "r",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.r.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=r&validateDefaultParameters=true",
dsn: "u:p@a.r.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=r&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "",
Password: "p",
Account: "a",
User: "",
Password: "p",
Account: "a",
ConnectionID: testConnectionID,
},
err: ErrEmptyUsername,
},
{
cfg: &Config{
User: "u",
Password: "",
Account: "a",
User: "u",
Password: "",
Account: "a",
ConnectionID: testConnectionID,
},
err: ErrEmptyPassword,
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "",
User: "u",
Password: "p",
Account: "",
ConnectionID: testConnectionID,
},
err: ErrEmptyAccount,
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.e",
User: "u",
Password: "p",
Account: "a.e",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.e.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
dsn: "u:p@a.e.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.e",
Region: "us-west-2",
User: "u",
Password: "p",
Account: "a.e",
Region: "us-west-2",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.e.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
dsn: "u:p@a.e.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.e",
Region: "r",
User: "u",
Password: "p",
Account: "a.e",
Region: "r",
ConnectionID: testConnectionID,
},
err: ErrInvalidRegion,
},
Expand All @@ -729,17 +743,19 @@ func TestDSN(t *testing.T) {
LoginTimeout: 10 * time.Second,
RequestTimeout: 300 * time.Second,
Application: "special go",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.b.snowflakecomputing.com:443?application=special+go&database=db&loginTimeout=10&ocspFailOpen=true&passcode=db&passcodeInPassword=true&queryMonitoringThreshold=5&region=b&requestTimeout=300&role=ro&schema=sc&validateDefaultParameters=true",
dsn: "u:p@a.b.snowflakecomputing.com:443?application=special+go&connectionId=abcd-0123-4567-1234&database=db&loginTimeout=10&ocspFailOpen=true&passcode=db&passcodeInPassword=true&queryMonitoringThreshold=5&region=b&requestTimeout=300&role=ro&schema=sc&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
Authenticator: AuthTypeExternalBrowser,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?authenticator=externalbrowser&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?authenticator=externalbrowser&connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
Expand All @@ -751,8 +767,9 @@ func TestDSN(t *testing.T) {
Scheme: "https",
Host: "sc.okta.com",
},
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?authenticator=https%3A%2F%2Fsc.okta.com&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?authenticator=https%3A%2F%2Fsc.okta.com&connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
Expand All @@ -762,8 +779,9 @@ func TestDSN(t *testing.T) {
Params: map[string]*string{
"TIMESTAMP_OUTPUT_FORMAT": &tmfmt,
},
ConnectionID: testConnectionID,
},
dsn: "u:p@a.e.snowflakecomputing.com:443?TIMESTAMP_OUTPUT_FORMAT=MM-DD-YYYY&ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
dsn: "u:p@a.e.snowflakecomputing.com:443?TIMESTAMP_OUTPUT_FORMAT=MM-DD-YYYY&connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
},
{
cfg: &Config{
Expand All @@ -773,77 +791,86 @@ func TestDSN(t *testing.T) {
Params: map[string]*string{
"TIMESTAMP_OUTPUT_FORMAT": &tmfmt,
},
ConnectionID: testConnectionID,
},
dsn: "u:%3A%40abc@a.e.snowflakecomputing.com:443?TIMESTAMP_OUTPUT_FORMAT=MM-DD-YYYY&ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
dsn: "u:%3A%40abc@a.e.snowflakecomputing.com:443?TIMESTAMP_OUTPUT_FORMAT=MM-DD-YYYY&connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=e&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
OCSPFailOpen: OCSPFailOpenTrue,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
OCSPFailOpen: OCSPFailOpenFalse,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?ocspFailOpen=false&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=false&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
ValidateDefaultParameters: ConfigBoolFalse,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=false",
dsn: "u:p@a.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=false",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
ValidateDefaultParameters: ConfigBoolTrue,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
InsecureMode: true,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.snowflakecomputing.com:443?insecureMode=true&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
dsn: "u:p@a.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&insecureMode=true&ocspFailOpen=true&queryMonitoringThreshold=5&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.b.c",
User: "u",
Password: "p",
Account: "a.b.c",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.b.c.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=b.c&validateDefaultParameters=true",
dsn: "u:p@a.b.c.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=b.c&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.b.c",
Region: "us-west-2",
User: "u",
Password: "p",
Account: "a.b.c",
Region: "us-west-2",
ConnectionID: testConnectionID,
},
dsn: "u:p@a.b.c.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=5&region=b.c&validateDefaultParameters=true",
dsn: "u:p@a.b.c.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=b.c&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.b.c",
Region: "r",
User: "u",
Password: "p",
Account: "a.b.c",
Region: "r",
ConnectionID: testConnectionID,
},
err: ErrInvalidRegion,
},
Expand All @@ -853,17 +880,19 @@ func TestDSN(t *testing.T) {
Password: "p",
Account: "a.b.c",
ClientTimeout: 300 * time.Second,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.b.c.snowflakecomputing.com:443?clientTimeout=300&ocspFailOpen=true&queryMonitoringThreshold=5&region=b.c&validateDefaultParameters=true",
dsn: "u:p@a.b.c.snowflakecomputing.com:443?clientTimeout=300&connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=5&region=b.c&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.e",
QueryMonitoringThreshold: 20 * time.Second,
ConnectionID: testConnectionID,
},
dsn: "u:p@a.e.snowflakecomputing.com:443?ocspFailOpen=true&queryMonitoringThreshold=20&region=e&validateDefaultParameters=true",
dsn: "u:p@a.e.snowflakecomputing.com:443?connectionId=abcd-0123-4567-1234&ocspFailOpen=true&queryMonitoringThreshold=20&region=e&validateDefaultParameters=true",
},
}
for _, test := range testcases {
Expand Down