sshtest

package
v0.107.34 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sshtest runs an SSH server inside the test process, on 127.0.0.1, for SSHManager tests. It logs users in with a password, a public key or keyboard-interactive questions, answers "exec" with a tiny built-in command set, echoes a PTY shell's input and serves SFTP from memory. It never runs a real command and never touches the real filesystem, so the tests behave the same on every OS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHostKey

func NewHostKey(t testing.TB) ssh.Signer

NewHostKey returns a fresh ed25519 host key.

Types

type Config

type Config struct {
	User string
	// Password, when set, is accepted by password logins.
	Password string
	// Questions, when set, are asked in one keyboard-interactive round.
	Questions []Question
	// PublicKey accepts logins with ClientKey.
	PublicKey bool
}

Config sets how the server logs users in.

type Question

type Question struct {
	Prompt string
	Echo   bool
	Answer string
}

Question is one keyboard-interactive prompt and the answer it expects.

type Server

type Server struct {
	Host string
	Port int
	User string
	// ClientKey is the key PublicKey logins accept; ClientKeyPEM is its
	// unencrypted OpenSSH private key.
	ClientKey    ed25519.PrivateKey
	ClientKeyPEM []byte
	// contains filtered or unexported fields
}

Server is a running test server.

func New

func New(t testing.TB, cfg Config) *Server

New starts a server and stops it when t ends.

func (*Server) Address

func (s *Server) Address() string

Address is host:port.

func (*Server) AuthTries

func (s *Server) AuthTries() []string

AuthTries lists the auth methods clients tried, in order.

func (*Server) BlockReads

func (s *Server) BlockReads() (blocked <-chan struct{}, release func())

BlockReads makes SFTP file reads wait until release is called; blocked is closed once a read is waiting.

func (*Server) Close

func (s *Server) Close()

Close stops the server and every connection.

func (*Server) Connections

func (s *Server) Connections() int

Connections counts open connections.

func (*Server) DropConnections

func (s *Server) DropConnections()

DropConnections closes every open connection, as a server restart would.

func (*Server) EncryptedClientKey

func (s *Server) EncryptedClientKey(t testing.TB, passphrase string) []byte

EncryptedClientKey returns ClientKey as an OpenSSH private key encrypted with passphrase.

func (*Server) Execs

func (s *Server) Execs() []string

Execs lists the exec commands received, as sent.

func (*Server) HostKey

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

HostKey is the key the server presents.

func (*Server) Logins

func (s *Server) Logins() int

Logins counts successful logins.

func (*Server) PTYs

func (s *Server) PTYs() [][2]int

PTYs lists the cols x rows of every PTY requested.

func (*Server) Resizes

func (s *Server) Resizes() [][2]int

Resizes lists every window change, cols x rows.

func (*Server) SetHostKey

func (s *Server) SetHostKey(key ssh.Signer)

SetHostKey makes later connections present key.

func (*Server) Signals

func (s *Server) Signals() []string

Signals lists the signals clients sent to commands.

Jump to

Keyboard shortcuts

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