-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver_test.go
More file actions
34 lines (27 loc) · 762 Bytes
/
Copy pathserver_test.go
File metadata and controls
34 lines (27 loc) · 762 Bytes
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
package sshtest_test
import (
"fmt"
"github.com/folbricht/sshtest"
"golang.org/x/crypto/ssh"
)
func ExampleNewUnstartedServer() {
hostKey := sshtest.KeyFromFile("testdata/ssh-host-key", "")
server := sshtest.NewUnstartedServer()
server.Config = &ssh.ServerConfig{NoClientAuth: true}
server.Config.AddHostKey(hostKey)
server.Handler = func(ch ssh.Channel, in <-chan *ssh.Request) {
defer ch.Close()
// Read a request from the client
req, ok := <-in
if !ok {
return
}
fmt.Printf("Received '%s' request from client", req.Type)
// Reply with a string
req.Reply(true, []byte("Hello client"))
// Let the client know the command completed successfuly (status=0)
sshtest.SendStatus(ch, 0)
}
server.Start()
defer server.Close()
}