mockssh

package
v0.0.0-...-52bc700 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandHandler

type CommandHandler func(conn ssh.ConnMetadata, command string, commandIO CommandIO) int

func ExecHandler

func ExecHandler(workingDir string, env []string) CommandHandler

ExecHandler returns a CommandHandler to execute a command in the given environment.

type CommandIO

type CommandIO struct {
	StdIn  io.Reader
	StdOut io.Writer
	StdErr io.Writer
}

type Server

type Server struct {

	// If CertChecker is nil then a default checker will be used, which checks that the
	// certificate's public key is in CertAuthorityKeys.
	CertAuthorityKeys []ssh.PublicKey
	CertChecker       ssh.CertChecker

	// An optional CommandHandler, which responds to commands sent over SSH.
	// NewServer will give this a default using ExecHandler, which can also
	// be reused from custom handlers.
	CommandHandler CommandHandler

	// SFTPDir enables the SFTP subsystem, with this working directory.
	SFTPDir string

	// DialTCP enables local port forwarding ("direct-tcpip" channels, as with "ssh -L"),
	// by connecting to the requested host and port. Otherwise, forwarding is rejected.
	DialTCP func(host string, port int) (net.Conn, error)

	// ListenUnix enables remote forwarding of Unix sockets (as with "ssh -R /path:host:port"),
	// by listening at the requested path. Otherwise, forwarding is rejected.
	ListenUnix func(path string) (net.Listener, error)
	// contains filtered or unexported fields
}

func NewServer

func NewServer(t *testing.T, authorityEndpoint string) (*Server, error)

NewServer creates and starts a local SSH server for a test. It must be stopped with the Server.Stop method. The authorityEndpoint returns SSH public keys in JSON under the key "authorities".

func (*Server) HostKey

func (s *Server) HostKey() ssh.PublicKey

func (*Server) HostKeyConfig

func (s *Server) HostKeyConfig() string

func (*Server) Port

func (s *Server) Port() int

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server, closes open connections, and waits for their handlers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址