communicator/ssh: Add type for static passwords
This commit is contained in:
parent
aee611db4f
commit
a23897f52d
|
@ -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
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue