Documentation
¶
Overview ¶
Package sshtest is an SSH server for tests, in the test's process on 127.0.0.1: it logs in its user by password or by an authorized key, runs commands in /bin/sh (each in a process group of its own, as sshd's sessions run; in a session of its own with a PTY on Linux after a pty-req, a shell too), answers signals and keepalives, serves SFTP from a folder, and forwards: direct-tcpip, direct-streamlocal@openssh.com and tcpip-forward (forwarding.go). NewWindows makes one that answers as Windows's OpenSSH does.
Index ¶
- Constants
- func FakeBecome(t testing.TB, sudoPassword, suPassword string)
- func Silent(t testing.TB) uint64
- func Speaks(t testing.TB, said string) uint64
- type Exec
- type Server
- func (s *Server) AuthorizeKey(key ssh.PublicKey)
- func (s *Server) Credentials() map[string]protocol.Credential
- func (s *Server) Fingerprint() string
- func (s *Server) Host() string
- func (s *Server) PasswordCredential(id, password string) protocol.Credential
- func (s *Server) Port() int
- func (s *Server) Values() map[string]any
Constants ¶
const PasswordID = "pw-1"
PasswordID is the id of the server's password's credential.
const WindowsVersion = "SSH-2.0-OpenSSH_for_Windows_9.5"
WindowsVersion is the version Windows's OpenSSH says.
Variables ¶
This section is empty.
Functions ¶
func FakeBecome ¶ added in v0.5.0
FakeBecome puts fake sudo, su and script first on the test's PATH, which the server's commands run with: sudo asks for sudoPassword (none with FAKE_NOPASSWD set), su for suPassword, both then running the command as the test's user.
Types ¶
type Exec ¶ added in v0.2.0
Exec runs a command as a test's Windows server runs it: its output to out and errOut, its exit status returned. Its ctx ends on a signal, on which Windows's OpenSSH ends all the command started, and when the test ends; a channel closing alone leaves it running, as on Windows.
type Server ¶
type Server struct {
// User and Password log in; so does a key AuthorizeKey adds.
User, Password string
// Dir is where SFTP starts and commands run.
Dir string
HostKey ssh.Signer
// Stall leaves the channels opened from now on unanswered, neither
// accepted nor refused: a server gone quiet under an open.
Stall atomic.Bool
// Signals counts the signals commands got.
Signals atomic.Int32
// NoForward refuses every forward, as AllowTcpForwarding no does;
// NoPTY every pty-req (the session runs on pipes); NoUnix every unix
// socket's (direct-streamlocal: a server without it says an unknown
// channel type).
NoForward, NoPTY, NoUnix atomic.Bool
// Size is the last size a session's terminal was given (pty-req,
// window-change), rows and cols.
Size atomic.Value
// contains filtered or unexported fields
}
Server is a running SSH server.
func NewWindows ¶ added in v0.2.0
NewWindows starts a server that answers as Windows's OpenSSH does: its version says so, its SFTP's root lists one drive, C:, which is dir, and SFTP starts in C:\Users\<user> (made in dir); a link to a folder reads as the folder it points to, as a junction does over Windows's SFTP, and a read-only file (no owner's write bit) is not removed. Its commands are exec's: it runs no shell.
func (*Server) AuthorizeKey ¶
AuthorizeKey lets key log in as the user.
func (*Server) Credentials ¶ added in v0.4.0
func (s *Server) Credentials() map[string]protocol.Credential
Credentials are what core gives beside Values: the server's user and password, a PLAINTEXT credential.
func (*Server) Fingerprint ¶
Fingerprint is the server's host key's, as ssh-keygen -l prints it.
func (*Server) PasswordCredential ¶ added in v0.4.0
func (s *Server) PasswordCredential(id, password string) protocol.Credential
PasswordCredential is a PLAINTEXT credential of the server's user, with password.