Mock SSH server for testing purposes
Project Links
Meta
Author: Carlos Valiente
Classifiers
Development Status
- 4 - Beta
Environment
- Console
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Operating System
- OS Independent
Topic
- Software Development :: Testing
Programming Language
- Python :: 2.7
- Python :: 3.5
- Python :: 3.6
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
mock-ssh-server packs a Python context manager that implements an SSH server for testing purposes. It is built on top of paramiko, so it does not need OpenSSH binaries to be installed.
Sample usage
As a py.test fixture:
import os from pytest import yield_fixture import mockssh @yield_fixture() def server(): users = { "sample-user": "/path/to/user-private-key", } with mockssh.Server(users) as s: yield s def test_ssh_session(server): for uid in server.users: with server.client(uid) as c: _, stdout, _ = c.exec_command("ls /") assert stdout.read() def test_sftp_session(server): for uid in server.users: target_dir = tempfile.mkdtemp() target_fname = os.path.join(target_dir, "foo") assert not os.access(target_fname, os.F_OK) with server.client(uid) as c: sftp = c.open_sftp() sftp.put(__file__, target_fname, confirm=True) assert os.access(target_fname, os.F_OK)
Sep 13, 2021
0.9.1
Feb 28, 2021
0.9.0
Jun 09, 2020
0.8.2
Mar 26, 2020
0.8.1
Nov 20, 2019
0.8.0
Nov 18, 2019
0.7.0
Sep 07, 2019
0.6.0
Feb 07, 2018
0.5.0
Feb 06, 2018
0.4.0
Aug 01, 2017
0.3.0
Jan 29, 2016
0.2.0
Jan 28, 2016
0.1.0