diff --git a/plugin.go b/plugin.go index 40bcce8..6be2781 100644 --- a/plugin.go +++ b/plugin.go @@ -161,6 +161,10 @@ func (p *Plugin) Exec() error { return errors.New("missing ssh config (Host, Username)") } + if len(p.Config.Password) != 0 || len(p.Config.Key) != 0 { + return errors.New("can't set password and key at the same time") + } + if len(p.Config.Source) == 0 || len(p.Config.Target) == 0 { return errors.New("missing source or target config") } diff --git a/plugin_test.go b/plugin_test.go index 036572c..2218116 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -47,6 +47,23 @@ func TestMissingSourceConfig(t *testing.T) { assert.NotNil(t, err) } +func TestSetPasswordAndKey(t *testing.T) { + plugin := Plugin{ + Config: Config{ + Host: []string{"example.com"}, + Username: "ubuntu", + Port: "443", + Password: "1234", + Key: "test", + }, + } + + err := plugin.Exec() + + assert.NotNil(t, err) + assert.Equal(t, "can't set password and key at the same time", err.Error()) +} + func TestTrimElement(t *testing.T) { var input, result []string