diff --git a/errors.go b/errors.go index 790e5f6..33164c1 100644 --- a/errors.go +++ b/errors.go @@ -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"): diff --git a/new_test.go b/new_test.go index 40b93e0..d316fd0 100644 --- a/new_test.go +++ b/new_test.go @@ -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)) diff --git a/test_helper.go b/test_helper.go index 66c6f2d..89287d9 100644 --- a/test_helper.go +++ b/test_helper.go @@ -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. @@ -114,6 +120,8 @@ func NewTestHelper( } return &testHelper{ + username: username, + password: password, client: client, tls: tlsProvider, clusterID: clusterID, @@ -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 {