Skip to content

Commit

Permalink
add bogus user password test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jl committed Sep 27, 2024
1 parent a26ac8a commit e0ccded
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/url"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"testing"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e0ccded

Please sign in to comment.