Skip to content

Commit

Permalink
Added DSN parameter for externalBrowserTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa committed Jun 29, 2023
1 parent c1db275 commit 0e06da8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
3 changes: 2 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ following Authenticator specified:
The external browser authentication implements timeout mechanism. This prevents the driver from hanging interminably when
browser window was closed, or not responding.
Timeout defaults to 120s and can be changed as follows:
Timeout defaults to 120s and can be changed through setting DSN field "externalBrowserTimeout=240" (time in seconds)
or using a Config structure with following ExternalBrowserTimeout specified:
config := &Config{
ExternalBrowserTimeout: 240 * time.Second, // Requires time.Duration
Expand Down
8 changes: 8 additions & 0 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ func DSN(cfg *Config) (dsn string, err error) {
if cfg.JWTExpireTimeout != defaultJWTTimeout {
params.Add("jwtTimeout", strconv.FormatInt(int64(cfg.JWTExpireTimeout/time.Second), 10))
}
if cfg.ExternalBrowserTimeout != defaultExternalBrowserTimeout {
params.Add("externalBrowserTimeout", strconv.FormatInt(int64(cfg.ExternalBrowserTimeout/time.Second), 10))
}
if cfg.Application != clientType {
params.Add("application", cfg.Application)
}
Expand Down Expand Up @@ -578,6 +581,11 @@ func parseDSNParams(cfg *Config, params string) (err error) {
if err != nil {
return err
}
case "externalBrowserTimeout":
cfg.ExternalBrowserTimeout, err = parseTimeout(value)
if err != nil {
return err
}
case "application":
cfg.Application = value
case "authenticator":
Expand Down
61 changes: 58 additions & 3 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -51,6 +52,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -62,6 +64,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -74,6 +77,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -87,6 +91,7 @@ func TestParseDSN(t *testing.T) {
ValidateDefaultParameters: ConfigBoolTrue,
OCSPFailOpen: OCSPFailOpenTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -100,6 +105,7 @@ func TestParseDSN(t *testing.T) {
ValidateDefaultParameters: ConfigBoolTrue,
OCSPFailOpen: OCSPFailOpenTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -112,6 +118,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -136,6 +143,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -149,6 +157,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -162,6 +171,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -175,6 +185,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: ErrEmptyPassword,
Expand All @@ -188,6 +199,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: ErrEmptyUsername,
Expand All @@ -201,6 +213,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: ErrEmptyAccount,
Expand All @@ -214,6 +227,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -226,6 +240,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -238,6 +253,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -250,6 +266,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -265,6 +282,20 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
},
{
dsn: "u:p@a?database=d&externalBrowserTimeout=20",
config: &Config{
Account: "a", User: "u", Password: "p",
Protocol: "https", Host: "a.snowflakecomputing.com", Port: 443,
Database: "d", Schema: "",
ExternalBrowserTimeout: 20 * time.Second,
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
},
ocspMode: ocspModeFailOpen,
},
Expand All @@ -278,6 +309,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
},
Expand All @@ -289,6 +321,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: &SnowflakeError{
Expand All @@ -307,6 +340,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeInsecure,
err: nil,
Expand All @@ -321,6 +355,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand Down Expand Up @@ -370,6 +405,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -383,6 +419,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -401,6 +438,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -414,6 +452,7 @@ func TestParseDSN(t *testing.T) {
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: &SnowflakeError{Number: ErrCodePrivateKeyParseError},
Expand All @@ -426,6 +465,7 @@ func TestParseDSN(t *testing.T) {
Database: "db", Schema: "s", OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -438,6 +478,7 @@ func TestParseDSN(t *testing.T) {
Database: "db", Schema: "s", OCSPFailOpen: OCSPFailOpenFalse,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailClosed,
err: nil,
Expand All @@ -450,6 +491,7 @@ func TestParseDSN(t *testing.T) {
Database: "db", Schema: "s", OCSPFailOpen: OCSPFailOpenFalse, InsecureMode: true,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeInsecure,
err: nil,
Expand All @@ -460,7 +502,8 @@ func TestParseDSN(t *testing.T) {
Account: "account", User: "user", Password: "pass",
Protocol: "https", Host: "account.snowflakecomputing.com", Port: 443,
Database: "db", Schema: "s", ValidateDefaultParameters: ConfigBoolTrue, OCSPFailOpen: OCSPFailOpenTrue,
ClientTimeout: defaultClientTimeout,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -471,7 +514,8 @@ func TestParseDSN(t *testing.T) {
Account: "account", User: "user", Password: "pass",
Protocol: "https", Host: "account.snowflakecomputing.com", Port: 443,
Database: "db", Schema: "s", ValidateDefaultParameters: ConfigBoolFalse, OCSPFailOpen: OCSPFailOpenTrue,
ClientTimeout: defaultClientTimeout,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand All @@ -482,7 +526,8 @@ func TestParseDSN(t *testing.T) {
Account: "a", User: "u", Password: "p",
Protocol: "https", Host: "a.r.c.snowflakecomputing.com", Port: 443,
Database: "db", Schema: "s", ValidateDefaultParameters: ConfigBoolFalse, OCSPFailOpen: OCSPFailOpenTrue,
ClientTimeout: defaultClientTimeout,
ClientTimeout: defaultClientTimeout,
ExternalBrowserTimeout: defaultExternalBrowserTimeout,
},
ocspMode: ocspModeFailOpen,
err: nil,
Expand Down Expand Up @@ -671,6 +716,16 @@ func TestDSN(t *testing.T) {
},
dsn: "u:p@a.r.snowflakecomputing.com:443?ocspFailOpen=true&region=r&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a",
Region: "r",
ExternalBrowserTimeout: 20 * time.Second,
},
dsn: "u:p@a.r.snowflakecomputing.com:443?externalBrowserTimeout=20&ocspFailOpen=true&region=r&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "",
Expand Down

0 comments on commit 0e06da8

Please sign in to comment.