sshtest

package module
v0.0.0-...-0a185de Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Golang SSH Test Rig

This is inspired by the httptest package and provides a simple rig to test SSH libraries. It starts a local server, that can be configured to a certain extent.

A word of warning: This is more of an experiment, than something I'd use in production. At least not without some proper review and some major refinements.

And a note on closing sessions: usually that is done by the server after the command exited. This in turn means, that a client, gracefully closing the session will receive an io.EOF error.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandleFunc

type HandleFunc func(cmd string, args []string, stdin io.Reader, stdout, stderr io.Writer) (rVal int)

HnadleFunc is a handler of the sshtest server. Needs to be registered for a command (see RegisterHandler).

type Option

type Option func(*sshCfg) error

Option is used to modify the ssh server behavior.

func WithAddr

func WithAddr(addr string) Option

WithAddr sets the address of the test ssh server.

func WithPasswordCallback

func WithPasswordCallback(f func(ssh.ConnMetadata, []byte) (*ssh.Permissions, error)) Option

WithPasswordCallback sets a callback used to test a user supplied password.

func WithPasswordCallbackForUser

func WithPasswordCallbackForUser(user, password string) Option

WithPasswordCallbackForUser sets a callback that grants the given user with the given password access.

func WithPort

func WithPort(port int) Option

WithPort changes the port from the default of 22.

func WithPublicKeyCallback

func WithPublicKeyCallback(f func(ssh.ConnMetadata, ssh.PublicKey) (*ssh.Permissions, error)) Option

WithPublicKeyCallback sets a callback used to authenticate a user via a public key.

type Server

type Server struct {
	Addr string
	Port int
	// contains filtered or unexported fields
}

Server is the SSH serving thing.

func NewServer

func NewServer(opts ...Option) (*Server, error)

NewServer starts the sshtest server.

func (*Server) CheckHostKey

func (ss *Server) CheckHostKey(hostname string, remote net.Addr, key ssh.PublicKey) error

Use this function with your client to check the servers host key.

func (*Server) Close

func (ss *Server) Close() error

Close the server.

func (*Server) RegisterHandler

func (ss *Server) RegisterHandler(cmd string, f HandleFunc)

RegisterHandler will invoke the given function if the first field of the command to be executed matches the `cmd` string.

func (*Server) Start

func (ss *Server) Start() error

Listen starts a SSH server listens on given port.

Jump to

Keyboard shortcuts

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