-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathforward_test.go
66 lines (54 loc) · 1.16 KB
/
forward_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package sshlib
import (
"log"
"testing"
"golang.org/x/crypto/ssh"
)
func TestGetDisplay(t *testing.T) {
for _, tc := range []struct {
expect int
input string
}{
{0, ":0.0"},
{123, ":123.0"},
{123, ":123"},
{0, "xxx"},
{11, "localhost:11.0"},
{123, "randomhost:123.0"},
} {
if act := getX11DisplayNumber(tc.input); act != tc.expect {
t.Errorf(`unexpected result for getX11Display("%s"), act="%v", exp="%v"`, tc.input, act, tc.expect)
}
}
}
func ExampleConnect_TCPForward() {
// host
host := "target.com"
port := "22"
user := "user"
key := "~/.ssh/id_rsa"
// port forwarding
localAddr := "localhost:10022"
remoteAddr := "localhost:22"
// Create ssh.AuthMethod
authMethod, _ := CreateAuthMethodPublicKey(key, "")
// Create sshlib.Connect
con := &Connect{}
// PortForward
con.TCPLocalForward(localAddr, remoteAddr)
// Connect ssh server
con.CreateClient(host, user, port, []ssh.AuthMethod{authMethod})
}
func TestConnect_X11Forward() {
// Create session
con := &Connect{}
session, err := con.CreateSession()
if err != nil {
return
}
// X11 forwarding
err = con.X11Forward(session)
if err != nil {
log.Fatal(err)
}
}