+
    Dfj                     $   R t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHt ^ RIt^ RIHtHtHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHtHtHtHt ^ RI H!t!H"t"H#t#H$t$ ^ RI%H&t&H't' ^ RI(H)t)H*t* ^ RI+H,t,H-t-H.t. ^ RI/H0t0H1t1 ^ RI2H3t3 ^ RI4H5t5 ^ RI6H7t7 ^ RI8H9t9 ^ RI:H;t; ^ RI<H=t= ];! R4      '       dd   ^ RI>H?t? ^ RI@HAtAHBtB ^ RICHDtDHEtE ^ RIFHGtGHHtHHItIHJtJHKtKHLtL ^ RIMHNtN ^ RIOHPtP ^ RIQHRtR ^ R ISHTtT ^ R!IUHVtV ^ R"IWHXtX ^ R#IYHZtZ ^ R$I[H\t\ ^ R%I]H^t^H_t_H`t`Hata MR&tb]ctV]ct\]ctT]ctX]ctR]ctP]ctE]ctB]ct?^ R'IdHeteHftf  ! R( R)]e4      tg ! R* R+]R4      th ! R, R-]R4      ti ! R. R/]R4      tj ! R0 R14      tk ! R2 R3])4      tl ! R4 R54      tm ! R6 R7]\4      tn ! R8 R9]V4      to]
! ]&4       ! R: R;4      4       tp]
! ]'4       ! R< R=4      4       tq ! R> R?4      tr ! R@ RA]=]r4      ts ! RB RC]=]r4      tt ! RD RE]=4      tu ! RF RG]4      tv ! RH RI4      tw ! RJ RK]=4      txR# )Lz'
Tests for L{twisted.conch.endpoints}.
N)BytesIO)pack)IO)implementer)verifyClassverifyObject)
ConchErrorHostKeyChangedUserRejectedKey)
IConchUser)'InMemoryUsernamePasswordDatabaseDontUse)Portal)IPv4Address)CancelledErrorDeferredfailsucceed)ConnectingCancelledErrorConnectionDoneConnectionRefusedErrorProcessTerminated)IAddressIStreamClientEndpoint)FactoryProtocol)EventLoggingObserverMemoryReactorClockStringTransport)LogLevelglobalLogPublisher)networkString)Failure)FilePath)msg)requireModule)TestCasecryptography)	ConchUser)InMemorySSHKeyDBSSHPublicKeyChecker)	ConsoleUIKnownHostsFile)AuthenticationFailedSSHCommandAddressSSHCommandClientEndpoint_ExistingConnectionHelper_ISSHConnectionCreator_NewConnectionHelper)common)SSHAgentServer)
SSHChannel)SSHConnection)
SSHFactory)Key)SSHClientTransport)SSHUserAuthServer)privateDSA_opensshprivateRSA_openssh privateRSA_openssh_encrypted_aespublicRSA_opensshzcan't run w/o cryptography)FakeTransportconnectc                   .   a  ] tR t^Vt o RtRtR tRtV tR# )AbortableFakeTransportz;
A L{FakeTransport} with added C{abortConnection} support.
Fc                    RV n         R# )ze
Abort the connection in a fake manner.

This should really be implemented in the underlying module.
TNabortedselfs   &C/usr/lib/python3/dist-packages/twisted/conch/test/test_endpoints.pyabortConnection&AbortableFakeTransport.abortConnection]   s         rC   N)	__name__
__module____qualname____firstlineno____doc__rD   rH   __static_attributes____classdictcell____classdict__s   @rG   rA   rA   V   s      G rJ   rA   c                   *   a  ] tR t^ft o RtR tRtV tR# )BrokenExecSessionzG
L{BrokenExecSession} is a session on which exec requests always fail.
c                    ^ # )z
Fail all exec requests.

@param data: Information about what is being executed.
@type data: L{bytes}

@return: C{0} to indicate failure
@rtype: L{int}
 rF   datas   &&rG   request_execBrokenExecSession.request_execk        rJ   rW   NrK   rL   rM   rN   rO   rZ   rP   rQ   rR   s   @rG   rU   rU   f        
 
rJ   rU   c                   *   a  ] tR t^xt o RtR tRtV tR# )WorkingExecSessionzK
L{WorkingExecSession} is a session on which exec requests always succeed.
c                    ^# )z
Succeed all exec requests.

@param data: Information about what is being executed.
@type data: L{bytes}

