def test_consume_stderr(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******'}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1024

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, False]
        chan.recv_stderr.side_effect = ['123', '456']

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual(u('123456'), stderr)
        self.assertEqual(len(stderr), 6)

        conn_params = {'hostname': 'dummy.host.org',
                       'username': '******'}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1024

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, False]
        chan.recv_stderr.side_effect = ['987', '6543210']

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual(u('9876543210'), stderr)
        self.assertEqual(len(stderr), 10)
Esempio n. 2
0
    def test_consume_stderr_chunk_contains_non_utf8_character(self):
        conn_params = {"hostname": "dummy.host.org", "username": "******"}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, True, False]
        chan.recv_stderr.side_effect = ["🤦".encode("utf-32"), "a", "b"]

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual("\x00\x00&\x01\x00ab", stderr)
        self.assertEqual(len(stderr), 7)
    def test_consume_stderr_chunk_contains_non_utf8_character(self):
        conn_params = {'hostname': 'dummy.host.org', 'username': '******'}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, True, False]
        chan.recv_stderr.side_effect = ['🤦'.encode('utf-32'), 'a', 'b']

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual('\x00\x00&\x01\x00ab', stderr)
        self.assertEqual(len(stderr), 7)
Esempio n. 4
0
    def test_consume_stderr_chunk_contains_part_of_multi_byte_utf8_character(
            self):
        conn_params = {'hostname': 'dummy.host.org', 'username': '******'}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, True, True, False]
        chan.recv_stderr.side_effect = ['\xF0', '\x90', '\x8D', '\x88']

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual('\xf0\x90\x8d\x88', stderr.encode('utf-8'))
        self.assertTrue(len(stderr) in [1, 2])
Esempio n. 5
0
    def test_consume_stderr_chunk_contains_part_of_multi_byte_utf8_character(
            self):
        conn_params = {"hostname": "dummy.host.org", "username": "******"}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, True, True, False]
        chan.recv_stderr.side_effect = ["\xF0", "\x90", "\x8D", "\x88"]

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual("ð\x90\x8d\x88", stderr)
        self.assertEqual(len(stderr), 4)
Esempio n. 6
0
    def test_consume_stderr(self):
        conn_params = {"hostname": "dummy.host.org", "username": "******"}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1024

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, False]
        chan.recv_stderr.side_effect = ["123", "456"]

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual(u("123456"), stderr)
        self.assertEqual(len(stderr), 6)

        conn_params = {"hostname": "dummy.host.org", "username": "******"}
        client = ParamikoSSHClient(**conn_params)
        client.CHUNK_SIZE = 1024

        chan = Mock()
        chan.recv_stderr_ready.side_effect = [True, True, False]
        chan.recv_stderr.side_effect = ["987", "6543210"]

        stderr = client._consume_stderr(chan).getvalue()
        self.assertEqual(u("9876543210"), stderr)
        self.assertEqual(len(stderr), 10)