testsrv

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package testsrv 提供离线测试用的 mock 服务(SSH/Telnet/SFTP),不引入任何外部依赖。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SshServer

type SshServer struct {
	Addr     string
	User     string
	Password string
	Banner   string
	Prompt   string
	// HostKey 服务端公钥串(keytype + base64),用于生成 known_hosts 行
	HostKey string
	// Session 自定义会话行为(stdin 读取命令、stdout 写入输出);nil 时使用默认回显行为
	Session func(s *SshSession)
	// RootDir SFTP 子系统的根目录(为空时不启用 SFTP)
	RootDir string
	// contains filtered or unexported fields
}

SshServer 模拟 SSH 服务端(基于 golang.org/x/crypto/ssh 服务端实现,零外部依赖):

密码认证 + PTY + 交互式 shell + SFTP 子系统。

func NewSshServer

func NewSshServer(t *testing.T) *SshServer

NewSshServer 启动 mock SSH 服务;测试结束后自动关闭。

type SshSession

type SshSession struct {
	Stdin  io.Reader
	Stdout io.Writer
}

SshSession 会话的输入输出

type TelnetServer

type TelnetServer struct {
	Addr     string
	Welcome  string
	User     string
	Password string
	Prompt   string
	// UserPrompt/PassPrompt 自定义登录提示符(空则用默认 "Login:"/"Password:"),
	//	用于模拟非标设备的登录提示符
	UserPrompt string
	PassPrompt string
	// contains filtered or unexported fields
}

TelnetServer 模拟网络设备的 telnet 服务:IAC 协商 + 用户名/密码认证 + 命令回显。

func NewTelnetServer

func NewTelnetServer(t *testing.T, authMode string) *TelnetServer

NewTelnetServer 启动 mock telnet 服务;测试结束后自动关闭。

authMode: "password" 仅密码认证(直接提示 Password:);"user" 先提示用户名再提示密码。
密码错误时重新提示(最多2次),用于验证客户端的认证失败错误。

Jump to

Keyboard shortcuts

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