|
22 | 22 |
|
23 | 23 | from gevent import sleep, Timeout as GTimeout, spawn
|
24 | 24 | from ssh.session import Session
|
| 25 | +from ssh.exceptions import AuthenticationDenied |
25 | 26 | from pssh.exceptions import AuthenticationException, ConnectionErrorException, \
|
26 | 27 | SessionError, SFTPIOError, SFTPError, SCPError, PKeyFileError, Timeout, \
|
27 | 28 | AuthenticationError
|
@@ -238,5 +239,51 @@ def _session():
|
238 | 239 | def test_invalid_mkdir(self):
|
239 | 240 | self.assertRaises(OSError, self.client._make_local_dir, '/my_new_dir')
|
240 | 241 |
|
| 242 | + def test_no_auth(self): |
| 243 | + self.assertRaises( |
| 244 | + AuthenticationError, |
| 245 | + SSHClient, |
| 246 | + self.host, |
| 247 | + port=self.port, |
| 248 | + num_retries=1, |
| 249 | + allow_agent=False, |
| 250 | + identity_auth=False, |
| 251 | + ) |
| 252 | + |
| 253 | + def test_agent_auth_failure(self): |
| 254 | + class UnknownError(Exception): |
| 255 | + pass |
| 256 | + def _agent_auth_unk(): |
| 257 | + raise UnknownError |
| 258 | + def _agent_auth_agent_err(): |
| 259 | + raise AuthenticationDenied |
| 260 | + client = SSHClient(self.host, port=self.port, |
| 261 | + pkey=self.user_key, |
| 262 | + num_retries=1, |
| 263 | + allow_agent=True, |
| 264 | + identity_auth=False) |
| 265 | + client.session.disconnect() |
| 266 | + client.pkey = None |
| 267 | + client._connect(self.host, self.port) |
| 268 | + self.assertRaises(AuthenticationDenied, client._agent_auth) |
| 269 | + client._agent_auth = _agent_auth_unk |
| 270 | + self.assertRaises(AuthenticationError, client.auth) |
| 271 | + client._agent_auth = _agent_auth_agent_err |
| 272 | + self.assertRaises(AuthenticationError, client.auth) |
| 273 | + |
| 274 | + def test_agent_auth_fake_success(self): |
| 275 | + def _agent_auth(): |
| 276 | + return |
| 277 | + client = SSHClient(self.host, port=self.port, |
| 278 | + pkey=self.user_key, |
| 279 | + num_retries=1, |
| 280 | + allow_agent=True, |
| 281 | + identity_auth=False) |
| 282 | + client.session.disconnect() |
| 283 | + client.pkey = None |
| 284 | + client._connect(self.host, self.port) |
| 285 | + client._agent_auth = _agent_auth |
| 286 | + self.assertIsNone(client.auth()) |
| 287 | + |
241 | 288 | # TODO:
|
242 | 289 | # * disconnect exc
|
0 commit comments