diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_file.py | 5 | ||||
-rw-r--r-- | tests/test_hostkeys.py | 18 | ||||
-rw-r--r-- | tests/test_proxy.py | 16 | ||||
-rw-r--r-- | tests/test_sftp.py | 8 | ||||
-rw-r--r-- | tests/test_transport.py | 2 |
5 files changed, 37 insertions, 12 deletions
diff --git a/tests/test_file.py b/tests/test_file.py index 364bbce2..456c0388 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -127,8 +127,9 @@ class BufferedFileTest(unittest.TestCase): f.write("Not\nquite\n512 bytes.\n") self.assertEqual(f.read(1), b"") f.flush() - self.assertEqual(f.read(5), b"Not\nq") - self.assertEqual(f.read(10), b"uite\n512 b") + self.assertEqual(f.read(6), b"Not\nqu") + self.assertEqual(f.read(4), b"ite\n") + self.assertEqual(f.read(5), b"512 b") self.assertEqual(f.read(9), b"ytes.\n") self.assertEqual(f.read(3), b"") f.close() diff --git a/tests/test_hostkeys.py b/tests/test_hostkeys.py index ebcc40f5..bdda295a 100644 --- a/tests/test_hostkeys.py +++ b/tests/test_hostkeys.py @@ -38,6 +38,18 @@ BGQ3GQ/Fc7SX6gkpXkwcZryoi4kNFhHu5LvHcZPdxXV1D+uTMfGS1eyd2Yz/DoNWXNAl8TI0cAsW\ 5ymME3bQ4J/k1IKxCtz/bAlAqFgKoc+EolMziDYqWIATtW0rYTJvzGAzTmMj80/QpsFH+Pc2M= """ +test_hosts_file_tabs = """\ +secure.example.com\tssh-rsa\tAAAAB3NzaC1yc2EAAAABIwAAAIEA1PD6U2/TVxET6lkpKhOk5r\ +9q/kAYG6sP9f5zuUYP8i7FOFp/6ncCEbbtg/lB+A3iidyxoSWl+9jtoyyDOOVX4UIDV9G11Ml8om3\ +D+jrpI9cycZHqilK0HmxDeCuxbwyMuaCygU9gS2qoRvNLWZk70OpIKSSpBo0Wl3/XUmz9uhc= +happy.example.com\tssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA8bP1ZA7DCZDB9J0s50l31M\ +BGQ3GQ/Fc7SX6gkpXkwcZryoi4kNFhHu5LvHcZPdxXV1D+uTMfGS1eyd2Yz/DoNWXNAl8TI0cAsW\ +5ymME3bQ4J/k1IKxCtz/bAlAqFgKoc+EolMziDYqWIATtW0rYTJvzGAzTmMj80/QpsFH+Pc2M= +doublespace.example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA1PD6U2/TVxET6lkp\ +KhOk5r9q/kAYG6sP9f5zuUYP8i7FOFp/6ncCEbbtg/lB+A3iidyxoSWl+9jtoyyDOOVX4UIDV9G11M\ +l8om3D+jrpI9cycZHqilK0HmxDeCuxbwyMuaCygU9gS2qoRvNLWZk70OpIKSSpBo0Wl3/XUmz8BtZ= +""" + keyblob = b"""\ AAAAB3NzaC1yc2EAAAABIwAAAIEA8bP1ZA7DCZDB9J0s50l31MBGQ3GQ/Fc7SX6gkpXkwcZryoi4k\ NFhHu5LvHcZPdxXV1D+uTMfGS1eyd2Yz/DoNWXNAl8TI0cAsW5ymME3bQ4J/k1IKxCtz/bAlAqFgK\ @@ -147,3 +159,9 @@ class HostKeysTest(unittest.TestCase): pass # Good else: assert False, "Key was not deleted from Entry on delitem!" + + +class HostKeysTabsTest(HostKeysTest): + def setUp(self): + with open("hostfile.temp", "w") as f: + f.write(test_hosts_file_tabs) diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 83bdc040..22c2c9c3 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -43,14 +43,20 @@ class TestProxyCommand: stdout = Popen.return_value.stdout select.return_value = [stdout], None, None fileno = stdout.fileno.return_value - # Intentionally returning <5 at a time sometimes - os_read.side_effect = [b"was", b"te", b"of ti", b"me"] + # Force os.read to return smaller-than-requested chunks + os_read.side_effect = [b"was", b"t", b"e", b"of ti", b"me"] proxy = ProxyCommand("hi") + # Ask for 5 bytes (ie b"waste") data = proxy.recv(5) + # Ensure we got "waste" stitched together assert data == b"waste" + # Ensure the calls happened in the sizes expected (starting with the + # initial "I want all 5 bytes", followed by "I want whatever I believe + # should be left after what I've already read", until done) assert [x[0] for x in os_read.call_args_list] == [ - (fileno, 5), - (fileno, 2), + (fileno, 5), # initial + (fileno, 2), # I got 3, want 2 more + (fileno, 1), # I've now got 4, want 1 more ] @patch("paramiko.proxy.subprocess.Popen") @@ -122,7 +128,7 @@ class TestProxyCommand: select.return_value = [stdout], None, None # Base case: None timeout means no timing out os_read.return_value = b"meh" - proxy = ProxyCommand("yello") + proxy = ProxyCommand("hello") assert proxy.timeout is None # Implicit 'no raise' check assert proxy.recv(3) == b"meh" diff --git a/tests/test_sftp.py b/tests/test_sftp.py index 2cd68d94..be123de4 100644 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -46,7 +46,7 @@ ARTICLE = """ Insulin sensitivity and liver insulin receptor structure in ducks from two genera -T. Constans, B. Chevalier, M. Derouet and J. Simon +T. Constantine, B. Chevalier, M. Derouet and J. Simon Station de Recherches Avicoles, Institut National de la Recherche Agronomique, Nouzilly, France. @@ -129,7 +129,7 @@ class TestSFTP: try: with sftp.open(sftp.FOLDER + "/duck.txt", "w") as f: f.write(ARTICLE) - assert sftp.stat(sftp.FOLDER + "/duck.txt").st_size == 1483 + assert sftp.stat(sftp.FOLDER + "/duck.txt").st_size == 1486 finally: sftp.remove(sftp.FOLDER + "/duck.txt") @@ -140,7 +140,7 @@ class TestSFTP: try: with sftp.open(sftp.FOLDER + "/duck.txt", "w") as f: f.write(ARTICLE) - assert sftp.stat(sftp.FOLDER + "/duck.txt").st_size == 1483 + assert sftp.stat(sftp.FOLDER + "/duck.txt").st_size == 1486 finally: sftp.remove(sftp.FOLDER + "/duck.txt") @@ -724,7 +724,7 @@ class TestSFTP: def test_seek_append(self, sftp): """ - verify that seek does't affect writes during append. + verify that seek doesn't affect writes during append. does not work except through paramiko. :( openssh fails. """ diff --git a/tests/test_transport.py b/tests/test_transport.py index 4d28199a..4062d767 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -891,7 +891,7 @@ class TransportTest(unittest.TestCase): @slow def test_handshake_timeout(self): """ - verify that we can get a hanshake timeout. + verify that we can get a handshake timeout. """ # Tweak client Transport instance's Packetizer instance so # its read_message() sleeps a bit. This helps prevent race conditions |