-
Notifications
You must be signed in to change notification settings - Fork 5
/
pageant_ssh_test.go
44 lines (40 loc) · 1.27 KB
/
pageant_ssh_test.go
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
// +build sshtest
package pageant
import (
"os"
"testing"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)
// This test requires all of the following to work:
// - build tag sshtest is active
// - environment variable PAGEANT_TEST_SSH_ADDR is set to a valid SSH
// server address (host:port)
// - environment variable PAGEANT_TEST_SSH_USER is set to a user name
// that the SSH server recognizes
// - Pageant is running on the local machine
// - Pageant has a key that is authorized for the user on the server
func TestSSHConnect(t *testing.T) {
pageantConn, err := NewConn()
if err != nil {
t.Fatalf("error on NewConn: %s", err)
}
defer pageantConn.Close()
sshAgent := agent.NewClient(pageantConn)
signers, err := sshAgent.Signers()
if err != nil {
t.Fatalf("cannot obtain signers from SSH agent: %s", err)
}
sshUser := os.Getenv("PAGEANT_TEST_SSH_USER")
config := ssh.ClientConfig{
Auth: []ssh.AuthMethod{ssh.PublicKeys(signers...)},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
User: sshUser,
}
sshAddr := os.Getenv("PAGEANT_TEST_SSH_ADDR")
sshConn, err := ssh.Dial("tcp", sshAddr, &config)
if err != nil {
t.Fatalf("failed to connect to %s@%s due to error: %s", sshUser, sshAddr, err)
}
sshConn.Close()
}