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

Uploaded Source

Built Distribution

mock_ssh_server-0.9.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mock-ssh-server-0.9.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for mock-ssh-server-0.9.0.tar.gz
Algorithm Hash digest
SHA256 f13e7ffb3d70caeb605c5bdd7990cd59d43005ceff61f2903531fd4ed7985c7f
MD5 decd7126701a5c21658d655217286725
BLAKE2b-256 8263337fcfab5c4bb61928786cfb92e4146ee1276d7565d6dbeed92ae1505fc6

See more details on using hashes here.

File details

Details for the file mock_ssh_server-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: mock_ssh_server-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for mock_ssh_server-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72ccdbe96f302a4b0585947f3b18f40821cc2d95abc66817a981c558951d21db
MD5 071b232cc7683f1172c185e193a6d760
BLAKE2b-256 bb52e68f3f8d147a2d38f11a565686c81cce7d33bbdd375c15636337fbd2cdb1

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