@return: C{1} to indicate success
@rtype: L{int}
rW   rX   s   &&rG   rZ   WorkingExecSession.request_exec}   r\   rJ   rW   Nr]   rR   s   @rG   r`   r`   x   r^   rJ   r`   c                   *   a  ] tR t^t o RtR tRtV tR# )UnsatisfiedExecSessionz}
L{UnsatisfiedExecSession} is a session on which exec requests are always
delayed indefinitely, never succeeding or failing.
c                    \        4       # )z
Delay all exec requests indefinitely.

@param data: Information about what is being executed.
@type data: L{bytes}

@return: A L{Deferred} which will never fire.
@rtype: L{Deferred}
)r   rX   s   &&rG   rZ   #UnsatisfiedExecSession.request_exec   s     zrJ   rW   Nr]   rR   s   @rG   rd   rd      s     

 
rJ   rd   c                   ,   a  ] tR t^t o R tR tRtV tR# )TrivialRealmc                    / V n         R # NchannelLookuprE   s   &rG   __init__TrivialRealm.__init__   s
    rJ   c                L    \        4       pV P                  Vn        \        VR  3# )c                      R # rj   rW   rW   rJ   rG   <lambda>,TrivialRealm.requestAvatar.<locals>.<lambda>   s    DrJ   )r'   rl   r   )rF   avatarIdmind
interfacesavatars   &&&* rG   requestAvatarTrivialRealm.requestAvatar   s$    #11FL11rJ   rk   N)rK   rL   rM   rN   rm   rw   rP   rQ   rR   s   @rG   rh   rh      s      2 2rJ   rh   c                   *   a  ] tR t^t o RtR tRtV tR# )AddressSpyFactoryNc                :    Wn         \        P                  ! W4      # rj   )addressr   buildProtocol)rF   r|   s   &&rG   r}   AddressSpyFactory.buildProtocol   s    $$T33rJ   )r|   )rK   rL   rM   rN   r|   r}   rP   rQ   rR   s   @rG   rz   rz      s     G4 4rJ   rz   c                   2   a  ] tR t^t o R tR tR tRtV tR# )FixedResponseUIc                    Wn         R # rj   result)rF   r   s   &&rG   rm   FixedResponseUI.__init__   s    rJ   c                ,    \        V P                  4      # rj   )r   r   rF   texts   &&rG   promptFixedResponseUI.prompt   s    t{{##rJ   c                    R # rj   rW   r   s   &&rG   warnFixedResponseUI.warn   s    rJ   r   N)	rK   rL   rM   rN   rm   r   r   rP   rQ   rR   s   @rG   r   r      s     $ rJ   r   c                   @   a  ] tR t^t o ]R 4       t]R 4       tRtV tR# )FakeClockSSHUserAuthServerc                B    V P                   P                  P                  # )za
Use the C{attemptsBeforeDisconnect} value defined by the factory to make
it easier to override.
)	transportfactoryattemptsBeforeDisconnectrE   s   &rG   r   3FakeClockSSHUserAuthServer.attemptsBeforeDisconnect   s     ~~%%>>>rJ   c                B    V P                   P                  P                  # )z
Use the reactor defined by the factory, rather than the default global
reactor, to simplify testing (by allowing an alternate implementation
to be supplied by tests).
)r   r   reactorrE   s   &rG   clock FakeClockSSHUserAuthServer.clock   s     ~~%%---rJ   rW   N)	rK   rL   rM   rN   propertyr   r   rP   rQ   rR   s   @rG   r   r      s+     ? ? . .rJ   r   c                   P   a  ] tR t^t o ]R 4       t]R 4       tR]R]/t	^ t
RtV tR# )CommandFactoryc                <    R \         P                  ! \        R7      /#    ssh-rsa)rY   )r7   
fromStringr=   rE   s   &rG   
publicKeysCommandFactory.publicKeys   s    CNN0ABCCrJ   c                <    R \         P                  ! \        R7      /# r   )r7   r   r;   rE   s   &rG   privateKeysCommandFactory.privateKeys   s    CNN0BCDDrJ   s   ssh-userauths   ssh-connectionrW   N)rK   rL   rM   rN   r   r   r   r   r5   servicesr   rP   rQ   rR   s   @rG   r   r      sK     D D E E 	3=H  !rJ   r   c                       ] tR t^tRtR# )MemoryAddressrW   N)rK   rL   rM   rN   rP   rW   rJ   rG   r   r      s    rJ   r   c                   0   a  ] tR t^t o RtR tR tRtV tR# )SingleUseMemoryEndpointaA  
L{SingleUseMemoryEndpoint} is a client endpoint which allows one connection
to be set up and then exposes an API for moving around bytes related to
that connection.

@ivar pump: L{None} until a connection is attempted, then a L{IOPump}
    instance associated with the protocol which is connected.
@type pump: L{IOPump}
c                     RV n         Wn        R# )zx
@param server: An L{IProtocol} provider to which the client will be
    connected.
@type server: L{IProtocol} provider
N)pump_server)rF   servers   &&rG   rm    SingleUseMemoryEndpoint.__init__   s     	rJ   c           
     .   V P                   e   \        R4      h VP                  \        4       4      p\	        V P
                  \        V P
                  RR7      V\        VRR7      4      V n         \        V4      #   \         d    \        4       u # i ; i)Nz(SingleUseMemoryEndpoint was already usedTisServerF)
r   	Exceptionr}   r   r?   r   rA   r   BaseExceptionr   )rF   r   protocols   && rG   r?   SingleUseMemoryEndpoint.connect   s    99 FGG	%,,]_=H  &t||dC&x%@	DI 8$$  	6M	s   A< <BB)r   r   N)	rK   rL   rM   rN   rO   rm   r?   rP   rQ   rR   s   @rG   r   r      s     % %rJ   r   c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tRR ltR tR tRtV tR# )"SSHCommandClientEndpointTestsMixini  a  
Tests for L{SSHCommandClientEndpoint}, an L{IStreamClientEndpoint}
implementations which connects a protocol with the stdin and stdout of a
command running in an SSH session.

These tests apply to L{SSHCommandClientEndpoint} whether it is constructed
using L{SSHCommandClientEndpoint.existingConnection} or
L{SSHCommandClientEndpoint.newConnection}.

Subclasses must override L{create}, L{assertClientTransportState}, and
L{finishConnection}.
c                   R V n         RV n        RV n        RV n        \	        4       V n        \        4       V n        \        V P                  4      V n	        \        4       V n        V P                  P                  V P                  V P                  4       V P                  P                  V P                  4       \        4       V n        V P
                  V P                  n        V P                  V P                  n	        V P                  P!                  4        V P#                  V P                  P$                  4       \'        RRR4      V n        \'        RRR4      V n        R	# )
s   ssh.example.comi&  s   users   passwordTCPz10.0.0.1i90  z192.168.100.200i1  N)hostnameportuserpasswordr   r   rh   realmr   portalr   passwdDBaddUserregisterCheckerr   r   doStart
addCleanupdoStopr   clientAddressserverAddressrE   s   &rG   setUp(SSHCommandClientEndpointTestsMixin.setUp  s    *		#)+!^
TZZ(?Adii7##DMM2%'#||"kk++,(
EB(0A5IrJ   c                H    \        V P                  P                  : R24      h)z
Create and return a new L{SSHCommandClientEndpoint} to be tested.
Override this to implement creation in an interesting way the endpoint.
z did not implement createNotImplementedError	__class__rK   rE   s   &rG   create)SSHCommandClientEndpointTestsMixin.create1  s'    
 "~~&&))BC
 	
rJ   c                H    \        V P                  P                  : R24      h)aa  
Make an assertion about the connectedness of the given protocol's
transport.  Override this to implement either a check for the
connection still being open or having been closed as appropriate.

@param client: The client whose state is being checked.

@param immediateClose: Boolean indicating whether the connection was
    closed immediately or not.
z- did not implement assertClientTransportStater   rF   clientimmediateCloses   &&&rG   assertClientTransportState=SSHCommandClientEndpointTestsMixin.assertClientTransportState:  s#     "~~&&)
 	
rJ   c                H    \        V P                  P                  : R24      h)zp
Do any remaining work necessary to complete an in-memory connection
attempted initiated using C{self.reactor}.
z# did not implement finishConnectionr   rE   s   &rG   finishConnection3SSHCommandClientEndpointTestsMixin.finishConnectionJ  s'    
 "~~&&))LM
 	
rJ   c                    VP                  R4      pVP                  R4      p\        VRV P                  V P                  R7      p\        VRV P                  V P                  R7      p\	        WFW54      pWCV3# )a?  
Set up an in-memory connection between protocols created by
C{serverFactory} and C{clientFactory}.

@return: A three-tuple.  The first element is the protocol created by
    C{serverFactory}.  The second element is the protocol created by
    C{clientFactory}.  The third element is the L{IOPump} connecting
    them.
NF)r   hostAddresspeerAddressT)r}   rA   r   r   r?   )rF   serverFactoryclientFactoryclientProtocolserverProtocolclientTransportserverTransportr   s   &&&     rG   connectedServerAndClient;SSHCommandClientEndpointTestsMixin.connectedServerAndClientS  s     '44T:&44T:0****	
 1****	
 ~Xt33rJ   c                H   V P                  4       p\        4       p\        Vn        VP	                  V4      pV P                  4       w  rEpV P                  \        4      pV P                  RV^ ,          P                  P                  V^ ,          P                  P                  34       V P                  ^\        V4      4       V P                  V4      pVP                  \        4       V P                  RVP                  P                  4       V P                  VR4       R# )z
If a channel cannot be opened on the authenticated SSH connection, the
L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires with
a L{Failure} wrapping the reason given by the server.
unknown channel   unknown channelFN)r   r   r   r   r?   r   flushLoggedErrorsr   assertInvaluerY   assertEquallenfailureResultOftrapr   )	rF   endpointr   	connectedr   r   r   errorsfs	   &        rG   test_channelOpenFailure:SSHCommandClientEndpointTestsMixin.test_channelOpenFailurep  s     ;;=)#$$W-	#446 ''
3'&)//*>*>q	@U@U)VWCK(   +	z+QWW]];''6rJ   c                   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpV P                  V4      pVP                  \        4       V P                  RVP                  P                  4       V P                  VR4       R# )z
If execution of the command fails, the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
the reason given by the server.
   sessionzchannel request failedFN)rU   r   rl   r   r   r   r   r?   r   r   r   r   r   r   r   rF   r   r   r   r   r   r   r   s   &       rG   test_execFailure3SSHCommandClientEndpointTestsMixin.test_execFailure  s     0A

  ,;;=)#$$W-	#446  +	z1177==A''6rJ   c                b   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpVP                  4        V P                  V4      pVP                  \        4       V P                  VR4       R# )z
If execution of the command is cancelled via the L{Deferred} returned
by L{SSHCommandClientEndpoint.connect}, the connection is closed
immediately.
r   TN)rd   r   rl   r   r   r   r   r?   r   cancelr   r   r   r   r   s   &       rG   test_execCancelled5SSHCommandClientEndpointTestsMixin.test_execCancelled  s     0F

  ,;;=)#$$W-	#446  +	~''5rJ   c                :   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4       V P                  4       w  r4pV P                  VP                  \        4       V P                  VP                  P                  4       VP                  P                  4       V P                  V P                   VP                  P"                  4       V P                  RVP                  P$                  4       R# )a  
Once the necessary SSH actions have completed successfully,
L{SSHCommandClientEndpoint.connect} uses the factory passed to it to
construct a protocol instance by calling its C{buildProtocol} method
with an address object representing the SSH connection and command
executed.
r   
   /bin/ls -lN)r`   r   rl   r   rz   r   r   r?   r   assertIsInstancer|   r-   r   r   getHostr   r   usernamecommand)rF   r   r   r   r   r   s   &     rG   test_buildProtocol5SSHCommandClientEndpointTestsMixin.test_buildProtocol  s     0B

  ,;;=#%#!#446goo/@A))113W__5K5KLGOO$<$<=(?(?@rJ   c                *   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpV P                  V4      pV P                  VP                  4       R# )z
