diff --git a/driver_test.go b/driver_test.go index f3c956f79..01377a41b 100644 --- a/driver_test.go +++ b/driver_test.go @@ -13,6 +13,7 @@ import ( "net/url" "os" "os/signal" + "strconv" "strings" "syscall" "testing" @@ -469,6 +470,47 @@ func runningOnGCP() bool { return os.Getenv("CLOUD_PROVIDER") == "GCP" } +func TestBogusUserPasswordParameters(t *testing.T) { + // Different error message is returned depending on whether the user is known or not. + var invalidDNS string + if runningOnGithubAction() { + invalidDNS = fmt.Sprintf("%s:%s@%s", "bogus", pass, host) + invalidUserPassErrorTests(invalidDNS, 390422, t) + } + invalidDNS = fmt.Sprintf("%s:%s@%s", username, "INVALID_PASSWORD", host) + invalidUserPassErrorTests(invalidDNS, 390100, t) +} + +func invalidUserPassErrorTests(invalidDNS string, expectedErr int, t *testing.T) { + parameters := url.Values{} + if protocol != "" { + parameters.Add("protocol", protocol) + } + if account != "" { + parameters.Add("account", account) + } + invalidDNS += "?" + parameters.Encode() + db, err := sql.Open("snowflake", invalidDNS) + if err != nil { + t.Fatalf("error creating a connection object: %s", err.Error()) + } + // actual connection won't happen until run a query + defer db.Close() + if _, err = db.Exec("SELECT 1"); err == nil { + t.Fatal("should cause an error.") + } + if driverErr, ok := err.(*SnowflakeError); ok { + if driverErr.Number != expectedErr { + t.Fatalf("wrong error code: %v", driverErr) + } + if !strings.Contains(driverErr.Error(), strconv.Itoa(expectedErr)) { + t.Fatalf("error message should included the error code. got: %v", driverErr.Error()) + } + } else { + t.Fatalf("wrong error code: %v", err) + } +} + func TestBogusHostNameParameters(t *testing.T) { invalidDNS := fmt.Sprintf("%s:%s@%s", username, pass, "INVALID_HOST:1234") invalidHostErrorTests(invalidDNS, []string{"no such host", "verify account name is correct", "HTTP Status: 403", "Temporary failure in name resolution", "server misbehaving"}, t)