Skip to main content

Mock SSH server for testing purposes

Project description

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)
https://travis-ci.org/carletes/mock-ssh-server.svg

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mock-ssh-server-0.5.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

mock_ssh_server-0.5.0-py2-none-any.whl (13.2 kB view details)

Uploaded Python 2

File details

Details for the file mock-ssh-server-0.5.0.tar.gz.

File metadata

File hashes

Hashes for mock-ssh-server-0.5.0.tar.gz
Algorithm Hash digest
SHA256 d0091068bf9ecf492ec79a60eb19688157252536cb0f756b82f4a5b4750726b4
MD5 a0d0c0f114facd52f0ed3635faad1a4a
BLAKE2b-256 d07270fa5deb092a0f1ddf201b74a43a1f81dff2beac93368a041c92be2b8d53

See more details on using hashes here.

File details

Details for the file mock_ssh_server-0.5.0-py2-none-any.whl.

File metadata

File hashes

Hashes for mock_ssh_server-0.5.0-py2-none-any.whl
Algorithm Hash digest
SHA256 56345994853ebd4116d0c17133be59cd694f1592e5be057ef0385ba2500666b1
MD5 83801523118e7c8f16e029e862f8bcd9
BLAKE2b-256 a5ae5de3e3017994503f2dcb06bc54b1d6235c3835c4645c1243310ed74c6626

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page