Skip to content

Commit

Permalink
SNOW-1759523 Fix 404 for test accounts (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pfus authored Oct 23, 2024
1 parent b299730 commit 3d7a06c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 16 additions & 12 deletions driver_ocsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ func TestOCSPFailOpen(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}

func isFailToConnectOrAuthErr(driverErr *SnowflakeError) bool {
return driverErr.Number != ErrCodeFailedToConnect && driverErr.Number != ErrFailedToAuth
}

// TestOCSPFailOpenWithoutFileCache ensures no file cache is used.
func TestOCSPFailOpenWithoutFileCache(t *testing.T) {
cleanup()
Expand Down Expand Up @@ -128,7 +132,7 @@ func TestOCSPFailOpenWithoutFileCache(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}
Expand Down Expand Up @@ -170,7 +174,7 @@ func TestOCSPFailOpenValidityError(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}
Expand Down Expand Up @@ -259,7 +263,7 @@ func TestOCSPFailOpenUnknownStatus(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}
Expand Down Expand Up @@ -444,7 +448,7 @@ func TestOCSPFailOpenCacheServerTimeout(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}
Expand Down Expand Up @@ -493,7 +497,7 @@ func TestOCSPFailClosedCacheServerTimeout(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should have failed to connect. err: %v", err)
}
// Go 1.18 and after rejects SHA-1 certificates, therefore a different error is returned (https://github.com/golang/go/issues/41682)
Expand Down Expand Up @@ -545,7 +549,7 @@ func TestOCSPFailOpenResponderTimeout(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}
Expand Down Expand Up @@ -592,7 +596,7 @@ func TestOCSPFailClosedResponderTimeout(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error URL Error: %v", urlErr.Err)
}
if !strings.Contains(urlErr0.Err.Error(), "Client.Timeout") {
if !strings.Contains(urlErr0.Err.Error(), "Client.Timeout") && !strings.Contains(urlErr0.Err.Error(), "connection refused") {
t.Fatalf("the root cause is not timeout: %v", urlErr0.Err)
}
}
Expand Down Expand Up @@ -634,7 +638,7 @@ func TestOCSPFailOpenResponder404(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}
Expand Down Expand Up @@ -676,8 +680,8 @@ func TestOCSPFailClosedResponder404(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if !strings.Contains(urlErr.Err.Error(), "404 Not Found") {
t.Fatalf("the root cause is not timeout: %v", urlErr.Err)
if !strings.Contains(urlErr.Err.Error(), "404 Not Found") && !strings.Contains(urlErr.Err.Error(), "connection refused") {
t.Fatalf("the root cause is not 404: %v", urlErr.Err)
}
}

Expand Down Expand Up @@ -804,7 +808,7 @@ func TestOCSPFailOpenNoOCSPURL(t *testing.T) {
if !ok {
t.Fatalf("failed to extract error SnowflakeError: %v", err)
}
if driverErr.Number != ErrCodeFailedToConnect {
if isFailToConnectOrAuthErr(driverErr) {
t.Fatalf("should failed to connect %v", err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ 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)
invalidDNS = fmt.Sprintf("%s:%s@%s", username, pass, "INVALID_HOST")
invalidHostErrorTests(invalidDNS, []string{"read: connection reset by peer", "EOF", "verify account name is correct", "HTTP Status: 403", "Temporary failure in name resolution", "server misbehaving"}, t)
invalidHostErrorTests(invalidDNS, []string{"read: connection reset by peer", "EOF", "verify account name is correct", "HTTP Status: 403", "Temporary failure in name resolution", "server misbehaving", "failed to auth"}, t)
}

func invalidHostErrorTests(invalidDNS string, mstr []string, t *testing.T) {
Expand Down Expand Up @@ -1715,7 +1715,7 @@ func TestPingInvalidHost(t *testing.T) {
if strings.Contains(err.Error(), "HTTP Status: 513. Hanging?") {
return
}
if driverErr, ok := err.(*SnowflakeError); !ok || ok && driverErr.Number != ErrCodeFailedToConnect {
if driverErr, ok := err.(*SnowflakeError); !ok || ok && isFailToConnectOrAuthErr(driverErr) {
// Failed to connect error
t.Fatalf("error didn't match")
}
Expand Down

0 comments on commit 3d7a06c

Please sign in to comment.