L{SSHCommandClientEndpoint} establishes an SSH connection, creates a
channel in it, runs a command in that channel, and uses the protocol's
C{makeConnection} to associate it with a protocol representing that
command's stdin and stdout.
r   N)r`   r   rl   r   r   r   r   r?   r   successResultOfassertIsNotNoner   rF   r   r   r   r   r   r   r   s   &       rG   test_makeConnection6SSHCommandClientEndpointTestsMixin.test_makeConnection  sz     0B

  ,;;=)#$$W-	#446''	2X//0rJ   c                    \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpV P                  V4      p. pVP                  Vn        VP                  P                  p	VP                  P                  V	,          P!                  R4       VP#                  4        V P%                  RRP'                  V4      4       R# )z
After establishing the connection, when the command on the SSH server
produces output, it is delivered to the protocol's C{dataReceived}
method.
r      hello, worldrJ   N)r`   r   rl   r   r   r   r   r?   r   r  appenddataReceivedr   idservicechannelswriter   r   join)
rF   r   r   r   r   r   r   r   r  	channelIds
   &         rG   test_dataReceived4SSHCommandClientEndpointTestsMixin.test_dataReceived  s     0B

  ,;;=)#$$W-	#446''	2 , 3 3 &&))		*00A		#((<*@ArJ   c                   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpV P                  V4      p. pVP                  Vn        VP                  P                  p	VP                  P                  V	,          P!                  4        VP#                  4        V^ ,          P%                  \&        4       V P)                  VR4       R# )zY
When the command closes the channel, the protocol's C{connectionLost}
method is called.
r   FN)r`   r   rl   r   r   r   r   r?   r   r  r  connectionLostr   r  r  r  loseConnectionr   r   r   r   )
rF   r   r   r   r   r   r   r   r  r  s
   &         rG   test_connectionLost6SSHCommandClientEndpointTestsMixin.test_connectionLost  s    
 0B

  ,;;=)#$$W-	#446''	2"0"7"7 &&))		*99;		q~.''6rJ   c                *   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rgpV P                  V4      p	. p
V
P                  V	n        V	P                  P                  pVP                  P                  V,          pVP                  P!                  WV4       VP#                  4        VP%                  4        V P'                  VR4       V
^ ,          # )z:
Test handling of non-zero exit statuses or exit signals.
r   F)r`   r   rl   r   r   r   r   r?   r   r  r  r  r   r  r  r  sendRequestr  r   r   )rF   request
requestArgr   r   r   r   r   r   r   r  r  channels   &&&          rG   _exitStatusTest2SSHCommandClientEndpointTestsMixin._exitStatusTest  s     0B

  ,;;=)#$$W-	#446''	2"0"7"7
 &&))	..)))4""7Z@ 		''6a  rJ   c                l    ^ pV P                  R\        RV4      4      pVP                  \        4       R# )
When the command exits with a non-zero status, the protocol's
C{connectionLost} method is called with a L{Failure} wrapping an
exception which encapsulates that status.
   exit-status>LN)r   r   r   r   )rF   exitCodeexcs   &  rG   test_zeroExitCode4SSHCommandClientEndpointTestsMixin.test_zeroExitCode2  s.     "">4h3GH rJ   c                   ^{pRpV P                  R\        RV4      4      pVP                  \        4       V P	                  WP
                  P                  4       V P	                  W#P
                  P                  4       R# )r#  Nr$  r%  )r   r   r   r   r   r   r&  signal)rF   r&  r+  r'  s   &   rG   test_nonZeroExitStatus9SSHCommandClientEndpointTestsMixin.test_nonZeroExitStatus<  sd     "">4h3GH"#99#5#56!1!12rJ   c                   \        4       p\        P                  ! V4       V P                  \        P                  V4       Rp^pRP                  \        P                  ! R4      R\        P                  ! R4      \        P                  ! R4      .4      pV P                  RV4      pVP                  \        4       V P                  W%P                  P                  4       V P                  W5P                  P                  4       Rp\        P                   ! V\        P"                  ! \        P$                  ! R	\        P&                  ! \(        P*                  4      R
VRRRRRRRR/4      4      4       R# )z
When the command exits with a non-zero signal, the protocol's
C{connectionLost} method is called with a L{Failure} wrapping an
exception which encapsulates that status.

Additional packet contents are logged at the C{info} level.
NrJ   s   TERM   s   messages   en-USs   exit-signalz'twisted.conch.endpoints._CommandChannel	log_levellog_namespaceshortSignalName
coreDumpedTerrorMessagemessagelanguageTag)r   r   addObserverr   removeObserverr  r2   NSr   r   r   r   r   r&  r+  hamcrestassert_thathas_itemhas_entriesequal_tor   info)rF   logObserverr&  r+  packetr'  logNamespaces   &      rG   test_nonZeroExitSignal9SSHCommandClientEndpointTestsMixin.test_nonZeroExitSignalI  s(    +,&&{3*99;G		'"		*%		(#
 "">6:"#99#5#56!1!12@$$#X%6%6x}}%E')7$d&	%x		
rJ   c                   a VP                   P                  p. oV'       d   V3R lpMSP                  p\        VP                  P
                  V,          W64       S# )z
Hook into and record events which happen to C{protocol}.

@param server: The SSH server protocol over which C{protocol} is
    running.
@type server: L{IProtocol} provider

@param protocol:

@param event:

@param noArgs:
c                  &   < S P                  R 4      # rj   )r  )recorders   rG   rq   ;SSHCommandClientEndpointTestsMixin.record.<locals>.<lambda>  s    -rJ   )r   r  r  setattrr  r  )rF   r   r   eventnoArgsr  r   rG  s   &&&&&  @rG   record)SSHCommandClientEndpointTestsMixin.recordw  sJ      &&))	-AA''	2E=rJ   c                   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpV P                  V4      pV P                  WGR4      pVP                  P                  R4       VP                  4        V P                  RRP                  V4      4       R# )z
The transport connected to the protocol has a C{write} method which
sends bytes to the input of the command executing on the SSH server.
r   r  r  rJ   N)r`   r   rl   r   r   r   r   r?   r   r  rL  r   r  r   r   r  	rF   r   r   r   r   r   r   r   r  s	   &        rG   
test_write-SSHCommandClientEndpointTestsMixin.test_write  s    
 0B

  ,;;=)#$$W-	#446''	2{{6^D  1		#((<*@ArJ   c                   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpV P                  V4      pV P                  WGR4      pVP                  P                  R.4       VP                  4        V P                  RRP                  V4      4       R# )z
The transport connected to the protocol has a C{writeSequence} method which
sends bytes to the input of the command executing on the SSH server.
r   r  r  rJ   N)r`   r   rl   r   r   r   r   r?   r   r  rL  r   writeSequencer   r   r  rO  s	   &        rG   test_writeSequence5SSHCommandClientEndpointTestsMixin.test_writeSequence  s    
 0B

  ,;;=)#$$W-	#446''	2{{6^D((/):;		#((<*@ArJ   )r   r   r   r   r   r   r   r   r   r   r   N)F)rK   rL   rM   rN   rO   r   r   r   r   r   r   r   r   r  r  r  r  r   r(  r,  rC  rL  rP  rT  rP   rQ   rR   s   @rG   r   r     su     J(

 
4:747*6*A.1&B678!:!3,
\6B*B BrJ   r   c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )NewConnectionTestsi  zT
Tests for L{SSHCommandClientEndpoint} when using the C{newConnection}
constructor.
c                   \         P                  V 4       \        V P                  4       4      V n        \        V P                  4      V n        V P                  P                  V P                  V P                  P                  R,          4       V P                  P                  \        V P                  P                  4      V P                  P                  R,          4       V P                  P                  4        R# )g
Configure an SSH server with password authentication enabled for a
well-known (to the tests) account.
r   N)r   r   r"   mktemphostKeyPathr+   
knownHosts
addHostKeyr   r   r   r    r   hostsaverE   s   &rG   r   NewConnectionTests.setUp  s    
 	+006#DKKM2()9)9:""4==$,,2I2I*2UV""$,,112DLL4K4KJ4W	
 	rJ   c                    \         P                  ! V P                  RV P                  V P                  V P
                  V P                  V P                  \        R4      R7      # )z]
Create and return a new L{SSHCommandClientEndpoint} using the
C{newConnection} constructor.
r   Fr   r\  ui)	r.   newConnectionr   r   r   r   r   r\  r   rE   s   &rG   r   NewConnectionTests.create  sL    
 (55LLIIMMII]]u%	
 		
rJ   c                ~    V P                  V P                  V P                  P                  ^ ,          ^,          4      # )ze
Establish the first attempted TCP connection using the SSH server which
C{self.factory} can create.
)r   r   r   
tcpClientsrE   s   &rG   r   #NewConnectionTests.finishConnection  s4    
 ,,LL$,,11!4Q7
 	
rJ   c                    V P                  WRRR7      pVP                  P                  4        VP                  4        V P	                  R.V4       VP                  4        VP                  P                  4        R# )a_  
Lose the connection to a server and pump the L{IOPump} sufficiently for
the client to handle the lost connection. Asserts that the client
disconnects its transport.

@param server: The SSH server protocol over which C{protocol} is
    running.
@type server: L{IProtocol} provider

@param client: The SSH client protocol over which C{protocol} is
    running.
@type client: L{IProtocol} provider

@param protocol: The protocol created by calling connect on the ssh
    endpoint under test.
@type protocol: L{IProtocol} provider

@param pump: The L{IOPump} connecting client to server.
@type pump: L{IOPump}
closedT)rK  N)rL  r   r  r   r   reportDisconnect)rF   r   r   r   r   rj  s   &&&&& rG   loseConnectionToServer)NewConnectionTests.loseConnectionToServer  sd    * VxE))+		$(
 			 	))+rJ   c                    V'       d(   V P                  VP                  P                  4       R# V P                  VP                  P                  4       R# )z
Assert that the transport for the given protocol has been disconnected.
L{SSHCommandClientEndpoint.newConnection} creates a new dedicated SSH
connection and cleans it up after the command exits.
N)
assertTruer   rD   disconnectingr   s   &&&rG   r   -NewConnectionTests.assertClientTransportState  s7     OOF,,445OOF,,::;rJ   c                    \         P                  ! V P                  RRV P                  V P                  4      pV P                  \        \        V4      4       R# )zI
L{SSHCommandClientEndpoint} instances provide L{IStreamClientEndpoint}.
   dummy command
   dummy userN)r.   rd  r   r   r   ro  r   r   rF   r   s   & rG   test_interface!NewConnectionTests.test_interface  sB     ,99LL*M4==$))
 	%:HEFrJ   c                    \         P                  ! V P                  RRV P                  4      pV P	                  ^VP
                  P                  4       R# )zn
L{SSHCommandClientEndpoint} uses the default port number for SSH when
the C{port} argument is not specified.
rs  rt  Nr.   rd  r   r   r   _creatorr   ru  s   & rG   test_defaultPort#NewConnectionTests.test_defaultPort$  sD    
 ,99LL*M4==
 	X..334rJ   c                    \         P                  ! V P                  RRV P                  RR7      pV P	                  RVP
                  P                  4       R# )zE
L{SSHCommandClientEndpoint} uses the C{port} argument if specified.
rs  rt  i  )r   Nry  ru  s   & rG   test_specifiedPort%NewConnectionTests.test_specifiedPort.  sF     ,99LL*M4==t
 	x00556rJ   c                :   \         P                  ! V P                  RV P                  V P                  V P
                  V P                  V P                  \        R4      R7      p\        4       p\        Vn        VP                  V4       V P                  P                  ^ ,          w  r4r%pV P                  V P                  \        V4      4       V P                  V P
                  V4       V P                  ^\!        V P                  P                  4      4       R# )z
L{SSHCommandClientEndpoint} uses the L{IReactorTCP} passed to it to
attempt a connection to the host/port address also passed to it.
r   Frb  N)r.   rd  r   r   r   r   r   r\  r   r   r   r   r?   rg  r   r    r   )rF   r   r   r^  r   timeoutbindAddresss   &      rG   test_destination#NewConnectionTests.test_destination7  s    
 ,99LLIIMMII]]u%	
 )#!48LL4K4KA4N1Gkd(;<D)C 7 789rJ   c                   \         P                  ! V P                  RRV P                  V P                  V P
                  \        R4      R7      p\        4       p\        Vn	        VP                  V4      pV P                  P                  ^ ,          ^,          pVP                  R\        \        4       4      4       V P                  V4      P!                  \        4       R# )z
