伪造SSH服务器
fake-ssh的Python项目详细描述
模拟SSH服务器
你。。。在
- 在
有一个SSHs到服务器的测试,不想设置一个测试的麻烦?在
在 - 在
你觉得恶作剧不像听起来那么好?在
在 - 在
想开发一个应用程序,需要一个假服务器来返回预定义的结果?在
在
这个包裹是给你的!在
安装
pip install fake-ssh
使用
阻止服务器
阻塞服务器通常用于开发目的。在
只需为自己编写一个server.py
文件:
然后运行它:
$ python3 server.py
在单独的终端中,运行:
$ ssh root@127.0.0.1 -p 5050 echo 42
42
$ ssh root@127.0.0.1 -p 5050 ls
file1
file2
(如果系统提示您输入密码,您可以将其留空)
无阻塞服务器
测试中经常使用非阻塞服务器。在
此服务器在线程中运行,允许您并行运行一些测试。在
importparamikoimportpytestfromfake_sshimportServerdefhandler(command):ifcommand=="ls":return"file1\nfile2\n"@pytest.fixturedefserver():withServer(command_handler=handler)asserver:yieldserver@pytest.fixturedefclient(server):c=paramiko.SSHClient()c.set_missing_host_key_policy(paramiko.AutoAddPolicy())c.connect(hostname=server.host,port=server.port,username="root",password="",allow_agent=False,look_for_keys=False)returncdeftest_ls(client):_stdin,stdout,stderr=client.exec_command("ls")assertstdout.read().decode()=="file1\nfile2\n"
- 项目
标签: