summaryrefslogtreecommitdiff
path: root/tests/test_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_client.py')
-rw-r--r--tests/test_client.py47
1 files changed, 41 insertions, 6 deletions
diff --git a/tests/test_client.py b/tests/test_client.py
index cb578394..f87c2692 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -34,8 +34,8 @@ import weakref
from tempfile import mkstemp
import paramiko
-from paramiko.py3compat import PY2, b
-from paramiko.ssh_exception import SSHException
+from paramiko.common import PY2
+from paramiko.ssh_exception import SSHException, AuthenticationException
from .util import _support, slow
@@ -44,6 +44,7 @@ FINGERPRINTS = {
"ssh-dss": b"\x44\x78\xf0\xb9\xa2\x3c\xc5\x18\x20\x09\xff\x75\x5b\xc1\xd2\x6c",
"ssh-rsa": b"\x60\x73\x38\x44\xcb\x51\x86\x65\x7f\xde\xda\xa2\x2b\x5a\x57\xd5",
"ecdsa-sha2-nistp256": b"\x25\x19\xeb\x55\xe6\xa1\x47\xff\x4f\x38\xd2\x75\x6f\xa5\xd5\x60",
+ "ssh-ed25519": b'\xb3\xd5"\xaa\xf9u^\xe8\xcd\x0e\xea\x02\xb9)\xa2\x80',
}
@@ -61,6 +62,9 @@ class NullServer(paramiko.ServerInterface):
def check_auth_password(self, username, password):
if (username == "slowdive") and (password == "pygmalion"):
return paramiko.AUTH_SUCCESSFUL
+ if (username == "slowdive") and (password == "unresponsive-server"):
+ time.sleep(5)
+ return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
def check_auth_publickey(self, username, key):
@@ -203,6 +207,9 @@ class SSHClientTest(unittest.TestCase):
"""
self._test_connection(key_filename=_support("test_ecdsa_256.key"))
+ def test_client_ed25519(self):
+ self._test_connection(key_filename=_support("test_ed25519.key"))
+
def test_3_multiple_key_files(self):
"""
verify that SSHClient accepts and tries multiple key files.
@@ -391,7 +398,19 @@ class SSHClientTest(unittest.TestCase):
)
self._test_connection(**kwargs)
- def test_9_auth_trickledown_gsskex(self):
+ def test_9_auth_timeout(self):
+ """
+ verify that the SSHClient has a configurable auth timeout
+ """
+ # Connect with a half second auth timeout
+ self.assertRaises(
+ AuthenticationException,
+ self._test_connection,
+ password="unresponsive-server",
+ auth_timeout=0.5,
+ )
+
+ def test_10_auth_trickledown_gsskex(self):
"""
Failed gssapi-keyex auth doesn't prevent subsequent key auth from succeeding
"""
@@ -400,7 +419,7 @@ class SSHClientTest(unittest.TestCase):
kwargs = dict(gss_kex=True, key_filename=[_support("test_rsa.key")])
self._test_connection(**kwargs)
- def test_10_auth_trickledown_gssauth(self):
+ def test_11_auth_trickledown_gssauth(self):
"""
Failed gssapi-with-mic auth doesn't prevent subsequent key auth from succeeding
"""
@@ -409,7 +428,7 @@ class SSHClientTest(unittest.TestCase):
kwargs = dict(gss_auth=True, key_filename=[_support("test_rsa.key")])
self._test_connection(**kwargs)
- def test_11_reject_policy(self):
+ def test_12_reject_policy(self):
"""
verify that SSHClient's RejectPolicy works.
"""
@@ -425,7 +444,7 @@ class SSHClientTest(unittest.TestCase):
**self.connect_kwargs
)
- def test_12_reject_policy_gsskex(self):
+ def test_13_reject_policy_gsskex(self):
"""
verify that SSHClient's RejectPolicy works,
even if gssapi-keyex was enabled but not used.
@@ -532,3 +551,19 @@ class SSHClientTest(unittest.TestCase):
)
else:
self.assertFalse(False, "SSHException was not thrown.")
+
+ def test_missing_key_policy_accepts_classes_or_instances(self):
+ """
+ Client.missing_host_key_policy() can take classes or instances.
+ """
+ # AN ACTUAL UNIT TEST?! GOOD LORD
+ # (But then we have to test a private API...meh.)
+ client = paramiko.SSHClient()
+ # Default
+ assert isinstance(client._policy, paramiko.RejectPolicy)
+ # Hand in an instance (classic behavior)
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ assert isinstance(client._policy, paramiko.AutoAddPolicy)
+ # Hand in just the class (new behavior)
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
+ assert isinstance(client._policy, paramiko.AutoAddPolicy)