If a connection cannot be established, the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure}
representing the reason for the connection setup failure.
r   rt  Fr\  rc  N)r.   rd  r   r   r   r\  r   r   r   r   r?   rg  clientConnectionFailedr!   r   r   r   rF   r   r   ds   &   rG   test_connectionFailed(NewConnectionTests.test_connectionFailedO  s     ,99LLMMIIu%
 )#W%,,))!,Q/&&tW5K5M-NOQ$$%;<rJ   c                   \         P                  ! V P                  RRV P                  V P                  \        V P                  4       4      \        R4      R7      p\        4       p\        Vn
        VP                  V4      pV P                  V P                  V P                  P                  ^ ,          ^,          4      w  rEpV P                  V4      pVP!                  \"        4       R# )z
If the L{KnownHostsFile} instance used to construct
L{SSHCommandClientEndpoint} rejects the SSH public key presented by the
server, the L{Deferred} returned by L{SSHCommandClientEndpoint.connect}
fires with a L{Failure} wrapping L{UserRejectedKey}.
r   rt  Fr  N)r.   rd  r   r   r   r+   rZ  r   r   r   r   r?   r   r   rg  r   r   r
   r   s   &       rG   test_userRejectedHostKey+NewConnectionTests.test_userRejectedHostKeyg  s     ,99LLMMII%dkkm4u%
 )#$$W-	#<<LL$,,11!4Q7 
   +	rJ   c                ,   \         P                  ! \        4      P                  4       p\	        \        V P                  4       4      4      pVP                  \        V P                  P                  4      V4       \         P                  ! \        RR7      P                  4       pVP                  V P                  V4       \        R4      p\        P                  ! V P                   RRV P                  V P"                  RVVR7      p\%        4       p\&        Vn        VP+                  V4      pV P-                  V P.                  V P                   P0                  ^ ,          ^,          4      w  rp
V P3                  V4      pVP5                  \6        4       R# )	a3  
If the SSH public key presented by the SSH server does not match the
previously remembered key, as reported by the L{KnownHostsFile}
instance use to construct the endpoint, for that server, the
L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires with
a L{Failure} wrapping L{HostKeyChanged}.
s   testxp)
passphraseTr   rt     dummy passwordrb  N)r7   r   r;   publicr+   r"   rZ  r]  r    r   r^  r<   r   r   r.   rd  r   r   r   r   r   r?   r   r   rg  r   r   r	   )rF   firstKeyr\  differentKeyrc  r   r   r   r   r   r   r   s   &           rG   test_mismatchedHostKey)NewConnectionTests.test_mismatchedHostKey  s6    >>"45<<>#HT[[]$;<
mD,>,>,C,CDhO~~,

&( 	 	dmm\:
 T"+99LLMMII&!	
 )#$$W-	#<<LL$,,11!4Q7 
   +	~rJ   c                   \         P                  ! V P                  RRV P                  V P                  V P
                  \        R4      R7      p\        4       p\        Vn	        VP                  V4      p\        4       pV P                  P                  ^ ,          ^,          pVP                  R4      pVP                  V4       VP                  \!        \#        4       4      4       V P%                  V4      P'                  \"        4       R# )a%  
If the connection closes at any point before the SSH transport layer
has finished key exchange (ie, gotten to the point where we may attempt
to authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
the reason for the lost connection.
r   rt  Fr  N)r.   rd  r   r   r   r\  r   r   r   r   r?   r   rg  r}   makeConnectionr  r!   r   r   r   rF   r   r   r  r   r   s   &     rG   !test_connectionClosedBeforeSecure4NewConnectionTests.test_connectionClosedBeforeSecure  s     ,99LLMMIIu%
 )#W%#%	,,))!,Q/&&t,i(gn&678Q$$^4rJ   c                v   \         P                  ! V P                  RRV P                  V P                  V P
                  \        R4      R7      p\        4       p\        Vn	        VP                  V4      p\        RRR7      pV P                  P                  ^ ,          ^,          pVP                  R4      pVP                  V4       VP                  4        V P!                  V4      P#                  \$        4       V P'                  VP(                  4       VP+                  \-        \/        4       4      4       R# )a+  
If the connection is cancelled before the SSH transport layer has
finished key exchange (ie, gotten to the point where we may attempt to
authenticate), the L{Deferred} returned by
L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
L{CancelledError} and the connection is aborted.
r   rt  Fr  Nr   )r.   rd  r   r   r   r\  r   r   r   r   r?   rA   rg  r}   r  r   r   r   r   ro  rD   r  r!   r   r  s   &     rG   $test_connectionCancelledBeforeSecure7NewConnectionTests.test_connectionCancelledBeforeSecure  s     ,99LLMMIIu%
 )#W%*4%@	,,))!,Q/&&t,i(	
Q$$^4	))* 	gn&678rJ   c                   \         P                  ! V P                  RRV P                  V P                  V P
                  \        R4      R7      p\        4       p\        Vn	        VP                  V4      pVP                  4        V P                  V4      P                  \        4       V P                  V P                  P                   ^ ,          P"                  4       R# )zb
If the connection is cancelled before it finishes connecting, the
connection attempt is stopped.
r   rt  Fr  N)r.   rd  r   r   r   r\  r   r   r   r   r?   r   r   r   r   ro  
connectorsstoppedConnectingr  s   &   rG   'test_connectionCancelledBeforeConnected:NewConnectionTests.test_connectionCancelledBeforeConnected  s    
 ,99LLMMIIu%
 )#W%	
Q$$%=>//2DDErJ   c                `   \         P                  ! V P                  RRV P                  V P                  RV P
                  \        R4      R7      p\        4       p\        Vn	        VP                  V4      pV P                  V P                  V P                  P                  ^ ,          ^,          4      w  rEpV P                  P                  VP                  P                   4       VP#                  4        V P%                  V4      pVP'                  \(        4       V P+                  VR4       R# )z
If the SSH server rejects the password presented during authentication,
the L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires
with a L{Failure} wrapping L{AuthenticationFailed}.
r   rt  r  Frb  N)r.   rd  r   r   r   r\  r   r   r   r   r?   r   r   rg  advancer  passwordDelayflushr   r   r,   r   r   s   &       rG   "test_passwordAuthenticationFailure5NewConnectionTests.test_passwordAuthenticationFailure  s     ,99LLMMII&u%	
 )#$$W-	#<<LL$,,11!4Q7 
 	V^^99: 	

  +	#$ 	''6rJ   c                    VP                  4        UUu/ uF+  w  r4V\        P                  ! V4      P                  4       .bK-  	  ppp\	        \        V4      4      pVP                  V4       R# u uppi )at  
Create an L{ISSHPrivateKey} checker which recognizes C{users} and add it
to C{portal}.

@param portal: A L{Portal} to which to add the checker.
@type portal: L{Portal}

@param users: The users and their keys the checker will recognize.  Keys
    are byte strings giving user names.  Values are byte strings giving
    OpenSSH-formatted private keys.
