Skip to content

Instantly share code, notes, and snippets.

@Bluehorn
Last active December 26, 2015 09:19
Show Gist options
  • Save Bluehorn/7128643 to your computer and use it in GitHub Desktop.
Save Bluehorn/7128643 to your computer and use it in GitHub Desktop.

Trivial test for paramiko issue #22

This demonstrates issue #22. For this to expose the problem, you have to reconfigure your local sshd to listen only on a IPv4 socket. I had to add the following line to /etc/ssh/sshd_config (on a Debian system):

ListenAddress 0.0.0.0

With that change, paramiko can not connect to localhost anymore:

>>> import paramiko
>>> client = paramiko.SSHClient()
>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> client.connect("localhost")

This lead to the following traceback:

Traceback (most recent call last):
  File "/usr/lib/python2.7/doctest.py", line 1289, in __run
    compileflags, 1) in test.globs
  File "<doctest issue22.rst[3]>", line 1, in <module>
    client.connect("localhost")
  File "paramiko/client.py", line 305, in connect
    retry_on_signal(lambda: sock.connect(addr))
  File "paramiko/util.py", line 278, in retry_on_signal
    return function()
  File "paramiko/client.py", line 305, in <lambda>
    retry_on_signal(lambda: sock.connect(addr))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 111] Connection refused

You can check that this is fixed by running the following command from the shell:

$ python -m doctest -v Issue22.rst

With the commit 27b800bf3f1c0ee7063221538d2913cec7c048c1 this gives the following output here:

torsten@pulsar:~/workspace/paramiko$ python -m doctest -v Issue22.rst
Trying:
    import paramiko
Expecting nothing
ok
Trying:
    client = paramiko.SSHClient()
Expecting nothing
ok
Trying:
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
Expecting nothing
ok
Trying:
    client.connect("localhost")
Expecting nothing
ok
1 items passed all tests:
   4 tests in Issue22.rst
4 tests in 1 items.
4 passed and 0 failed.
Test passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment