Skip to content

Commit cfe517c

Browse files
committed
Disable keychain tests if no keychain available
1 parent 0cfc2ca commit cfe517c

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

src/clj_ssh/keychain.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
[clojure.java.shell :as shell]))
77

88
(defn ask-passphrase [path]
9-
(when-let [console (. System console)]
10-
(print "Passphrase for" path ": ")
11-
(.readPassword console)))
9+
(if-let [console (. System console)]
10+
(do (print "Passphrase for" path ": ")
11+
(.readPassword console))
12+
(throw (ex-info "No means to ask for passphrase"
13+
{:type :clj-ssh/no-passphrase-available}))))
1214

1315
(defmulti keychain-passphrase "Obtain password for path"
1416
(fn [system path] system))

test/clj_ssh/cli_test.clj

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,23 @@
7474
(is (connected? session)))
7575
(is (not (connected? session)))))
7676
(with-ssh-agent (ssh-agent {:use-system-ssh-agent false})
77-
(add-identity-with-keychain
78-
:private-key-path (encrypted-private-key-path)
79-
:passphrase "clj-ssh")
80-
(let [session (session "localhost")]
81-
(is (instance? com.jcraft.jsch.Session session))
82-
(is (not (connected? session)))
83-
(connect session)
84-
(is (connected? session))
85-
(disconnect session)
86-
(is (not (connected? session))))
87-
(let [session (session "localhost")]
88-
(with-connection session
89-
(is (connected? session)))
90-
(is (not (connected? session)))))
77+
(try (add-identity-with-keychain
78+
:private-key-path (encrypted-private-key-path)
79+
:passphrase "clj-ssh")
80+
(let [session (session "localhost")]
81+
(is (instance? com.jcraft.jsch.Session session))
82+
(is (not (connected? session)))
83+
(connect session)
84+
(is (connected? session))
85+
(disconnect session)
86+
(is (not (connected? session))))
87+
(let [session (session "localhost")]
88+
(with-connection session
89+
(is (connected? session)))
90+
(is (not (connected? session))))
91+
(catch Exception e
92+
(when-not (= :clj-ssh/no-passphrase-available (:type (ex-data e)))
93+
(throw e)))))
9194
(with-ssh-agent (ssh-agent {})
9295
(let [session (session "localhost")]
9396
(is (instance? com.jcraft.jsch.Session session))

test/clj_ssh/ssh_test.clj

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,33 @@
138138
(is (connected? session)))
139139
(is (not (connected? session)))))
140140
(testing "key with passphrase"
141-
(let [agent (ssh-agent {:use-system-ssh-agent false})]
142-
(add-identity-with-keychain
143-
agent
144-
{:private-key-path (encrypted-private-key-path)
145-
:passphrase "clj-ssh"})
146-
(let [session (session
147-
agent
148-
"localhost"
149-
{:username (username)
150-
:strict-host-key-checking :no})]
151-
(is (instance? com.jcraft.jsch.Session session))
152-
(is (not (connected? session)))
153-
(connect session)
154-
(is (connected? session))
155-
(disconnect session)
156-
(is (not (connected? session))))
157-
(let [session (session
158-
agent
159-
"localhost"
160-
{:username (username)
161-
:strict-host-key-checking :no})]
162-
(with-connection session
163-
(is (connected? session)))
164-
(is (not (connected? session)))))))
141+
(try (let [agent (ssh-agent {:use-system-ssh-agent false})]
142+
(add-identity-with-keychain
143+
agent
144+
{:private-key-path (encrypted-private-key-path)
145+
:passphrase "clj-ssh"})
146+
(let [session (session
147+
agent
148+
"localhost"
149+
{:username (username)
150+
:strict-host-key-checking :no})]
151+
(is (instance? com.jcraft.jsch.Session session))
152+
(is (not (connected? session)))
153+
(connect session)
154+
(is (connected? session))
155+
(disconnect session)
156+
(is (not (connected? session))))
157+
(let [session (session
158+
agent
159+
"localhost"
160+
{:username (username)
161+
:strict-host-key-checking :no})]
162+
(with-connection session
163+
(is (connected? session)))
164+
(is (not (connected? session)))))
165+
(catch Exception e
166+
(when-not (= :clj-ssh/no-passphrase-available (:type (ex-data e)))
167+
(throw e))))))
165168
(testing "system ssh-agent"
166169
(let [agent (ssh-agent {})]
167170
(let [session (session

0 commit comments

Comments
 (0)