@type users: L{dict}
N)itemsr7   r   r  r)   r(   r   )rF   r   userskvmappingcheckers   &&&    rG   setupKeyChecker"NewConnectionTests.setupKeyChecker-  s`     @E{{}M}tq1s~~a(//122}M%&6w&?@w' Ns   1A/c                   \         P                  ! \        4      pV P                  V P                  V P
                  \        /4       \        P                  ! V P                  RV P
                  V P                  V P                  V.V P                  \        R4      R7      p\        4       p\        Vn        VP#                  V4      pV P%                  V P&                  V P                  P(                  ^ ,          ^,          4      w  rVpV P+                  V4      pVP-                  \.        4       V P1                  VP2                  P4                  4       R# )z
If the SSH server rejects the key pair presented during authentication,
the L{Deferred} returned by L{SSHCommandClientEndpoint.connect} fires
with a L{Failure} wrapping L{AuthenticationFailed}.
r   Fkeysr\  rc  N)r7   r   r;   r  r   r   r:   r.   rd  r   r   r   r\  r   r   r   r   r?   r   r   rg  r   r   r,   ro  r   rp  )	rF   badKeyr   r   r   r   r   r   r   s	   &        rG   #test_publicKeyAuthenticationFailure6NewConnectionTests.test_publicKeyAuthenticationFailure>  s      23T[[4996H*IJ+99LLIIMMIIu%	
 )#$$W-	#<<LL$,,11!4Q7 
   +	#$ 	((667rJ   c                f   \         P                  ! \        4      pV P                  V P                  V P
                  \        /4       \        P                  ! V P                  RV P
                  V P                  V P                  V.V P                  V P                  \        R4      R7	      p\        4       p\         Vn        VP%                  V4      pV P&                  ;P(                  ^,          un        V P+                  V P&                  V P                  P,                  ^ ,          ^,          4      w  rVpVP/                  4        V P1                  \2        4      pV P5                  RV^ ,          P6                  P8                  V^ ,          P6                  P6                  34       V P;                  ^\=        V4      4       V P?                  V4      p	V	PA                  \2        4       V P;                  RV	P6                  P6                  4       V PC                  VPD                  PF                  4       R# )zc
If the SSH server does not accept any of the specified SSH keys, the
specified password is tried.
r   F)r  r   r\  rc  r   r   N)$r7   r   r;   r  r   r   r:   r.   rd  r   r   r   r   r\  r   r   r   r   r?   r   r   r   rg  r   r   r   r   r   rY   r   r   r   r   ro  r   rp  )
rF   r  r   r   r   r   r   r   r   r   s
   &         rG   test_authenticationFallback.NewConnectionTests.test_authenticationFallbackc  s   
  23T[[4996H*IJ+99LLIIMMII]]u%

 )#$$W-	 	--2-#<<LL$,,11!4Q7 
 			 ''
3'&)//*>*>q	@U@U)VWCK(   +	z+QWW]]; 	((667rJ   c                   \         P                  ! \        4      pV P                  V P                  V P
                  \        /4       \        V P                  P                  R&   \        P                  ! V P                  RV P
                  V P                  V P                  V.V P                  \        R4      R7      p\!        4       p\"        Vn        VP'                  V4      pV P)                  V P*                  V P                  P,                  ^ ,          ^,          4      w  rVpV P/                  V4      pV P1                  VP2                  4       R# )z
If L{SSHCommandClientEndpoint} is initialized with any private keys, it
will try to use them to authenticate with the SSH server.
r   r   Fr  N)r7   r   r:   r  r   r   r`   r   rl   r.   rd  r   r   r   r\  r   r   r   r   r?   r   r   rg  r  r  r   )	rF   keyr   r   r   r   r   r   r   s	   &        rG   test_publicKeyAuthentication/NewConnectionTests.test_publicKeyAuthentication  s   
 nn/0T[[4996H*IJ/A

  ,+99LLIIMMIIu%	
 )#$$W-	#<<LL$,,11!4Q7 
 ''	2X//0rJ   c                :   \         P                  ! V P                  RV P                  V P                  V P
                  V P                  \        R4      R7      p\        4       p\        Vn
        VP                  V4      pV P                  V P                  V P                  P                  ^ ,          ^,          4      w  rEpVP                  4        V P!                  V4      pVP#                  \$        4       V P'                  VP(                  P*                  4       R# )zn
If the password is not specified, L{SSHCommandClientEndpoint} doesn't
try it as an authentication mechanism.
r   Fr  N)r.   rd  r   r   r   r   r\  r   r   r   r   r?   r   r   rg  r   r   r   r,   ro  r   rp  r   s   &       rG   test_skipPasswordAuthentication2NewConnectionTests.test_skipPasswordAuthentication  s    
 ,99LLIIMMIIu%
 )#$$W-	#<<LL$,,11!4Q7 
 			   +	#$ 	((667rJ   c                v   \         P                  ! \        4      p\        4       p\	        4       Vn        VP                  4       VR3/VP
                  n        V P                  V P                  V P                  \        /4       \        V4      p\        P                  ! V P                  RV P                  V P                  V P                   V P"                  \%        R4      VR7      p\&        V P(                  P*                  R&   \	        4       p\,        Vn        VP1                  V4      pV P3                  V P
                  V P                  P4                  ^ ,          ^,          4      w  rxp	\7        ^4       F-  p
VP8                  P9                  4        V	P9                  4        K/  	  V P;                  V4      pV P=                  VP>                  4       V PA                  WxW4       V PC                  VP>                  PD                  4       V PC                  VP8                  PF                  PD                  4       R# )z
If L{SSHCommandClientEndpoint} is initialized with an
L{SSHAgentClient}, the agent is used to authenticate with the SSH
server. Once the connection with the SSH server has concluded, the
connection to the agent is disconnected.
rJ   r   F)r\  rc  agentEndpointr   N)$r7   r   r;   r3   r   r   blobr  r  r   r   r   r.   rd  r   r   r   r\  r   r`   r   rl   r   r   r?   r   rg  ranger   r  r  r   rl  ro  rp  clientIO)rF   r  agentServerr  r   r   r   r   r   r   ir   s   &           rG   test_agentAuthentication+NewConnectionTests.test_agentAuthentication  s    nn/0$&%i$'HHJc
#; T[[4996H*IJ/<+99LLIIMMIIu%'	
 0B

  ,)#$$W-	#<<LL$,,11!4Q7 
 rA##%IIK  ''	2X//0 	##FHC((667**33AABrJ   c                b   \         V P                  P                  R&   V P                  4       p\	        4       p\
        Vn        VP                  V4      pV P                  4       w  rEpV P                  V4      pV P                  WEWv4       V P                  VP                  P                  4       R# )z
The transport connected to the protocol has a C{loseConnection} method
which causes the channel in which the command is running to close and
the overall connection to be closed.
r   N)r`   r   rl   r   r   r   r   r?   r   r  rl  ro  r   rp  r  s   &       rG   test_loseConnection&NewConnectionTests.test_loseConnection  s     0B

  ,;;=)#$$W-	#446''	2##FHC 	((667rJ   )r[  r\  N)rK   rL   rM   rN   rO   r   r   r   rl  r   rv  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rP   rQ   rR   s   @rG   rW  rW    s     

 
!,F<G57:0=0 8*X5< 9DF,&7P("#8J.8`1>8B1Cf8 8rJ   rW  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	ExistingConnectionTestsi  zY
Tests for L{SSHCommandClientEndpoint} when using the C{existingConnection}
constructor.
c                2   \         P                  V 4       \        \        V P	                  4       4      4      pVP                  V P                  V P                  P                  R,          4       VP                  \        V P                  P                  4      V P                  P                  R,          4       \        P                  ! V P                  RV P                  V P                  V P                   V P"                  V\%        R4      R7      V n        R# )rY  r   r   Frb  N)r   r   r+   r"   rZ  r]  r   r   r   r    r   r^  r.   rd  r   r   r   r   r   r   )rF   r\  s   & rG   r   ExistingConnectionTests.setUp#  s    
 	+006#HT[[]$;<
