Skip to content

Commit

Permalink
🧹 test ssh errors (#3140)
Browse files Browse the repository at this point in the history
* 🧹 refactor os connection types
* 🧹 test ssh errors
  • Loading branch information
chris-rock authored Jan 29, 2024
1 parent 2c73f3f commit b7e5a59
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions providers/os/connection/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}

0 comments on commit b7e5a59

Please sign in to comment.