Skip to content

Commit 3ef1d65

Browse files
committed
Add a :agent-forwarding option
A boolean value is passed with :agent-forwarding to clj-ssh.ssh/ssh.
1 parent 0bd1478 commit 3ef1d65

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/clj_ssh/ssh.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ keys. All other option key pairs will be passed as SSH config options."
359359
(reflect/call-method
360360
com.jcraft.jsch.ChannelSession 'setPty [Boolean/TYPE]
361361
shell (boolean (opts :pty))))
362+
(when (contains? opts :agent-forwarding)
363+
(reflect/call-method
364+
com.jcraft.jsch.ChannelSession 'setAgentForwarding [Boolean/TYPE]
365+
shell (boolean (opts :agent-forwarding))))
362366
(if out-inputstream
363367
(do
364368
(connect shell)
@@ -390,6 +394,10 @@ keys. All other option key pairs will be passed as SSH config options."
390394
(reflect/call-method
391395
com.jcraft.jsch.ChannelSession 'setPty [Boolean/TYPE]
392396
exec (boolean (opts :pty))))
397+
(when (contains? opts :agent-forwarding)
398+
(reflect/call-method
399+
com.jcraft.jsch.ChannelSession 'setAgentForwarding [Boolean/TYPE]
400+
exec (boolean (opts :agent-forwarding))))
393401
(if out-inputstream
394402
(do
395403
(connect exec)

test/clj_ssh/ssh_test.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,14 @@ list, Alan Dipert and MeikelBrandmeyer."
265265
(let [result (ssh-shell session "exit $(tty -s)" "UTF-8" {:pty true})]
266266
(is (= 0 (first result))))
267267
(let [result (ssh-shell session "exit $(tty -s)" "UTF-8" {:pty nil})]
268-
(is (= 1 (first result))))))))
268+
(is (= 1 (first result))))
269+
(let [result (ssh-shell session "ssh-add -l" "UTF-8" {})]
270+
(is (pos? (first result))))
271+
(let [result (ssh-shell session "ssh-add -l" "UTF-8" {:agent-forwarding false})]
272+
(is (pos? (first result))))
273+
(let [result (ssh-shell session "ssh-add -l" "UTF-8" {:agent-forwarding true})]
274+
(is (re-find #"RSA" (second result)))
275+
(is (= 0 (first result))))))))
269276

270277
(deftest ssh-exec-test
271278
(with-ssh-agent [false]

0 commit comments

Comments
 (0)