aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/exp/ssh/client_func_test.go
blob: b4bdba95396bcc64c83e33482bd2ef337dff3bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ssh

// ClientConn functional tests.
// These tests require a running ssh server listening on port 22
// on the local host. Functional tests will be skipped unless
// -ssh.user and -ssh.pass must be passed to gotest.

import (
	"flag"
	"testing"
)

var (
	sshuser    = flag.String("ssh.user", "", "ssh username")
	sshpass    = flag.String("ssh.pass", "", "ssh password")
	sshprivkey = flag.String("ssh.privkey", "", "ssh privkey file")
)

func TestFuncPasswordAuth(t *testing.T) {
	if *sshuser == "" {
		t.Log("ssh.user not defined, skipping test")
		return
	}
	config := &ClientConfig{
		User: *sshuser,
		Auth: []ClientAuth{
			ClientAuthPassword(password(*sshpass)),
		},
	}
	conn, err := Dial("tcp", "localhost:22", config)
	if err != nil {
		t.Fatalf("Unable to connect: %s", err)
	}
	defer conn.Close()
}

func TestFuncPublickeyAuth(t *testing.T) {
	if *sshuser == "" {
		t.Log("ssh.user not defined, skipping test")
		return
	}
	kc := new(keychain)
	if err := kc.loadPEM(*sshprivkey); err != nil {
		t.Fatalf("unable to load private key: %s", err)
	}
	config := &ClientConfig{
		User: *sshuser,
		Auth: []ClientAuth{
			ClientAuthKeyring(kc),
		},
	}
	conn, err := Dial("tcp", "localhost:22", config)
	if err != nil {
		t.Fatalf("unable to connect: %s", err)
	}
	defer conn.Close()
}