@@ -2,6 +2,7 @@ defmodule SSHClientKeyAPITest do
2
2
use ExUnit.Case
3
3
4
4
alias SSHClientKeyAPI
5
+ alias SSHClientKeyAPI.KeyError
5
6
6
7
@ private_key """
7
8
-----BEGIN RSA PRIVATE KEY-----
@@ -132,19 +133,30 @@ FSlw/QlRe3XqAJDRtHyiI2d4JIPFcOjZQSF7fURYPEKaRRtQRvSaI0D9fYwuRZDY
132
133
end
133
134
134
135
test "user key returns error if passphrase is missing for protected key" , % { protected_key: protected_key } do
135
- result = SSHClientKeyAPI . user_key (
136
- :"ssh-dss" ,
137
- [ key_cb_private: [ identity: protected_key , identity_data: IO . binread ( protected_key , :all ) ] ]
138
- )
139
- assert { :error , _ } = result
136
+ assert_raise KeyError , ~r/ passphrase required/ , fn ->
137
+ SSHClientKeyAPI . user_key (
138
+ :"ssh-dss" ,
139
+ [ key_cb_private: [ identity: protected_key , identity_data: IO . binread ( protected_key , :all ) ] ]
140
+ )
141
+ end
140
142
end
141
143
142
144
test "user key returns error if passphrase is incorrect for protected key" , % { protected_key: protected_key } do
143
- result = SSHClientKeyAPI . user_key (
144
- :"ssh-dss" ,
145
- [ key_cb_private: [ passphrase: 'wrong' , identity: protected_key , identity_data: IO . binread ( protected_key , :all ) ] ]
146
- )
147
- assert { :error , _ } = result
145
+ assert_raise KeyError , ~r/ passphrase invalid/ , fn ->
146
+ SSHClientKeyAPI . user_key (
147
+ :"ssh-dss" ,
148
+ [ key_cb_private: [ passphrase: 'wrong' , identity: protected_key , identity_data: IO . binread ( protected_key , :all ) ] ]
149
+ )
150
+ end
151
+ end
152
+
153
+ test "user key returns error if trying to use unsupported algorithm" , % { protected_key: protected_key } do
154
+ assert_raise KeyError , ~r/ not supported/ , fn ->
155
+ SSHClientKeyAPI . user_key (
156
+ :"ssh-scooby-doo" ,
157
+ [ key_cb_private: [ passphrase: 'wrong' , identity: protected_key , identity_data: IO . binread ( protected_key , :all ) ] ]
158
+ )
159
+ end
148
160
end
149
161
150
162
test "with correct passphrase, user key returns contents of protected key" , % { protected_key: protected_key } do
0 commit comments