sftptest

package
v0.9.1 Latest Latest
Warning

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

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

Documentation

Overview

Package sftptest is an SSH server with an SFTP subsystem for tests.

It does not implement permissions, quotas, symlink creation limits, fsync, rename, bandwidth shaping beyond SlowData, or SSH rekeying. The file store for ordinary paths is in memory. GenFile and paths under /sink/ are not stored.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenByte

func GenByte(off int64) byte

GenByte is the byte a generated file holds at off.

Types

type Config

type Config struct {
	Users          map[string]string
	AuthorizedKeys map[string][]ssh.PublicKey
	Files          map[string][]byte
	NoPassword     bool
	NoPublicKey    bool
	NoSubsystem    bool
}

Config is the starting state of a server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a fake SFTP server.

func Start

func Start(t *testing.T) *Server

Start listens on 127.0.0.1 and serves SFTP. The default user is load with password secret.

func (*Server) AddRSA

func (s *Server) AddRSA() error

AddRSA adds an RSA host key. Later connections can present it.

func (*Server) Addr

func (s *Server) Addr() string

Addr is host:port.

func (*Server) Apply

func (s *Server) Apply(cfg Config)

Apply replaces users, keys and flags, and writes files.

func (*Server) AuthAttempts

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

AuthAttempts lists the methods the client tried, in order.

func (*Server) AuthDelay

func (s *Server) AuthDelay(d time.Duration)

AuthDelay waits inside the login callbacks.

func (*Server) ClearFaults

func (s *Server) ClearFaults()

ClearFaults releases stalls and turns the knobs off.

func (*Server) Close

func (s *Server) Close()

Close stops the server.

func (*Server) ConnCount

func (s *Server) ConnCount() int

ConnCount is how many TCP connections were accepted.

func (*Server) CorruptByte

func (s *Server) CorruptByte(offset int64)

CorruptByte flips one byte of a read at offset.

func (*Server) Delay

func (s *Server) Delay(d time.Duration)

Delay waits before each operation.

func (*Server) DropOn

func (s *Server) DropOn(op string)

DropOn closes the TCP connection when op runs.

func (*Server) File

func (s *Server) File(p string) ([]byte, bool)

File reads one ordinary file back.

func (*Server) Files

func (s *Server) Files() map[string][]byte

Files returns the ordinary files in the store. Sink and generated files are not included.

func (*Server) GenFile

func (s *Server) GenFile(p string, size int64)

GenFile serves size bytes at path. The bytes are made on each read.

func (*Server) HandshakeDelay

func (s *Server) HandshakeDelay(d time.Duration)

HandshakeDelay waits before the SSH handshake.

func (*Server) HostKeyFingerprint

func (s *Server) HostKeyFingerprint() string

HostKeyFingerprint is the SHA256 fingerprint of the Ed25519 host key.

func (*Server) IdleTimeout

func (s *Server) IdleTimeout(d time.Duration)

IdleTimeout closes a connection that has been idle for d.

func (*Server) MaxConnections

func (s *Server) MaxConnections(n int)

MaxConnections closes the connection after n, during the handshake.

func (*Server) Mkdir

func (s *Server) Mkdir(p string) error

Mkdir creates a directory in the store.

func (*Server) OpenConns

func (s *Server) OpenConns() int

OpenConns is how many TCP connections are open now.

func (*Server) Ops

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

Ops lists "connN op path" lines. It has no passwords.

func (*Server) RSAFingerprint

func (s *Server) RSAFingerprint() string

RSAFingerprint is the SHA256 fingerprint of the RSA host key.

func (*Server) RefuseConnections

func (s *Server) RefuseConnections(on bool)

RefuseConnections closes each new TCP connection at once.

func (*Server) ReplyOn

func (s *Server) ReplyOn(op string, code uint32, text string)

ReplyOn makes op fail with an SFTP status code and text.

func (*Server) Requests

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

Requests lists session requests other than the sftp subsystem.

func (*Server) SinkHash

func (s *Server) SinkHash(p string) (n int64, sum string, ok bool)

SinkHash reports how many bytes were written to a /sink/ path and their SHA-256. ok is false when the path was not a sink.

func (*Server) SlowData

func (s *Server) SlowData(bytesPerSecond int)

SlowData limits a transfer to about bytesPerSecond.

func (*Server) StallAfter

func (s *Server) StallAfter(op string, n int)

StallAfter lets n operations of op succeed, then stalls.

func (*Server) StallOn

func (s *Server) StallOn(op string)

StallOn reads the request and does not answer until ClearFaults.

func (s *Server) Symlink(target, link string) error

Symlink creates a symlink. target is the existing path. link is the new name.

func (*Server) TruncateReadAfter

func (s *Server) TruncateReadAfter(n int64)

TruncateReadAfter fails a read once n bytes have been returned.

func (*Server) URL

func (s *Server) URL() string

URL is an SFTP URL for the default user. It has no password.

Jump to

Keyboard shortcuts

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