Skip to content

folbricht/sshtest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sshtest

sshtest is a set of utilities for testing SSH features in Go. It currently supports quick setup and start of SSH servers to test a client against. To minimize the need for error handling in tests, most functions panic on error.

Examples

Start a simple SSH server with host key

hostKey := sshtest.KeyFromFile("ssh-host-key", "")
server := sshtest.NewServer(hostKey)
defer server.Close()

Start an SSH server with host key and certificate

hostKey := sshtest.KeyFromFile("ssh-host-key", "ssh-host-key-cert.pub")
server := sshtest.NewServer(hostKey)
defer server.Close()

SSH server with custom server config and handler

hostKey := sshtest.KeyFromFile("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()

Links

Packages

No packages published

Languages