1515# License along with this library; if not, write to the Free Software
1616# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717
18- import unittest
1918import os
20- import time
2119import subprocess
2220import shutil
2321import tempfile
2422from hashlib import sha256
2523from datetime import datetime
2624
27- from gevent import socket , sleep , spawn , Timeout as GTimeout
25+ from gevent import sleep , spawn , Timeout as GTimeout
2826
2927from pssh .clients .native import SSHClient
3028from ssh2 .session import Session
31- from ssh2 .channel import Channel
3229from ssh2 .exceptions import SocketDisconnectError , BannerRecvError , SocketRecvError , \
3330 AgentConnectionError , AgentListIdentitiesError , \
3431 AgentAuthenticationError , AgentGetIdentityError , SFTPProtocolError
3734 AuthenticationError
3835
3936from .base_ssh2_case import SSH2TestCase
40- from ..embedded_server .openssh import OpenSSHServer
4137
4238
4339class SSH2ClientTest (SSH2TestCase ):
@@ -175,21 +171,32 @@ def test_manual_auth(self):
175171 client .session .handshake (client .sock )
176172 self .assertRaises (AuthenticationException , client .auth )
177173
178- def test_default_identities_auth (self ):
174+ def test_identity_auth (self ):
175+ class _SSHClient (SSHClient ):
176+ IDENTITIES = (self .user_key ,)
179177 client = SSHClient (self .host , port = self .port ,
180178 pkey = self .user_key ,
181179 num_retries = 1 ,
182180 allow_agent = False )
183- client .session . disconnect ()
181+ client .disconnect ()
184182 client .pkey = None
185183 del client .session
186184 del client .sock
187185 client ._connect (self .host , self .port )
188186 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 )
193200
194201 def test_agent_auth_failure (self ):
195202 class UnknownError (Exception ):
@@ -201,7 +208,8 @@ def _agent_auth_agent_err():
201208 client = SSHClient (self .host , port = self .port ,
202209 pkey = self .user_key ,
203210 num_retries = 1 ,
204- allow_agent = True )
211+ allow_agent = True ,
212+ identity_auth = False )
205213 client .session .disconnect ()
206214 client .pkey = None
207215 client ._connect (self .host , self .port )
@@ -210,6 +218,20 @@ def _agent_auth_agent_err():
210218 client ._agent_auth = _agent_auth_agent_err
211219 self .assertRaises (AuthenticationError , client .auth )
212220
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+
213235 def test_agent_fwd (self ):
214236 client = SSHClient (self .host , port = self .port ,
215237 pkey = self .user_key ,
@@ -317,6 +339,7 @@ def __init__(self, host, port, num_retries):
317339 super (SSHClient , self ).__init__ (
318340 host , port = port , num_retries = 2 ,
319341 allow_agent = True )
342+ self .IDENTITIES = set ()
320343
321344 def _init_session (self ):
322345 self .session = Session ()
0 commit comments