From a23897f52de7f7010920dbbd752d4e62f13a40c7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 5 Jun 2013 23:05:39 -0700 Subject: [PATCH] communicator/ssh: Add type for static passwords --- communicator/ssh/password.go | 9 +++++++++ communicator/ssh/password_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 communicator/ssh/password.go create mode 100644 communicator/ssh/password_test.go diff --git a/communicator/ssh/password.go b/communicator/ssh/password.go new file mode 100644 index 000000000..8253985b8 --- /dev/null +++ b/communicator/ssh/password.go @@ -0,0 +1,9 @@ +package ssh + +// An implementation of ssh.ClientPassword so that you can use a static +// string password for the password to ClientAuthPassword. +type Password string + +func (p Password) Password(user string) (string, error) { + return string(p), nil +} diff --git a/communicator/ssh/password_test.go b/communicator/ssh/password_test.go new file mode 100644 index 000000000..87de99edb --- /dev/null +++ b/communicator/ssh/password_test.go @@ -0,0 +1,26 @@ +package ssh + +import ( + "code.google.com/p/go.crypto/ssh" + "testing" +) + +func TestPassword_Impl(t *testing.T) { + var raw interface{} + raw = Password("foo") + if _, ok := raw.(ssh.ClientPassword); !ok { + t.Fatal("Password must implement ClientPassword") + } +} + +func TestPasswordPassword(t *testing.T) { + p := Password("foo") + result, err := p.Password("user") + if err != nil { + t.Fatalf("err not nil: %s", err) + } + + if result != "foo" { + t.Fatalf("invalid password: %s", result) + } +}