dmmT\\-D-DZ-PQ$,,112DLL4K4KJ4W	
 1>>LLIIMMII]]!u%	
rJ   c                6   \        4       p\        Vn        V P                  P	                  V4      pV P
                  P                  P                  4       p \        V P
                  P                  R&   V P                  V P                  V P                  P                  ^ ,          ^,          4      w  rEpV P
                  P                  P                  4        V P
                  P                  P                  V4       W@n        WPn        W`n        V P%                  V4      pVP&                  P(                  p\*        P,                  ! VR4      #   T P
                  P                  P                  4        T P
                  P                  P                  T4       i ; i)zb
Create and return a new L{SSHCommandClientEndpoint} using the
C{existingConnection} constructor.
r   r   )r   r   r   r   r?   r   rl   copyr`   r   r   r   rg  clearupdater   _client_pumpr  r   connr.   existingConnection)	rF   r   r   rl   r   r   r   r   
connections	   &        rG   r   ExistingConnectionTests.create;  s1   
 )#MM))'2	 

00557		;3EDJJ$$Z0#'#@#@dll55a8;$ FD
 JJ$$**,JJ$$++M:
''	2'',,
':::}UU JJ$$**,JJ$$++M:s   AE AFc                   V P                   P                  4        V P                   P                  4        V P                   P                  4        V P                   P                  4        V P                  V P                  V P                   3# )zw
Give back the connection established in L{create} over which the new
command channel being tested will exchange data.
)r  r   r   r  rE   s   &rG   r   (ExistingConnectionTests.finishConnectionY  sU     	







||T\\4::55rJ   c                    V P                  VP                  P                  4       V P                  VP                  P                  4       R# )z
Assert that the transport for the given protocol is still connected.
L{SSHCommandClientEndpoint.existingConnection} re-uses an SSH connected
created by some other code, so other code is responsible for cleaning
it up.
N)assertFalser   rp  rD   r   s   &&&rG   r   2ExistingConnectionTests.assertClientTransportStateg  s8     	))778))112rJ   )r  r  r   r   N)rK   rL   rM   rN   rO   r   r   r   r   rP   rQ   rR   s   @rG   r  r    s$     

0V<63 3rJ   r  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	ExistingConnectionHelperTestsir  z)
Tests for L{_ExistingConnectionHelper}.
c                L    V P                  \        \        \        4      4       R# )zD
L{_ExistingConnectionHelper} implements L{_ISSHConnectionCreator}.
N)ro  r   r0   r/   rE   s   &rG   rv  ,ExistingConnectionHelperTests.test_interfacew  s     	$:<UVWrJ   c                    \        4       p\        V4      pV P                  WP                  VP	                  4       4      4       R# )z
L{_ExistingConnectionHelper.secureConnection} returns a L{Deferred}
which fires with whatever object was fed to
L{_ExistingConnectionHelper.__init__}.
N)objectr/   assertIsr  secureConnection)rF   r   helpers   &  rG   test_secureConnection3ExistingConnectionHelperTests.test_secureConnection}  s5     *62f2263J3J3LMNrJ   c                `    \        \        4       4      pVP                  \        4       R4       R# )z
L{_ExistingConnectionHelper.cleanupConnection} does nothing to the
existing connection if called with C{immediate} set to C{False}.
FNr/   r  cleanupConnectionrF   r  s   & rG   $test_cleanupConnectionNotImmediatelyBExistingConnectionHelperTests.test_cleanupConnectionNotImmediately  s$    
 +684 	  51rJ   c                `    \        \        4       4      pVP                  \        4       R4       R# )z
L{_ExistingConnectionHelper.cleanupConnection} does nothing to the
existing connection if called with C{immediate} set to C{True}.
TNr  r  s   & rG   !test_cleanupConnectionImmediately?ExistingConnectionHelperTests.test_cleanupConnectionImmediately  s$    
 +684 	  40rJ   rW   N)rK   rL   rM   rN   rO   rv  r  r  r  rP   rQ   rR   s   @rG   r  r  r  s%     XO	2	1 	1rJ   r  c                   2   a  ] tR tRt o V 3R lR ltRtV tR# )_WriteDiscarderi  c                &   < V ^8  d   QhRS[ RS[/# )   rY   return)r  int)formatrS   s   "rG   __annotate___WriteDiscarder.__annotate__  s      &  rJ   c                   ^ # )z
Discard writes because we are emulating a console object, where they'd
go to the screen, not back into the buffer to be read like an a+ file.
rW   rX   s   ""rG   r  _WriteDiscarder.write  s    
 rJ   rW   N)rK   rL   rM   rN   r  rP   rQ   rR   s   @rG   r  r    s      rJ   r  c                   H   a  ] tR tRt o RtV 3R lR ltV 3R lR ltRtV tR# )	_PTYPathi  z_
A L{FilePath}-like object which can be opened to create a L{_ReadFile} with
certain contents.
c                $   < V ^8  d   QhRS[ RR/# )r  contentsr  N)bytes)r  rS   s   "rG   r  _PTYPath.__annotate__  s     ! ! !4 !rJ   c                    Wn         R# )zb
@param contents: L{bytes} which will be the contents of the
    L{_ReadFile} this path can open.
Nr  )rF   r  s   &&rG   rm   _PTYPath.__init__  s	    
 !rJ   c                6   < V ^8  d   QhRS[ RS[S[,          /# )r  moder  )strr   r  )r  rS   s   "rG   r  r    s     . . .E .rJ   c                >    VR8X  g   Q h\        V P                  4      # )z
If the mode is r+, return a file with the given contents as a line.

@return: a buffer of the given contents, which will discard any writes
    given to it.
zr+)r  r  )rF   r  s   &&rG   open_PTYPath.open  s     t||t}}--rJ   r  N)	rK   rL   rM   rN   rO   rm   r  rP   rQ   rR   s   @rG   r  r    s     
! !. .rJ   r  c                   l   a  ] tR tRt o RtR tR tV 3R lR ltR tR t	R	 t
R
 tR tR tR tRtV tR# )NewConnectionHelperTestsi  z$
Tests for L{_NewConnectionHelper}.
c                L    V P                  \        \        \        4      4       R# )z?
L{_NewConnectionHelper} implements L{_ISSHConnectionCreator}.
N)ro  r   r0   r1   rE   s   &rG   rv  'NewConnectionHelperTests.test_interface  s     	$:<PQRrJ   c                F    V P                  R\        P                  4       R# )z;
The default I{known_hosts} path is I{~/.ssh/known_hosts}.
z~/.ssh/known_hostsN)r   r1   _KNOWN_HOSTSrE   s   &rG   test_defaultPath)NewConnectionHelperTests.test_defaultPath  s     	-/C/P/PQrJ   c                   < V ^8  d   QhRR/# )r  r  NrW   )r  rS   s   "rG   r  %NewConnectionHelperTests.__annotate__  s     1 1 1rJ   c                   a \        4       oV P                  \        RV3R l4       \        RRRRRRRRRR4
      pV P                  SVP                  4       R# )zt
