Skip to content

Commit

Permalink
Fixes #55: Incorrect oVirt Engine API URL not correctly identified
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Bonic committed Apr 6, 2022
1 parent 43fb45c commit 5b92b5b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
20 changes: 16 additions & 4 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,24 @@ func realIdentify(err error) EngineError {
var authErr *ovirtsdk.AuthError
var notFoundErr *ovirtsdk.NotFoundError
switch {
case strings.Contains(err.Error(), "stopped after") && strings.Contains(err.Error(), "redirects"):
return wrap(
err,
ENotAnOVirtEngine,
"the specified oVirt Engine URL has resulted in a redirect, check if your URL is correct",
)
case strings.Contains(err.Error(), "parse non-array sso with response"):
return wrap(err,
ENotAnOVirtEngine, "invalid credentials, or the URL does not point to an oVirt Engine, check your settings")
return wrap(
err,
ENotAnOVirtEngine,
"invalid credentials, or the URL does not point to an oVirt Engine, check your settings",
)
case strings.Contains(err.Error(), "server gave HTTP response to HTTPS client"):
return wrap(err,
ENotAnOVirtEngine, "the server gave a HTTP response to a HTTPS client, check if your URL is correct")
return wrap(
err,
ENotAnOVirtEngine,
"the server gave a HTTP response to a HTTPS client, check if your URL is correct",
)
case strings.Contains(err.Error(), "tls"):
fallthrough
case strings.Contains(err.Error(), "x509"):
Expand Down
29 changes: 29 additions & 0 deletions new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,41 @@ import (
"crypto/x509"
"errors"
"fmt"
"strings"
"testing"

ovirtclient "github.com/ovirt/go-ovirt-client"
ovirtclientlog "github.com/ovirt/go-ovirt-client-log/v2"
)

func TestBadOVirtURL(t *testing.T) {
helper, err := ovirtclient.NewLiveTestHelperFromEnv(ovirtclientlog.NewTestLogger(t))
if err != nil {
t.Skipf("🚧 Skipping test: no live credentials provided.")
return
}
url := helper.GetClient().GetURL()
tls := helper.GetTLS()
username := helper.GetUsername()
password := helper.GetPassword()

logger := ovirtclientlog.NewTestLogger(t)
_, err = ovirtclient.New(
strings.TrimSuffix(strings.TrimSuffix(url, "/api"), "/api/"),
username,
password,
tls,
logger,
nil,
)
if err == nil {
t.Fatalf("Creating a connection to an endpoint not ending in /api did not result in an error.")
}
if !ovirtclient.HasErrorCode(err, ovirtclient.ENotAnOVirtEngine) {
t.Fatalf("Creating a connection to an endpoint not ending in /api has not correctly resulted in an ENotAnOVirtEngine (%v)", err)
}
}

func TestInvalidCredentials(t *testing.T) {
t.Parallel()
helper, err := ovirtclient.NewLiveTestHelperFromEnv(ovirtclientlog.NewTestLogger(t))
Expand Down
18 changes: 18 additions & 0 deletions test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ type TestHelper interface {

// GetTLS returns the TLS provider used for this test helper.
GetTLS() TLSProvider

// GetUsername returns the oVirt username.
GetUsername() string

// GetPassword returns the oVirt password.
GetPassword() string
}

// MustNewTestHelper is identical to NewTestHelper, but panics instead of returning an error.
Expand Down Expand Up @@ -114,6 +120,8 @@ func NewTestHelper(
}

return &testHelper{
username: username,
password: password,
client: client,
tls: tlsProvider,
clusterID: clusterID,
Expand Down Expand Up @@ -405,6 +413,16 @@ type testHelper struct {
blankTemplateID TemplateID
vnicProfileID string
secondaryStorageDomainID string
password string
username string
}

func (t *testHelper) GetUsername() string {
return t.username
}

func (t *testHelper) GetPassword() string {
return t.password
}

func (t *testHelper) GetSecondaryStorageDomainID(te *testing.T) string {
Expand Down

0 comments on commit 5b92b5b

Please sign in to comment.