15
15
# License along with this library; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
18
- import unittest
19
18
import os
20
- import time
21
19
import subprocess
22
20
import shutil
23
21
import tempfile
24
22
from hashlib import sha256
25
23
from datetime import datetime
26
24
27
- from gevent import socket , sleep , spawn , Timeout as GTimeout
25
+ from gevent import sleep , spawn , Timeout as GTimeout
28
26
29
27
from pssh .clients .native import SSHClient
30
28
from ssh2 .session import Session
31
- from ssh2 .channel import Channel
32
29
from ssh2 .exceptions import SocketDisconnectError , BannerRecvError , SocketRecvError , \
33
30
AgentConnectionError , AgentListIdentitiesError , \
34
31
AgentAuthenticationError , AgentGetIdentityError , SFTPProtocolError
37
34
AuthenticationError
38
35
39
36
from .base_ssh2_case import SSH2TestCase
40
- from ..embedded_server .openssh import OpenSSHServer
41
37
42
38
43
39
class SSH2ClientTest (SSH2TestCase ):
@@ -175,21 +171,32 @@ def test_manual_auth(self):
175
171
client .session .handshake (client .sock )
176
172
self .assertRaises (AuthenticationException , client .auth )
177
173
178
- def test_default_identities_auth (self ):
174
+ def test_identity_auth (self ):
175
+ class _SSHClient (SSHClient ):
176
+ IDENTITIES = (self .user_key ,)
179
177
client = SSHClient (self .host , port = self .port ,
180
178
pkey = self .user_key ,
181
179
num_retries = 1 ,
182
180
allow_agent = False )
183
- client .session . disconnect ()
181
+ client .disconnect ()
184
182
client .pkey = None
185
183
del client .session
186
184
del client .sock
187
185
client ._connect (self .host , self .port )
188
186
client ._init_session ()
189
- # Default identities auth only
190
- self .assertRaises (AuthenticationException , client ._identity_auth )
191
- # Default auth
192
- self .assertRaises (AuthenticationException , client .auth )
187
+ client .IDENTITIES = (self .user_key ,)
188
+ # Default identities auth only should succeed
189
+ client ._identity_auth ()
190
+ client .disconnect ()
191
+ client ._connect (self .host , self .port )
192
+ client ._init_session ()
193
+ # Auth should succeed
194
+ self .assertIsNone (client .auth ())
195
+ # Standard init with custom identities
196
+ client = _SSHClient (self .host , port = self .port ,
197
+ num_retries = 1 ,
198
+ allow_agent = False )
199
+ self .assertIsInstance (client , SSHClient )
193
200
194
201
def test_agent_auth_failure (self ):
195
202
class UnknownError (Exception ):
@@ -201,7 +208,8 @@ def _agent_auth_agent_err():
201
208
client = SSHClient (self .host , port = self .port ,
202
209
pkey = self .user_key ,
203
210
num_retries = 1 ,
204
- allow_agent = True )
211
+ allow_agent = True ,
212
+ identity_auth = False )
205
213
client .session .disconnect ()
206
214
client .pkey = None
207
215
client ._connect (self .host , self .port )
@@ -210,6 +218,20 @@ def _agent_auth_agent_err():
210
218
client ._agent_auth = _agent_auth_agent_err
211
219
self .assertRaises (AuthenticationError , client .auth )
212
220
221
+ def test_agent_auth_fake_success (self ):
222
+ def _agent_auth ():
223
+ return
224
+ client = SSHClient (self .host , port = self .port ,
225
+ pkey = self .user_key ,
226
+ num_retries = 1 ,
227
+ allow_agent = True ,
228
+ identity_auth = False )
229
+ client .session .disconnect ()
230
+ client .pkey = None
231
+ client ._connect (self .host , self .port )
232
+ client ._agent_auth = _agent_auth
233
+ self .assertIsNone (client .auth ())
234
+
213
235
def test_agent_fwd (self ):
214
236
client = SSHClient (self .host , port = self .port ,
215
237
pkey = self .user_key ,
@@ -317,6 +339,7 @@ def __init__(self, host, port, num_retries):
317
339
super (SSHClient , self ).__init__ (
318
340
host , port = port , num_retries = 2 ,
319
341
allow_agent = True )
342
+ self .IDENTITIES = set ()
320
343
321
344
def _init_session (self ):
322
345
self .session = Session ()
0 commit comments