diff --git a/asyncssh/connection.py b/asyncssh/connection.py index e81a92c..22bcdaa 100644 --- a/asyncssh/connection.py +++ b/asyncssh/connection.py @@ -438,7 +438,7 @@ async def _open_tunnel(tunnels: object, options: _Options, last_conn = conn conn = await connect(host, port, username=username, passphrase=options.passphrase, tunnel=conn, - config=config) + config=config, reload=False) conn.set_tunnel(last_conn) if options.canonicalize_hostname != 'always': diff --git a/tests/test_forward.py b/tests/test_forward.py index fa9ee24..2f139da 100644 --- a/tests/test_forward.py +++ b/tests/test_forward.py @@ -247,6 +247,17 @@ def unix_connection_requested(self, dest_path): return self._upstream_conn +class _JumpServer(Server): + def __init__(self, remote_port): + self._remote_port = remote_port + + def begin_auth(self, username): + """user jumper is allowed to use this server""" + return username != "jumper" + + def connection_requested(self, dest_host, dest_port, orig_host, orig_port): + return dest_port == self._remote_port + class _CheckForwarding(ServerTestCase): """Utility functions for AsyncSSH forwarding unit tests""" @@ -379,6 +390,45 @@ async def test_proxy_jump(self): finally: os.remove('.ssh/config') + @asynctest + async def test_proxy_jump_user(self): + """Test connecting a tunnneled SSH connection using ProxyJump + with a User + """ + import logging + logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) + asyncssh.set_log_level('DEBUG') + + def jump_server(): + return _JumpServer(self._server_port) + + + jump_listener = await self.create_server(jump_server) + jump_port = jump_listener.get_port() + + + write_file('.ssh/config', +f""" +Host jump + HostName 127.0.0.3 + Port {jump_port} + User jumper + +Host target + Hostname 127.0.0.2 + Port {self._server_port} + +Match final host 127.0.0.2 + ProxyJump jump +""".encode()) + try: + async with self.connect(host='target', username='ckey'): + pass + finally: + os.remove('.ssh/config') + jump_listener.close() + await jump_listener.wait_closed() + @asynctest async def test_proxy_jump_multiple(self): """Test connecting a tunnneled SSH connection using ProxyJump"""