镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

About

Python mock SSH server for testing purposes

Topics

Resources

Stars

56 stars

Watchers

8 watching

Forks

Latest commit

 

History

60 Commits

Folders and files

Repository files navigation

mock-ssh-server - An SSH server for testing purposes

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)

User configuration

  • Simple string (backward compatible): "username": "/path/to/private/key"
  • Key-based with explicit type: "username": {"type": "key", "private_key_path": "/path/to/key", "key_type": "ssh-rsa"}
  • Password-based: "username": {"type": "password", "password": "mypassword"}

About

Python mock SSH server for testing purposes

Topics

Resources

Stars

56 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages