client_func_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ssh
  5. // ClientConn functional tests.
  6. // These tests require a running ssh server listening on port 22
  7. // on the local host. Functional tests will be skipped unless
  8. // -ssh.user and -ssh.pass must be passed to gotest.
  9. import (
  10. "flag"
  11. "testing"
  12. )
  13. var (
  14. sshuser = flag.String("ssh.user", "", "ssh username")
  15. sshpass = flag.String("ssh.pass", "", "ssh password")
  16. sshprivkey = flag.String("ssh.privkey", "", "ssh privkey file")
  17. )
  18. func TestFuncPasswordAuth(t *testing.T) {
  19. if *sshuser == "" {
  20. t.Log("ssh.user not defined, skipping test")
  21. return
  22. }
  23. config := &ClientConfig{
  24. User: *sshuser,
  25. Auth: []ClientAuth{
  26. ClientAuthPassword(password(*sshpass)),
  27. },
  28. }
  29. conn, err := Dial("tcp", "localhost:22", config)
  30. if err != nil {
  31. t.Fatalf("Unable to connect: %s", err)
  32. }
  33. defer conn.Close()
  34. }
  35. func TestFuncPublickeyAuth(t *testing.T) {
  36. if *sshuser == "" {
  37. t.Log("ssh.user not defined, skipping test")
  38. return
  39. }
  40. kc := new(keychain)
  41. if err := kc.loadPEM(*sshprivkey); err != nil {
  42. t.Fatalf("unable to load private key: %s", err)
  43. }
  44. config := &ClientConfig{
  45. User: *sshuser,
  46. Auth: []ClientAuth{
  47. ClientAuthKeyring(kc),
  48. },
  49. }
  50. conn, err := Dial("tcp", "localhost:22", config)
  51. if err != nil {
  52. t.Fatalf("unable to connect: %s", err)
  53. }
  54. defer conn.Close()
  55. }