This release is a pre-release and may not be stable for production use.
Mock SSH Server
Do you...
-
have a test that SSHs into a server and don't want the hassle of setting one up for testing?
-
think monkeypatching isn't as good as it sounds?
-
want to develop an application and need a fake server to return predefined results?
This package is for you!
Installation
pip install fake-ssh
Usage
Blocking Server
A blocking server is often used for development purposes.
Simply write yourself a server.py file:
from typing import Optional
from fake_ssh import Server
def handler(command: str) -> Optional[str]:
if command.startswith("ls"):
return "file1\nfile2\n"
elif command.startswith("echo"):
return command[4:].strip() + "\n"
if __name__ == "__main__":
Server(command_handler=handler, port=5050).run_blocking()
And run it:
$ python3 server.py
In a separate terminal, run:
$ ssh root@127.0.0.1 -p 5050 echo 42
42
$ ssh root@127.0.0.1 -p 5050 ls
file1
file2
(if you are prompted for a password, you can leave it blank)
Note how you need to specify a non standard port (5050). Using the standard port (22) would require root permissions and is probably unsafe.
Non-Blocking Server
A non blocking server is often used in tests.
This server runs in a thread and allows you to run some tests in parallel.
import paramiko
import pytest
from fake_ssh import Server
def handler(command):
if command == "ls":
return "file1\nfile2\n"
@pytest.fixture
def server():
with Server(command_handler=handler) as server:
yield server
def my_ls(host, port):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=host,
port=port,
username="root",
password="",
allow_agent=False,
look_for_keys=False)
return c.exec_command("ls")[1].read().decode().splitlines()
def test_ls(server):
assert my_ls(server.host, server.port) == ["file1", "file2"]
Metadata
Release files for fake-ssh 0.1.0a5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fake-ssh-0.1.0a5.tar.gz | 7.7 kB | Without provenance | Details for fake-ssh-0.1.0a5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fake_ssh-0.1.0a5-py3-none-any.whl | Python 3 | none | any | Details for fake_ssh-0.1.0a5-py3-none-any.whl |
Total release size: 16.0 kB
Release files / fake-ssh-0.1.0a5.tar.gz
| Download URL | fake-ssh-0.1.0a5.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8bc36bae2bd833d976c911c05f5acebc91514b6afc3bf0122b292c1bb2feb57
|
|
BLAKE2b-256 checksum How to use checksums |
b353ce220efe2b5de1b358f97cbf0ebc34d9b90066a9714b3c0549bd05905c2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Release files / fake_ssh-0.1.0a5-py3-none-any.whl
| Download URL | fake_ssh-0.1.0a5-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3868535e685467983fafa4370903ffc3079e5b468ec27eb4ab90ef7c85959171
|
|
BLAKE2b-256 checksum How to use checksums |
49757cb3320fef61a29e5a3ac2e59a2bfd6615d730b7b14160b4e4b6dd88150f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
|
Security for fake-ssh 0.1.0a5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.