feat(client): Add ssh private-key support (#1390)
* feat(endpoint): Add ssh key support Fixes #1257 * test(config): Add tests for private key config --------- Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSSH_validate(t *testing.T) {
|
||||
func TestSSH_validatePasswordCfg(t *testing.T) {
|
||||
cfg := &Config{}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Error("didn't expect an error")
|
||||
@@ -13,11 +13,26 @@ func TestSSH_validate(t *testing.T) {
|
||||
cfg.Username = "username"
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Error("expected an error")
|
||||
} else if !errors.Is(err, ErrEndpointWithoutSSHPassword) {
|
||||
t.Errorf("expected error to be '%v', got '%v'", ErrEndpointWithoutSSHPassword, err)
|
||||
} else if !errors.Is(err, ErrEndpointWithoutSSHAuth) {
|
||||
t.Errorf("expected error to be '%v', got '%v'", ErrEndpointWithoutSSHAuth, err)
|
||||
}
|
||||
cfg.Password = "password"
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Errorf("expected no error, got '%v'", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSSH_validatePrivateKeyCfg(t *testing.T) {
|
||||
t.Run("fail when username missing but private key provided", func(t *testing.T) {
|
||||
cfg := &Config{PrivateKey: "-----BEGIN"}
|
||||
if err := cfg.Validate(); !errors.Is(err, ErrEndpointWithoutSSHUsername) {
|
||||
t.Fatalf("expected ErrEndpointWithoutSSHUsername, got %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("success when username with private key", func(t *testing.T) {
|
||||
cfg := &Config{Username: "user", PrivateKey: "-----BEGIN"}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user