From 2c7070ceb1ebc596e1ab89c5f82c4fea09867e2d Mon Sep 17 00:00:00 2001 From: James Corsi Date: Mon, 27 Aug 2018 23:50:52 -0400 Subject: [PATCH] Adding in SSH forwarding to spur using Paramiko's AgentRequestHandler (http://docs.paramiko.org/en/2.4/api/agent.html#paramiko.agent.AgentRequestHandler). Fixes #50. --- spur/ssh.py | 1 + tests/ssh_tests.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/spur/ssh.py b/spur/ssh.py index 24e4a03..22d19ac 100644 --- a/spur/ssh.py +++ b/spur/ssh.py @@ -178,6 +178,7 @@ def spawn(self, command, *args, **kwargs): channel = self._get_ssh_transport().open_session() except EOFError as error: raise self._connection_error(error) + paramiko.agent.AgentRequestHandler(channel) if use_pty: channel.get_pty() channel.exec_command(command_in_cwd) diff --git a/tests/ssh_tests.py b/tests/ssh_tests.py index a239434..5ffca19 100644 --- a/tests/ssh_tests.py +++ b/tests/ssh_tests.py @@ -95,6 +95,13 @@ def an_open_socket_can_be_used_for_ssh_connection_with_sock_argument(): assert_equal(b"hello\n", result.output) +@istest +def ssh_agent_key_forwarding_successful(): + with create_ssh_shell(missing_host_key=spur.ssh.MissingHostKey.accept) as shell: + auth_sock = shell.run(["printenv", "SSH_AUTH_SOCK"]) + assert auth_sock is not None + + def _create_shell_with_wrong_port(**kwargs): return spur.SshShell( username=USERNAME,