L{_NewConnectionHelper._knownHosts} is used to create a
L{KnownHostsFile} if one is not passed to the initializer.
_knownHostsc                    < S# rj   rW   )clsignoredr   s   &&rG   rq   ANewConnectionHelperTests.test_defaultKnownHosts.<locals>.<lambda>  s    VrJ   N)r  patchr1   r  r\  )rF   r  r   s   & @rG   test_defaultKnownHosts/NewConnectionHelperTests.test_defaultKnownHosts  s\    
 

'8ST%
 	ff//0rJ   c                (   \        4       P                  R,          p\        V P                  4       4      p\	        V4      pVP                  RV4       VP                  4        \        RVP                  : 24       \        P                  P                  R4      pVP                  P                  VR4      pV P                  \        RV4       \        RV: 24       \        P                  ! 4       pV P                  VP!                  RV4      4       R# )z
Existing entries in the I{known_hosts} file are reflected by the
L{KnownHostsFile} created by L{_NewConnectionHelper} when none is
supplied to it.
r   s	   127.0.0.1zCreated known_hosts file at z~/r  zPatched _KNOWN_HOSTS with N)r   r   r"   rZ  r+   r]  r_  r#   pathos
expanduserreplacer   r1   r  ro  
hasHostKey)rF   r  r$  r\  homedefaultloadeds   &      rG   test_readExisting*NewConnectionHelperTests.test_readExisting  s     ))*5&#D)
lC0*499-89 ww!!$'))##D$/

'A(45%113)),<=rJ   c                n    \        RRRRRRRRRR4
      pV P                  VP                  \        4       R# )zb
If L{None} is passed for the C{ui} parameter to
L{_NewConnectionHelper}, a L{ConsoleUI} is used.
N)r1   r   rc  r*   r  s   & rG   test_defaultConsoleUI.NewConnectionHelperTests.test_defaultConsoleUI  s9    
 &$dD$dD$
 	fii3rJ   c                    \        R4      p\        RRRRRRRRRRV4      pV P                  VP                  P	                  R4      4      pV P                  V4       R# )z
If L{None} is passed for the C{ui} parameter to L{_NewConnectionHelper}
and /dev/tty is available, the L{ConsoleUI} used is associated with
/dev/tty.
s   yesNs   does this work?)r  r1   r  rc  r   ro  rF   ttyr  r   s   &   rG   test_ttyConsoleUI*NewConnectionHelperTests.test_ttyConsoleUI  s]     v%$dD$dD$
 %%fii&6&67I&JKrJ   c                    \        V P                  4       4      p\        RRRRRRRRRRV4      pV P                  VP                  P                  R4      4      pV P                  V4       R# )z
If L{None} is passed for the C{ui} parameter to L{_NewConnectionHelper}
and /dev/tty is not available, the L{ConsoleUI} used is associated with
some file which always produces a C{b"no"} response.
Ns   did this break?)r"   rZ  r1   r  rc  r   r  r2  s   &   rG   test_nottyUI%NewConnectionHelperTests.test_nottyUI  se     t{{}%%$dD$dD$
 %%fii&6&67I&JK rJ   c                x    \        RRRRRRRRRR4
      pV P                  \        R4      VP                  4       R# )za
If not passed the name of a tty in the filesystem,
L{_NewConnectionHelper} uses C{b"/dev/tty"}.
Ns   /dev/tty)r1   r   r"   r3  r  s   & rG   test_defaultTTYFilename0NewConnectionHelperTests.test_defaultTTYFilename"  s>    
 &$dD$dD$
 	+.

;rJ   c                    \        RRRRRRRRRR4
      p\        4       p\        4       Vn        VP	                  VR4       V P                  VP                  P                  4       R# )zu
L{_NewConnectionHelper.cleanupConnection} closes the transport cleanly
if called with C{immediate} set to C{False}.
NF)r1   r5   r   r   r  ro  rp  )rF   r  r  s   &  rG   r  =NewConnectionHelperTests.test_cleanupConnectionNotImmediately,  s_    
 &$dD$dD$
 #_
.0
  U3
,,::;rJ   c                "    ! R R4      p\        RRRRRRRRRR4
      p\        4       p\        4       Vn        V! 4       VP                  n        VP	                  VR4       V P                  VP                  P                  P                  4       R# )z
L{_NewConnectionHelper.cleanupConnection} closes the transport with
C{abortConnection} if called with C{immediate} set to C{True}.
c                   *   a  ] tR tRt o RtR tRtV tR# )MNewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.Abortablei?  Fc                    RV n         R# )z
Abort the connection.
TNrC   rE   s   &rG   rH   ]NewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.Abortable.abortConnectionB  s      $rJ   rC   N)rK   rL   rM   rN   rD   rH   rP   rQ   rR   s   @rG   	Abortabler@  ?  s     G$ $rJ   rC  NT)r1   r5   r8   r   r  ro  rD   )rF   rC  r  r  s   &   rG   r  :NewConnectionHelperTests.test_cleanupConnectionImmediately9  s    	$ 	$ &$dD$dD$
 #_
13
)2
&  T2
,,66>>?rJ   rW   N)rK   rL   rM   rN   rO   rv  r  r!  r,  r/  r4  r7  r:  r  r  rP   rQ   rR   s   @rG   r  r    sJ     SR1 1.>.4 !<<@ @rJ   r  )yrO   os.pathr%  ior   structr   typingr   zope.interfacer   zope.interface.verifyr   r   r:  twisted.conch.errorr   r	   r
   twisted.conch.interfacesr   twisted.cred.checkersr   twisted.cred.portalr   twisted.internet.addressr   twisted.internet.deferr   r   r   r   twisted.internet.errorr   r   r   r   twisted.internet.interfacesr   r   twisted.internet.protocolr   r   twisted.internet.testingr   r   r   twisted.loggerr   r   twisted.python.compatr    twisted.python.failurer!   twisted.python.filepathr"   twisted.python.logr#   twisted.python.reflectr$   twisted.trial.unittestr%   twisted.conch.avatarr'   twisted.conch.checkersr(   r)   twisted.conch.client.knownhostsr*   r+   twisted.conch.endpointsr,   r-   r.   r/   r0   r1   twisted.conch.sshr2   twisted.conch.ssh.agentr3   twisted.conch.ssh.channelr4   twisted.conch.ssh.connectionr5   twisted.conch.ssh.factoryr6   twisted.conch.ssh.keysr7   twisted.conch.ssh.transportr8   twisted.conch.ssh.userauthr9   twisted.conch.test.keydatar:   r;   r<   r=   skipr  twisted.test.iosimr>   r?   rA   rU   r`   rd   rh   rz   r   r   r   r   r   r   rW  r  r  r  r  r  rW   rJ   rG   <module>rk     s       & ;  K K / I & 0 J J  H 7 
 8 / * , " 0 +  .LI  )64:4*><  (DJM
CJNN I 5]  
 $ $Z &2 24 4 .!2 .(!Z !* X	 	 	 "##% #% $#%LkB kB\]	8#E ]	8@R3h(J R3j)1H )1Xg . .0P@x P@rJ   