为了测试目的,模拟SSH服务器

[英]Emulate SSH server for testing purposes


I have to write test for deployment script which uploads files through SSH, but I'd like to have it not depending on external servers configuration. This is how i see it:

我必须为部署脚本编写测试,该脚本通过SSH上传文件,但我希望它不依赖于外部服务器配置。我是这样看的:

  1. Create 2 SSH daemons without authentication on different ports of loopback interface.
  2. 在loopback接口的不同端口上创建两个没有身份验证的SSH守护进程。
  3. Run the deployment script on these two ports
  4. 在这两个端口上运行部署脚本

The only question is how to run these dummy SSH daemons.

唯一的问题是如何运行这些虚拟SSH守护进程。

I use Python and Fabric.

我使用Python和Fabric。

2 个解决方案

#1


6  

If you want full control over the server's actions (e.g. in order to simulate various problem conditions and thereby do a really thorough testing) I recommend twisted: as this article shows, it makes it really easy to set up your own custom SSH server.

如果您希望完全控制服务器的操作(例如,为了模拟各种问题条件,从而进行真正彻底的测试),我建议twisted:正如本文所示,它使您很容易建立自己的自定义SSH服务器。

If you'd rather use an existing ssh server, pick one from the list here (or use the one that comes with your system, if any; or maybe sshwindows if you're on windows) and run it with subprocess from Python as a part of starting up your tests.

如果您希望使用现有的ssh服务器,请从这里的列表中选择一个(或者使用系统附带的服务器,如果有的话;或者,如果您在windows上,也可以使用sshwindows)并使用Python的子进程运行它,作为启动测试的一部分。

#2


1  

Reimplementing an SSH daemon is not trivial.

重新实现SSH守护进程并非易事。

If your only problem is you don't want them depending on existing configurations, you can start up new sshd with -f to specify a specific configuration and -p to run on a given port.

如果您唯一的问题是您不希望它们依赖于现有的配置,您可以使用-f启动新的sshd,以指定在给定端口上运行的特定配置和-p。

You can use os.system to make calls to the shell:

您可以使用操作系统。系统调用shell:

os.system('sshd -f myconfig -p 22022')

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2010/07/06/3a7987821b9d99ff1326a984c0e1daed.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号