communicator/ssh: Add type for static passwords

This commit is contained in:
Mitchell Hashimoto 2013-06-05 23:05:39 -07:00
parent aee611db4f
commit a23897f52d
2 changed files with 35 additions and 0 deletions

View File

@ -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
}

View File

@ -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)
}
}