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.4.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

mock_ssh_server-0.4.0-py2.py3-none-any.whl (12.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for mock-ssh-server-0.4.0.tar.gz
Algorithm Hash digest
SHA256 666c2e46606a023a282bb4145b944a52a38c466881629279422ef3c6c225e958
MD5 3036ca5cfc9f2b07be11104a9522e771
BLAKE2b-256 98b4e112a23677b19ed349d317bf6478cbdb42003e1138bc0d5093687fad3e40

See more details on using hashes here.

Provenance

File details

Details for the file mock_ssh_server-0.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for mock_ssh_server-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f59a9d18388ed3fb6e954f6c0cb59f2820bf6c719ff9da9b3432e1a4d8257f1f
MD5 882d08386cbffbe3b4f5c8e65085731d
BLAKE2b-256 e53b08a26fb61e13ea0dda49358dea51717822c3b80d852a94f0b3ba562a8754

See more details on using hashes here.

Provenance

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