OSDN Git Service

libgo: Update to weekly.2011-12-14.
[pf3gnuchains/gcc-fork.git] / libgo / go / exp / ssh / client_func_test.go
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
5 package ssh
6
7 // ClientConn functional tests.
8 // These tests require a running ssh server listening on port 22
9 // on the local host. Functional tests will be skipped unless
10 // -ssh.user and -ssh.pass must be passed to gotest.
11
12 import (
13         "flag"
14         "testing"
15 )
16
17 var (
18         sshuser    = flag.String("ssh.user", "", "ssh username")
19         sshpass    = flag.String("ssh.pass", "", "ssh password")
20         sshprivkey = flag.String("ssh.privkey", "", "ssh privkey file")
21 )
22
23 func TestFuncPasswordAuth(t *testing.T) {
24         if *sshuser == "" {
25                 t.Log("ssh.user not defined, skipping test")
26                 return
27         }
28         config := &ClientConfig{
29                 User: *sshuser,
30                 Auth: []ClientAuth{
31                         ClientAuthPassword(password(*sshpass)),
32                 },
33         }
34         conn, err := Dial("tcp", "localhost:22", config)
35         if err != nil {
36                 t.Fatalf("Unable to connect: %s", err)
37         }
38         defer conn.Close()
39 }
40
41 func TestFuncPublickeyAuth(t *testing.T) {
42         if *sshuser == "" {
43                 t.Log("ssh.user not defined, skipping test")
44                 return
45         }
46         kc := new(keychain)
47         if err := kc.loadPEM(*sshprivkey); err != nil {
48                 t.Fatalf("unable to load private key: %s", err)
49         }
50         config := &ClientConfig{
51                 User: *sshuser,
52                 Auth: []ClientAuth{
53                         ClientAuthPublickey(kc),
54                 },
55         }
56         conn, err := Dial("tcp", "localhost:22", config)
57         if err != nil {
58                 t.Fatalf("unable to connect: %s", err)
59         }
60         defer conn.Close()
61 }