From 721e3efdfd8052ac8715aae2bf3ffa8eba0ec105 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Sat, 27 Jan 2024 14:53:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20test=20ssh=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/os/connection/ssh_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/providers/os/connection/ssh_test.go b/providers/os/connection/ssh_test.go index 000e396d44..cafbfcba68 100644 --- a/providers/os/connection/ssh_test.go +++ b/providers/os/connection/ssh_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v10/providers/os/connection/shared" ) func TestSSHDefaultSettings(t *testing.T) { @@ -22,3 +23,17 @@ func TestSSHDefaultSettings(t *testing.T) { assert.Equal(t, int32(22), conn.conf.Port) assert.Equal(t, "sudo", conn.conf.Sudo.Executable) } + +func TestSSHProviderError(t *testing.T) { + _, err := NewSshConnection(0, &inventory.Config{Type: shared.Type_Local.String(), Host: "example.local"}, nil) + assert.Equal(t, "provider type does not match", err.Error()) +} + +func TestSSHAuthError(t *testing.T) { + _, err := NewSshConnection(0, &inventory.Config{Type: shared.Type_SSH.String(), Host: "example.local"}, nil) + assert.True(t, + // local testing if ssh agent is available + err.Error() == "dial tcp: lookup example.local: no such host" || + // local testing without ssh agent + err.Error() == "no authentication method defined") +}