Ë
    ojÚ  ã                   óø  — d Z ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlZddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZ ddlmZm Z m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;  e9d«      reddl<m=Z= ddl>m?Z?m@Z@ ddlAmBZBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJmKZK ddlLmMZM ddlNmOZO ddlPmQZQ dd lRmSZS dd!lTmUZU dd"lVmWZW dd#lXmYZY dd$lZm[Z[ dd%l\m]Z]m^Z^m_Z_m`Z` nd&ZaebZUebZ[ebZSebZWebZQebZOebZCebZ@ebZ=dd'lcmdZdmeZe  G d(„ d)ed«      Zf G d*„ d+eQ«      Zg G d,„ d-eQ«      Zh G d.„ d/eQ«      Zi G d0„ d1«      Zj G d2„ d3e'«      Zk G d4„ d5«      Zl G d6„ d7e[«      Zm G d8„ d9eU«      Zn ee$«       G d:„ d;«      «       Zo ee%«       G d<„ d=«      «       Zp G d>„ d?«      Zq G d@„ dAe;eq«      Zr G dB„ dCe;eq«      Zs G dD„ dEe;«      Zt G dF„ dG«      Zu G dH„ dIe;«      Zvy)Jz'
Tests for L{twisted.conch.endpoints}.
é    N)ÚENOSYS)Úpack)Ú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Ú	_ReadFile)Ú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                   ó   — e Zd ZdZdZd„ Zy)ÚAbortableFakeTransportzC
    A L{FakeTransport} with added C{abortConnection} support.
    Fc                 ó   — d| _         y)z}
        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ÚabortConnectionz&AbortableFakeTransport.abortConnection]   s   € ð ˆ�ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rE   rI   © rJ   rH   rB   rB   V   s   „ ñð €GórJ   rB   c                   ó   — e Zd ZdZd„ Zy)ÚBrokenExecSessionzO
    L{BrokenExecSession} is a session on which exec requests always fail.
    c                  ó   — y)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}
        r   rO   ©rG   Údatas     rH   Úrequest_execzBrokenExecSession.request_execk   ó   € ð rJ   N©rK   rL   rM   rN   rU   rO   rJ   rH   rQ   rQ   f   ó   „ ñó
rJ   rQ   c                   ó   — e Zd ZdZd„ Zy)ÚWorkingExecSessionzS
    L{WorkingExecSession} is a session on which exec requests always succeed.
    c                  ó   — y)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}
        é   rO   rS   s     rH   rU   zWorkingExecSession.request_exec}   rV   rJ   NrW   rO   rJ   rH   rZ   rZ   x   rX   rJ   rZ   c                   ó   — e Zd ZdZd„ Zy)ÚUnsatisfiedExecSessionz‰
    L{UnsatisfiedExecSession} is a session on which exec requests are always
    delayed indefinitely, never succeeding or failing.
    c                 ó   — t        «       S )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   rS   s     rH   rU   z#UnsatisfiedExecSession.request_exec�   s   € ô ‹zÐrJ   NrW   rO   rJ   rH   r^   r^   Š   s   „ ñó

rJ   r^   c                   ó   — e Zd Zd„ Zd„ Zy)ÚTrivialRealmc                 ó   — i | _         y ©N)ÚchannelLookuprF   s    rH   Ú__init__zTrivialRealm.__init__ž   s
   € ØˆÕrJ   c                 óL   — t        «       }| j                  |_        t        |d„ fS )Nc                   ó   — y rc   rO   rO   rJ   rH   ú<lambda>z,TrivialRealm.requestAvatar.<locals>.<lambda>¤   s   � rJ   )r'   rd   r   )rG   ÚavatarIdÚmindÚ
interfacesÚavatars        rH   ÚrequestAvatarzTrivialRealm.requestAvatar¡   s$   € Ü“ˆØ#×1Ñ1ˆÔÜ˜F¡LÐ1Ð1rJ   N)rK   rL   rM   re   rm   rO   rJ   rH   ra   ra   �   s   „ ò ó2rJ   ra   c                   ó   — e Zd ZdZd„ Zy)ÚAddressSpyFactoryNc                 ó<   — || _         t        j                  | |«      S rc   )Úaddressr   ÚbuildProtocol)rG   rq   s     rH   rr   zAddressSpyFactory.buildProtocolª   s   € ØˆŒÜ×$Ñ$ T¨7Ó3Ð3rJ   )rK   rL   rM   rq   rr   rO   rJ   rH   ro   ro   §   s   „ Ø€Gó4rJ   ro   c                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ÚFixedResponseUIc                 ó   — || _         y rc   )Úresult)rG   rv   s     rH   re   zFixedResponseUI.__init__°   s	   € Øˆ�rJ   c                 ó,   — t        | j                  «      S rc   )r   rv   ©rG   Útexts     rH   ÚpromptzFixedResponseUI.prompt³   s   € Ü�t—{‘{Ó#Ð#rJ   c                  ó   — y rc   rO   rx   s     rH   ÚwarnzFixedResponseUI.warn¶   s   € ØrJ   N)rK   rL   rM   re   rz   r|   rO   rJ   rH   rt   rt   ¯   s   „ òò$órJ   rt   c                   ó,   — e Zd Zed„ «       Zed„ «       Zy)ÚFakeClockSSHUserAuthServerc                 óB   — | j                   j                  j                  S )zy
        Use the C{attemptsBeforeDisconnect} value defined by the factory to make
        it easier to override.
        )Ú	transportÚfactoryÚattemptsBeforeDisconnectrF   s    rH   r‚   z3FakeClockSSHUserAuthServer.attemptsBeforeDisconnect¼   s   € ð �~‰~×%Ñ%×>Ñ>Ð>rJ   c                 óB   — | j                   j                  j                  S )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�   ÚreactorrF   s    rH   Úclockz FakeClockSSHUserAuthServer.clockÄ   s   € ð �~‰~×%Ñ%×-Ñ-Ð-rJ   N)rK   rL   rM   Úpropertyr‚   r…   rO   rJ   rH   r~   r~   º   s(   „ àñ?ó ð?ð ñ.ó ñ.rJ   r~   c                   ó:   — e Zd Zed„ «       Zed„ «       ZeedœZdZ	y)ÚCommandFactoryc                 ó:   — dt        j                  t        ¬«      iS ©Nó   ssh-rsa)rT   )r8   Ú
fromStringr>   rF   s    rH   Ú
publicKeyszCommandFactory.publicKeysÏ   s   € àœCŸN™NÔ0AÔBÐCÐCrJ   c                 ó:   — dt        j                  t        ¬«      iS rŠ   )r8   rŒ   r<   rF   s    rH   ÚprivateKeyszCommandFactory.privateKeysÓ   s   € àœCŸN™NÔ0BÔCÐDÐDrJ   )s   ssh-userauths   ssh-connectionr   N)
rK   rL   rM   r†   r�   r�   r~   r6   Úservicesr‚   rO   rJ   rH   rˆ   rˆ   Î   sC   „ ØñDó ðDð ñEó ðEð 4Ø(ñ€Hð  !ÑrJ   rˆ   c                   ó   — e Zd Zy)ÚMemoryAddressN)rK   rL   rM   rO   rJ   rH   r’   r’   ã   s   „ àrJ   r’   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚSingleUseMemoryEndpointa]  
    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                 ó    — d| _         || _        y)z˜
        @param server: An L{IProtocol} provider to which the client will be
            connected.
        @type server: L{IProtocol} provider
        N)ÚpumpÚ_server)rG   Úservers     rH   re   z SingleUseMemoryEndpoint.__init__ô   s   € ð ˆŒ	Øˆ�rJ   c           	      ó&  — | j                   �t        d«      ‚	 |j                  t        «       «      }t	        | j
                  t        | j
                  d¬«      |t        |d¬«      «      | _         t        |«      S # t        $ r t        «       cY S w xY w)Nz(SingleUseMemoryEndpoint was already usedT©ÚisServerF)
r–   Ú	Exceptionrr   r’   r@   r—   rB   r   ÚBaseExceptionr   )rG   r�   Úprotocols      rH   r@   zSingleUseMemoryEndpoint.connectý   s„   € Ø�9‰9Ð ÜÐFÓGÐGð	%Ø×,Ñ,¬]«_Ó=ˆHô  Ø—‘Ü& t§|¡|¸dÔCØÜ& x¸%Ô@ó	ˆDŒIô ˜8Ó$Ð$øô ò 	Ü“6ŠMð	ús   ™A: Á:BÂBN)rK   rL   rM   rN   re   r@   rO   rJ   rH   r”   r”   è   s   „ ñòó%rJ   r”   c                   ó„   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zy)Ú"SSHCommandClientEndpointTestsMixinaà  
    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                 óÄ  — d| _         d| _        d| _        d| _        t	        «       | _        t        «       | _        t        | j                  «      | _	        t        «       | _        | j                  j                  | j                  | j                  «       | j                  j                  | j                  «       t        «       | _        | j
                  | j                  _        | j                  | j                  _	        | j                  j!                  «        | j#                  | j                  j$                  «       t'        ddd«      | _        t'        ddd	«      | _        y )
Ns   ssh.example.comi&¤  s   users   passwordÚTCPz10.0.0.1i90  z192.168.100.200i1Ô  )ÚhostnameÚportÚuserÚpasswordr   r„   ra   Úrealmr   Úportalr   ÚpasswdDBÚaddUserÚregisterCheckerrˆ   r�   ÚdoStartÚ
addCleanupÚdoStopr   ÚclientAddressÚserverAddressrF   s    rH   ÚsetUpz(SSHCommandClientEndpointTestsMixin.setUp  sð   € Ø*ˆŒØˆŒ	ØˆŒ	Ø#ˆŒÜ)Ó+ˆŒÜ!“^ˆŒ
Ü˜TŸZ™ZÓ(ˆŒÜ?ÓAˆŒØ�‰×Ñ˜dŸi™i¨¯©Ô7Ø�‰×#Ñ# D§M¡MÔ2Ü%Ó'ˆŒØ#Ÿ|™|ˆ�‰ÔØ"Ÿk™kˆ�‰ÔØ�‰×ÑÔØ�‰˜Ÿ™×+Ñ+Ô,ä(¨°
¸EÓBˆÔÜ(¨Ð0AÀ5ÓIˆÕrJ   c                 óF   — t        | j                  j                  ›d�«      ‚)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   rF   s    rH   Úcreatez)SSHCommandClientEndpointTestsMixin.create1  s'   € ô
 "Ø�~‰~×&Ñ&Ð)Ð)BÐCó
ð 	
rJ   c                 óF   — t        | j                  j                  ›d�«      ‚)a™  
        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³   ©rG   ÚclientÚimmediateCloses      rH   ÚassertClientTransportStatez=SSHCommandClientEndpointTestsMixin.assertClientTransportState:  s#   € ô "à�~‰~×&Ó&ð)ó
ð 	
rJ   c                 óF   — t        | j                  j                  ›d�«      ‚)zˆ
        Do any remaining work necessary to complete an in-memory connection
        attempted initiated using C{self.reactor}.
        z# did not implement finishConnectionr³   rF   s    rH   ÚfinishConnectionz3SSHCommandClientEndpointTestsMixin.finishConnectionJ  s'   € ô
 "Ø�~‰~×&Ñ&Ð)Ð)LÐMó
ð 	
rJ   c                 óø   — |j                  d«      }|j                  d«      }t        |d| j                  | j                  ¬«      }t        |d| j                  | j                  ¬«      }t	        ||||«      }|||fS )aw  
        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)rr   rB   r¯   r°   r@   )rG   ÚserverFactoryÚclientFactoryÚclientProtocolÚserverProtocolÚclientTransportÚserverTransportr–   s           rH   ÚconnectedServerAndClientz;SSHCommandClientEndpointTestsMixin.connectedServerAndClientS  s‰   € ð '×4Ñ4°TÓ:ˆØ&×4Ñ4°TÓ:ˆä0ØØØ×*Ñ*Ø×*Ñ*ô	
ˆô 1ØØØ×*Ñ*Ø×*Ñ*ô	
ˆô �~ ¸ÈÓXˆØ˜~¨tÐ3Ð3rJ   c                 ó8  — | j                  «       }t        «       }t        |_        |j	                  |«      }| j                  «       \  }}}| j                  t        «      }| j                  d|d   j                  j                  |d   j                  j                  f«       | j                  dt        |«      «       | j                  |«      }|j                  t        «       | j                  d|j                  j                  «       | j                  |d«       y)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 channelr   r\   ó   unknown channelFN)r¶   r   r   rž   r@   r½   ÚflushLoggedErrorsr   ÚassertInÚvaluerT   ÚassertEqualÚlenÚfailureResultOfÚtrapr»   )	rG   Úendpointr�   Ú	connectedr˜   r¹   r–   ÚerrorsÚfs	            rH   Útest_channelOpenFailurez:SSHCommandClientEndpointTestsMixin.test_channelOpenFailurep  sà   € ð —;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜ð ×'Ñ'¬
Ó3ˆØ�‰Ð'¨&°©)¯/©/×*>Ñ*>ÀÀqÁ	ÇÁ×@UÑ@UÐ)VÔWØ×Ñ˜œC ›KÔ(ð × Ñ  Ó+ˆØ	�‰ŒzÔØ×ÑÐ+¨Q¯W©W¯]©]Ô;à×'Ñ'¨°Õ6rJ   c                 óŽ  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }|j                  t        «       | j                  d|j                  j                  «       | j                  |d«       y)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)rQ   r§   rd   r¶   r   r   rž   r@   r½   rÐ   rÑ   r   rÎ   rÍ   r»   ©rG   rÒ   r�   rÓ   r˜   r¹   r–   rÕ   s           rH   Útest_execFailurez3SSHCommandClientEndpointTestsMixin.test_execFailureŠ  s�   € ô 0Aˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à× Ñ  Ó+ˆØ	�‰ŒzÔØ×ÑÐ1°1·7±7·=±=ÔAà×'Ñ'¨°Õ6rJ   c                 ób  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}|j                  «        | j                  |«      }|j                  t        «       | j                  |d«       y)zµ
        If execution of the command is cancelled via the L{Deferred} returned
        by L{SSHCommandClientEndpoint.connect}, the connection is closed
        immediately.
        rØ   TN)r^   r§   rd   r¶   r   r   rž   r@   r½   ÚcancelrÐ   rÑ   r   r»   rÙ   s           rH   Útest_execCancelledz5SSHCommandClientEndpointTestsMixin.test_execCancelledŸ  s�   € ô 0Fˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	Ø#×4Ñ4Ó6Ñˆ�˜à×ÑÔà× Ñ  Ó+ˆØ	�‰Œ~Ôà×'Ñ'¨°Õ5rJ   c                 ó:  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«       | j                  «       \  }}}| j                  |j                  t        «       | j                  |j                  j                  «       |j                  j                  «       | j                  | j                   |j                  j"                  «       | j                  d|j                  j$                  «       y)aD  
        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)rZ   r§   rd   r¶   ro   r   rž   r@   r½   ÚassertIsInstancerq   r-   rÎ   r€   ÚgetHostr˜   r¥   ÚusernameÚcommand)rG   rÒ   r�   r˜   r¹   r–   s         rH   Útest_buildProtocolz5SSHCommandClientEndpointTestsMixin.test_buildProtocol´  sÍ   € ô 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä#Ó%ˆÜ#ˆÔà×Ñ˜Ô!à#×4Ñ4Ó6Ñˆ�˜à×Ñ˜gŸo™oÔ/@ÔAØ×Ñ˜×)Ñ)×1Ñ1Ó3°W·_±_×5KÑ5KÔLØ×Ñ˜Ÿ™ G§O¡O×$<Ñ$<Ô=Ø×Ñ˜¨¯©×(?Ñ(?Õ@rJ   c                 ó*  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }| j                  |j                  «       y)a  
        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)rZ   r§   rd   r¶   r   r   rž   r@   r½   ÚsuccessResultOfÚassertIsNotNoner€   ©rG   rÒ   r�   rÓ   r˜   r¹   r–   rž   s           rH   Útest_makeConnectionz6SSHCommandClientEndpointTestsMixin.test_makeConnectionË  s|   € ô 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à×'Ñ'¨	Ó2ˆØ×Ñ˜X×/Ñ/Õ0rJ   c                 óø  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }g }|j                  |_        |j                  j                  }	|j                  j                  |	   j!                  d«       |j#                  «        | j%                  ddj'                  |«      «       y)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)rZ   r§   rd   r¶   r   r   rž   r@   r½   ræ   ÚappendÚdataReceivedr€   ÚidÚserviceÚchannelsÚwriter–   rÎ   Újoin)
rG   rÒ   r�   rÓ   r˜   r¹   r–   rž   rí   Ú	channelIds
             rH   Útest_dataReceivedz4SSHCommandClientEndpointTestsMixin.test_dataReceivedÞ  sÍ   € ô 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à×'Ñ'¨	Ó2ˆØˆØ ,× 3Ñ 3ˆÔð ×&Ñ&×)Ñ)ˆ	à�‰×Ñ 	Ñ*×0Ñ0°ÔAØ�	‰	ŒØ×Ñ˜¨#¯(©(°<Ó*@ÕArJ   c                 ó  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }g }|j                  |_        |j                  j                  }	|j                  j                  |	   j!                  «        |j#                  «        |d   j%                  t&        «       | j)                  |d«       y)zq
        When the command closes the channel, the protocol's C{connectionLost}
        method is called.
        rØ   r   FN)rZ   r§   rd   r¶   r   r   rž   r@   r½   ræ   rì   ÚconnectionLostr€   rî   rï   rð   ÚloseConnectionr–   rÑ   r   r»   )
rG   rÒ   r�   rÓ   r˜   r¹   r–   rž   rö   ró   s
             rH   Útest_connectionLostz6SSHCommandClientEndpointTestsMixin.test_connectionLostù  sÕ   € ô
 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à×'Ñ'¨	Ó2ˆØˆØ"0×"7Ñ"7ˆÔð ×&Ñ&×)Ñ)ˆ	Ø�‰×Ñ 	Ñ*×9Ñ9Ô;à�	‰	ŒØ�qÑ×Ñœ~Ô.à×'Ñ'¨°Õ6rJ   c                 ó  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }	g }
|
j                  |	_        |	j                  j                  }|j                  j                  |   }|j                  j!                  |||«       |j#                  «        |j%                  «        | j'                  |d«       |
d   S )zJ
        Test handling of non-zero exit statuses or exit signals.
        rØ   Fr   )rZ   r§   rd   r¶   r   r   rž   r@   r½   ræ   rì   rö   r€   rî   rï   rð   ÚsendRequestr÷   r–   r»   )rG   ÚrequestÚ
requestArgrÒ   r�   rÓ   r˜   r¹   r–   rž   rö   ró   Úchannels                rH   Ú_exitStatusTestz2SSHCommandClientEndpointTestsMixin._exitStatusTest  sè   € ô 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à×'Ñ'¨	Ó2ˆØˆØ"0×"7Ñ"7ˆÔð
 ×&Ñ&×)Ñ)ˆ	Ø—.‘.×)Ñ)¨)Ñ4ˆà�‰×"Ñ" 7¨G°ZÔ@Ø×ÑÔ Ø�	‰	ŒØ×'Ñ'¨°Ô6Ø˜aÑ Ð rJ   c                 ój   — d}| j                  dt        d|«      «      }|j                  t        «       y)úÊ
        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.
        r   ó   exit-statusú>LN)rþ   r   rÑ   r   )rG   ÚexitCodeÚexcs      rH   Útest_zeroExitCodez4SSHCommandClientEndpointTestsMixin.test_zeroExitCode2  s.   € ð ˆØ×"Ñ" >´4¸¸hÓ3GÓHˆØ�‰”Õ rJ   c                 ó  — d}d}| j                  dt        d|«      «      }|j                  t        «       | j	                  ||j
                  j                  «       | j	                  ||j
                  j                  «       y)r   é{   Nr  r  )rþ   r   rÑ   r   rÎ   rÍ   r  Úsignal)rG   r  r  r  s       rH   Útest_nonZeroExitStatusz9SSHCommandClientEndpointTestsMixin.test_nonZeroExitStatus<  sh   € ð ˆØˆØ×"Ñ" >´4¸¸hÓ3GÓHˆØ�‰Ô"Ô#Ø×Ñ˜ 3§9¡9×#5Ñ#5Ô6Ø×Ñ˜ §¡×!1Ñ!1Õ2rJ   c                 óØ  — t        «       }t        j                  |«       | j                  t        j                  |«       d}d}dj                  t        j                  d«      dt        j                  d«      t        j                  d«      g«      }| j                  d|«      }|j                  t        «       | j                  ||j                  j                  «       | j                  ||j                  j                  «       d	}t        j                   |t        j"                  t        j$                  t        j&                  t(        j*                  «      |dd
dddœ«      «      «       y)a  
        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.
        Né   rJ   s   TERMó   s   messages   en-USs   exit-signalz'twisted.conch.endpoints._CommandChannelTÚmessage)Ú	log_levelÚlog_namespaceÚshortSignalNameÚ
coreDumpedÚerrorMessageÚlanguageTag)r   r   ÚaddObserverr­   ÚremoveObserverrò   r3   ÚNSrþ   rÑ   r   rÎ   rÍ   r  r  ÚhamcrestÚassert_thatÚhas_itemÚhas_entriesÚequal_tor   Úinfo)rG   ÚlogObserverr  r  Úpacketr  ÚlogNamespaces          rH   Útest_nonZeroExitSignalz9SSHCommandClientEndpointTestsMixin.test_nonZeroExitSignalI  s   € ô +Ó,ˆÜ×&Ñ& {Ô3Ø�‰Ô*×9Ñ9¸;ÔGàˆØˆà—‘ä—	‘	˜'Ó"àÜ—	‘	˜*Ó%Ü—	‘	˜(Ó#ðó
ˆð ×"Ñ" >°6Ó:ˆØ�‰Ô"Ô#Ø×Ñ˜ 3§9¡9×#5Ñ#5Ô6Ø×Ñ˜ §¡×!1Ñ!1Ô2à@ˆÜ×ÑØÜ×ÑÜ×$Ñ$ä%-×%6Ñ%6´x·}±}Ó%EØ)5Ø+2Ø&*Ø(1Ø'/ñó	óõ	
rJ   c                 ó¨   ‡— |j                   j                  }g Š|rˆfd„}n‰j                  }t        |j                  j
                  |   ||«       ‰S )a  
        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                  ó&   •— ‰ j                  d «      S rc   )rì   )Úrecorders   €rH   rh   z;SSHCommandClientEndpointTestsMixin.record.<locals>.<lambda>‹  s   ø€ ˜Ÿ™¨Ó-€ rJ   )r€   rî   rì   Úsetattrrï   rð   )rG   r˜   rž   ÚeventÚnoArgsró   rÕ   r#  s          @rH   Úrecordz)SSHCommandClientEndpointTestsMixin.recordw  sL   ø€ ð  ×&Ñ&×)Ñ)ˆ	àˆÙÛ-‰Aà—‘ˆAä�—‘×'Ñ'¨	Ñ2°E¸1Ô=ØˆrJ   c                 ó²  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }| j                  ||d«      }|j                  j                  d«       |j                  «        | j                  ddj                  |«      «       y)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)rZ   r§   rd   r¶   r   r   rž   r@   r½   ræ   r'  r€   rñ   r–   rÎ   rò   ©	rG   rÒ   r�   rÓ   r˜   r¹   r–   rž   rí   s	            rH   Ú
test_writez-SSHCommandClientEndpointTestsMixin.test_write’  s°   € ô
 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à×'Ñ'¨	Ó2ˆà—{‘{ 6¨8°^ÓDˆØ×Ñ× Ñ  Ô1Ø�	‰	ŒØ×Ñ˜¨#¯(©(°<Ó*@ÕArJ   c                 ó´  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }| j                  ||d«      }|j                  j                  dg«       |j                  «        | j                  ddj                  |«      «       y)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)rZ   r§   rd   r¶   r   r   rž   r@   r½   ræ   r'  r€   ÚwriteSequencer–   rÎ   rò   r)  s	            rH   Útest_writeSequencez5SSHCommandClientEndpointTestsMixin.test_writeSequence§  s³   € ô
 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à×'Ñ'¨	Ó2ˆà—{‘{ 6¨8°^ÓDˆØ×Ñ×(Ñ(¨/Ð):Ô;Ø�	‰	ŒØ×Ñ˜¨#¯(©(°<Ó*@ÕArJ   N)F)rK   rL   rM   rN   r±   r¶   r»   r½   rÇ   rÖ   rÚ   rÝ   rä   ré   rô   rø   rþ   r  r	  r   r'  r*  r-  rO   rJ   rH   r    r      sl   „ ñòJò(
ò
ò 
ò4ò:7ò47ò*6ò*Aò.1ò&Bò67ò8!ò:!ò3ò,
ó\ò6Bó*BrJ   r    c                   óš   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚNewConnectionTestsz`
    Tests for L{SSHCommandClientEndpoint} when using the C{newConnection}
    constructor.
    c                 óì  — t         j                  | «       t        | j                  «       «      | _        t        | j                  «      | _        | j                  j                  | j                  | j                  j                  d   «       | j                  j                  t        | j                  j                  «      | j                  j                  d   «       | j                  j                  «        y)ú
        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ÚsaverF   s    rH   r±   zNewConnectionTests.setUpÃ  s§   € ô
 	+×0Ñ0°Ô6ä# D§K¡K£MÓ2ˆÔÜ(¨×)9Ñ)9Ó:ˆŒØ�‰×"Ñ" 4§=¡=°$·,±,×2IÑ2IÈ*Ñ2UÔVØ�‰×"Ñ"Ü˜$×,Ñ,×1Ñ1Ó2°D·L±L×4KÑ4KÈJÑ4Wô	
ð 	�‰×ÑÕrJ   c                 óÆ   — t        j                  | j                  d| j                  | j                  | j
                  | j                  | j                  t        d«      ¬«      S )zu
        Create and return a new L{SSHCommandClientEndpoint} using the
        C{newConnection} constructor.
        rß   F©r¦   r4  Úui)	r.   ÚnewConnectionr„   r¥   r£   r¤   r¦   r4  rt   rF   s    rH   r¶   zNewConnectionTests.createÒ  sL   € ô
 (×5Ñ5Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ—]‘]Ø—‘Ü˜uÓ%ô	
ð 		
rJ   c                 ón   — | j                  | j                  | j                  j                  d   d   «      S )z}
        Establish the first attempted TCP connection using the SSH server which
        C{self.factory} can create.
        r   é   )rÇ   r�   r„   Ú
tcpClientsrF   s    rH   r½   z#NewConnectionTests.finishConnectionâ  s4   € ð
 ×,Ñ,Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó
ð 	
rJ   c                 óü   — | j                  ||dd¬«      }|j                  j                  «        |j                  «        | j	                  dg|«       |j                  «        |j                  j                  «        y)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)r&  N)r'  r€   r÷   r–   rÎ   ÚreportDisconnect)rG   r˜   r¹   rž   r–   r@  s         rH   ÚloseConnectionToServerz)NewConnectionTests.loseConnectionToServerë  sf   € ð* —‘˜V X¨xÀ�ÓEˆØ×Ñ×)Ñ)Ô+Ø�	‰	ŒØ×Ñ˜$˜ Ô(ð
 	�	‰	Œð 	×Ñ×)Ñ)Õ+rJ   c                 óž   — |r&| j                  |j                  j                  «       y| j                  |j                  j                  «       y)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€   rE   Údisconnectingr¸   s      rH   r»   z-NewConnectionTests.assertClientTransportState  s7   € ñ Ø�O‰O˜F×,Ñ,×4Ñ4Õ5à�O‰O˜F×,Ñ,×:Ñ:Õ;rJ   c                 ó°   — t        j                  | j                  dd| j                  | j                  «      }| j                  t        t        |«      «       y)zY
        L{SSHCommandClientEndpoint} instances provide L{IStreamClientEndpoint}.
        ó   dummy commandó
   dummy userN)r.   r;  r„   r£   r¤   rD  r   r   ©rG   rÒ   s     rH   Útest_interfacez!NewConnectionTests.test_interface  sB   € ô ,×9Ñ9Ø�L‰LÐ*¨M¸4¿=¹=È$Ï)É)ó
ˆð 	�‰œÔ%:¸HÓEÕFrJ   c                 ó¨   — t        j                  | j                  dd| j                  «      }| j	                  d|j
                  j                  «       y)z†
        L{SSHCommandClientEndpoint} uses the default port number for SSH when
        the C{port} argument is not specified.
        rG  rH  é   N©r.   r;  r„   r£   rÎ   Ú_creatorr¤   rI  s     rH   Útest_defaultPortz#NewConnectionTests.test_defaultPort$  sD   € ô
 ,×9Ñ9Ø�L‰LÐ*¨M¸4¿=¹=ó
ˆð 	×Ñ˜˜X×.Ñ.×3Ñ3Õ4rJ   c                 ó¬   — t        j                  | j                  dd| j                  d¬«      }| j	                  d|j
                  j                  «       y)zU
        L{SSHCommandClientEndpoint} uses the C{port} argument if specified.
        rG  rH  i®  )r¤   NrM  rI  s     rH   Útest_specifiedPortz%NewConnectionTests.test_specifiedPort.  sF   € ô ,×9Ñ9Ø�L‰LÐ*¨M¸4¿=¹=Ètô
ˆð 	×Ñ˜˜x×0Ñ0×5Ñ5Õ6rJ   c                 ó2  — t        j                  | j                  d| j                  | j                  | j
                  | j                  | j                  t        d«      ¬«      }t        «       }t        |_        |j                  |«       | j                  j                  d   \  }}}}}| j                  | j                  t        |«      «       | j                  | j
                  |«       | j                  dt!        | j                  j                  «      «       y)zž
        L{SSHCommandClientEndpoint} uses the L{IReactorTCP} passed to it to
        attempt a connection to the host/port address also passed to it.
        rß   Fr9  r   r\   N)r.   r;  r„   r¥   r£   r¤   r¦   r4  rt   r   r   rž   r@   r>  rÎ   r    rÏ   )rG   rÒ   r�   r6  r¤   ÚtimeoutÚbindAddresss          rH   Útest_destinationz#NewConnectionTests.test_destination7  sÓ   € ô
 ,×9Ñ9Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ—]‘]Ø—‘Ü˜uÓ%ô	
ˆô “)ˆÜ#ˆÔØ×Ñ˜Ô!à48·L±L×4KÑ4KÈAÑ4NÑ1ˆˆd�G˜W kØ×Ñ˜Ÿ™¬°dÓ(;Ô<Ø×Ñ˜Ÿ™ DÔ)Ø×Ñ˜œC §¡× 7Ñ 7Ó8Õ9rJ   c                 ó°  — t        j                  | j                  dd| j                  | j                  | j
                  t        d«      ¬«      }t        «       }t        |_	        |j                  |«      }| j                  j                  d   d   }|j                  dt        t        «       «      «       | j                  |«      j!                  t        «       y)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ß   rH  F©r4  r:  r   r=  N)r.   r;  r„   r£   r¤   r4  rt   r   r   rž   r@   r>  ÚclientConnectionFailedr!   r   rÐ   rÑ   ©rG   rÒ   r�   Úds       rH   Útest_connectionFailedz(NewConnectionTests.test_connectionFailedO  s«   € ô ,×9Ñ9Ø�L‰LØØØ�M‰MØ�I‰IØ—‘Ü˜uÓ%ô
ˆô “)ˆÜ#ˆÔØ×Ñ˜WÓ%ˆà—,‘,×)Ñ)¨!Ñ,¨QÑ/ˆØ×&Ñ& t¬WÔ5KÓ5MÓ-NÔOà×Ñ˜QÓ×$Ñ$Ô%;Õ<rJ   c                 óÄ  — t        j                  | j                  dd| j                  | j                  t        | j                  «       «      t        d«      ¬«      }t        «       }t        |_
        |j                  |«      }| j                  | j                  | j                  j                  d   d   «      \  }}}| j                  |«      }|j!                  t"        «       y)a"  
        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ß   rH  FrW  r   r=  N)r.   r;  r„   r£   r¤   r+   r2  rt   r   r   rž   r@   rÇ   r�   r>  rÐ   rÑ   r
   rÙ   s           rH   Útest_userRejectedHostKeyz+NewConnectionTests.test_userRejectedHostKeyg  s¸   € ô ,×9Ñ9Ø�L‰LØØØ�M‰MØ�I‰IÜ% d§k¡k£mÓ4Ü˜uÓ%ô
ˆô “)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ð × Ñ  Ó+ˆØ	�‰ŒÕrJ   c           
      ó  — t        j                  t        «      j                  «       }t	        t        | j                  «       «      «      }|j                  t        | j                  j                  «      |«       t        j                  t        d¬«      j                  «       }|j                  | j                  |«       t        d«      }t        j                  | j                   dd| j                  | j"                  d||¬«      }t%        «       }t&        |_        |j+                  |«      }| j-                  | j.                  | j                   j0                  d   d	   «      \  }}	}
| j3                  |«      }|j5                  t6        «       y
)ac  
        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ß   rH  ó   dummy passwordr9  r   r=  N)r8   rŒ   r<   Úpublicr+   r"   r2  r5  r    r°   r6  r=   r£   rt   r.   r;  r„   r¤   r   r   rž   r@   rÇ   r�   r>  rÐ   rÑ   r	   )rG   ÚfirstKeyr4  ÚdifferentKeyr:  rÒ   r�   rÓ   r˜   r¹   r–   rÕ   s               rH   Útest_mismatchedHostKeyz)NewConnectionTests.test_mismatchedHostKeyƒ  s8  € ô —>‘>Ô"4Ó5×<Ñ<Ó>ˆÜ#¤H¨T¯[©[«]Ó$;Ó<ˆ
Ø×Ñœm¨D×,>Ñ,>×,CÑ,CÓDÀhÔOä—~‘~Ü,¸ô
ç
‰&‹(ð 	ð 	×Ñ˜dŸm™m¨\Ô:ô
 ˜TÓ"ˆä+×9Ñ9Ø�L‰LØØØ�M‰MØ�I‰IØ&Ø!Øô	
ˆô “)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ð × Ñ  Ó+ˆØ	�‰Œ~ÕrJ   c                 ó  — t        j                  | j                  dd| j                  | j                  | j
                  t        d«      ¬«      }t        «       }t        |_	        |j                  |«      }t        «       }| j                  j                  d   d   }|j                  d«      }|j                  |«       |j                  t!        t#        «       «      «       | j%                  |«      j'                  t"        «       y)aU  
        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ß   rH  FrW  r   r=  N)r.   r;  r„   r£   r¤   r4  rt   r   r   rž   r@   r   r>  rr   ÚmakeConnectionrö   r!   r   rÐ   rÑ   ©rG   rÒ   r�   rZ  r€   r¹   s         rH   Ú!test_connectionClosedBeforeSecurez4NewConnectionTests.test_connectionClosedBeforeSecure¯  sÍ   € ô ,×9Ñ9Ø�L‰LØØØ�M‰MØ�I‰IØ—‘Ü˜uÓ%ô
ˆô “)ˆÜ#ˆÔØ×Ñ˜WÓ%ˆä#Ó%ˆ	Ø—,‘,×)Ñ)¨!Ñ,¨QÑ/ˆØ×&Ñ& tÓ,ˆØ×Ñ˜iÔ(à×Ñœg¤nÓ&6Ó7Ô8Ø×Ñ˜QÓ×$Ñ$¤^Õ4rJ   c                 ób  — t        j                  | j                  dd| j                  | j                  | j
                  t        d«      ¬«      }t        «       }t        |_	        |j                  |«      }t        dd¬«      }| j                  j                  d   d   }|j                  d«      }|j                  |«       |j                  «        | j!                  |«      j#                  t$        «       | j'                  |j(                  «       |j+                  t-        t/        «       «      «       y)	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ß   rH  FrW  Nrš   r   r=  )r.   r;  r„   r£   r¤   r4  rt   r   r   rž   r@   rB   r>  rr   rf  rÜ   rÐ   rÑ   r   rD  rE   rö   r!   r   rg  s         rH   Ú$test_connectionCancelledBeforeSecurez7NewConnectionTests.test_connectionCancelledBeforeSecureÍ  sî   € ô ,×9Ñ9Ø�L‰LØØØ�M‰MØ�I‰IØ—‘Ü˜uÓ%ô
ˆô “)ˆÜ#ˆÔØ×Ñ˜WÓ%ˆä*¨4¸%Ô@ˆ	Ø—,‘,×)Ñ)¨!Ñ,¨QÑ/ˆØ×&Ñ& tÓ,ˆØ×Ñ˜iÔ(Ø	�‰Œ
à×Ñ˜QÓ×$Ñ$¤^Ô4Ø�‰˜	×)Ñ)Ô*ð 	×Ñœg¤nÓ&6Ó7Õ8rJ   c                 ó¶  — t        j                  | j                  dd| j                  | j                  | j
                  t        d«      ¬«      }t        «       }t        |_	        |j                  |«      }|j                  «        | j                  |«      j                  t        «       | j                  | j                  j                   d   j"                  «       y)zz
        If the connection is cancelled before it finishes connecting, the
        connection attempt is stopped.
        rß   rH  FrW  r   N)r.   r;  r„   r£   r¤   r4  rt   r   r   rž   r@   rÜ   rÐ   rÑ   r   rD  Ú
connectorsÚstoppedConnectingrY  s       rH   Ú'test_connectionCancelledBeforeConnectedz:NewConnectionTests.test_connectionCancelledBeforeConnectedï  s£   € ô
 ,×9Ñ9Ø�L‰LØØØ�M‰MØ�I‰IØ—‘Ü˜uÓ%ô
ˆô “)ˆÜ#ˆÔØ×Ñ˜WÓ%ˆØ	�‰Œ
Ø×Ñ˜QÓ×$Ñ$Ô%=Ô>Ø�‰˜Ÿ™×/Ñ/°Ñ2×DÑDÕErJ   c                 óN  — t        j                  | j                  dd| j                  | j                  d| j
                  t        d«      ¬«      }t        «       }t        |_	        |j                  |«      }| j                  | j                  | j                  j                  d   d   «      \  }}}| j                  j                  |j                  j                   «       |j#                  «        | j%                  |«      }|j'                  t(        «       | j+                  |d«       y)	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ß   rH  r`  Fr9  r   r=  N)r.   r;  r„   r£   r¤   r4  rt   r   r   rž   r@   rÇ   r�   r>  Úadvancerï   ÚpasswordDelayÚflushrÐ   rÑ   r,   r»   rÙ   s           rH   Ú"test_passwordAuthenticationFailurez5NewConnectionTests.test_passwordAuthenticationFailure  sî   € ô ,×9Ñ9Ø�L‰LØØØ�M‰MØ�I‰IØ&Ø—‘Ü˜uÓ%ô	
ˆô “)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ð 	�‰×Ñ˜VŸ^™^×9Ñ9Ô:ð 	�
‰
Œà× Ñ  Ó+ˆØ	�‰Ô#Ô$ð 	×'Ñ'¨°Õ6rJ   c                 óä   — |j                  «       D ��ci c]*  \  }}|t        j                  |«      j                  «       g“Œ, }}}t	        t        |«      «      }|j                  |«       yc c}}w )a¼  
        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)Úitemsr8   rŒ   ra  r)   r(   r«   )rG   r¨   ÚusersÚkÚvÚmappingÚcheckers          rH   ÚsetupKeyCheckerz"NewConnectionTests.setupKeyChecker-  sa   € ð @E¿{¹{»}×M±t°q¸!�1”s—~‘~ aÓ(×/Ñ/Ó1Ð2Ñ2ÐMˆÑMÜ%Ô&6°wÓ&?Ó@ˆØ×Ñ˜wÕ'ùó Ns   ”/A,c                 ó–  — t        j                  t        «      }| j                  | j                  | j
                  t        i«       t        j                  | j                  d| j
                  | j                  | j                  |g| j                  t        d«      ¬«      }t        «       }t        |_        |j#                  |«      }| j%                  | j&                  | j                  j(                  d   d   «      \  }}}| j+                  |«      }|j-                  t.        «       | j1                  |j2                  j4                  «       y)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©Úkeysr4  r:  r   r=  N)r8   rŒ   r<   r{  r¨   r¥   r;   r.   r;  r„   r£   r¤   r4  rt   r   r   rž   r@   rÇ   r�   r>  rÐ   rÑ   r,   rD  r€   rE  )	rG   ÚbadKeyrÒ   r�   rÓ   r˜   r¹   r–   rÕ   s	            rH   Ú#test_publicKeyAuthenticationFailurez6NewConnectionTests.test_publicKeyAuthenticationFailure>  s  € ô —‘Ô 2Ó3ˆØ×Ñ˜TŸ[™[¨4¯9©9Ô6HÐ*IÔJä+×9Ñ9Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ�Ø—‘Ü˜uÓ%ô	
ˆô “)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ð × Ñ  Ó+ˆØ	�‰Ô#Ô$ð 	�‰˜×(Ñ(×6Ñ6Õ7rJ   c                 ó:  — t        j                  t        «      }| j                  | j                  | j
                  t        i«       t        j                  | j                  d| j
                  | j                  | j                  |g| j                  | j                  t        d«      ¬«	      }t        «       }t         |_        |j%                  |«      }| j&                  xj(                  dz  c_        | j+                  | j&                  | j                  j,                  d   d   «      \  }}}|j/                  «        | j1                  t2        «      }| j5                  d|d   j6                  j8                  |d   j6                  j6                  f«       | j;                  dt=        |«      «       | j?                  |«      }	|	jA                  t2        «       | j;                  d|	j6                  j6                  «       | jC                  |jD                  jF                  «       y	)
z{
        If the SSH server does not accept any of the specified SSH keys, the
        specified password is tried.
        rß   F)r~  r¦   r4  r:  r\   r   r=  rÉ   rÊ   N)$r8   rŒ   r<   r{  r¨   r¥   r;   r.   r;  r„   r£   r¤   r¦   r4  rt   r   r   rž   r@   r�   r‚   rÇ   r>  r–   rË   r   rÌ   rÍ   rT   rÎ   rÏ   rÐ   rÑ   rD  r€   rE  )
rG   r  rÒ   r�   rÓ   r˜   r¹   r–   rÔ   rÕ   s
             rH   Útest_authenticationFallbackz.NewConnectionTests.test_authenticationFallbackc  s™  € ô
 —‘Ô 2Ó3ˆØ×Ñ˜TŸ[™[¨4¯9©9Ô6HÐ*IÔJä+×9Ñ9Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ�Ø—]‘]Ø—‘Ü˜uÓ%ô

ˆô “)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	ð 	�‰×-Ò-°Ñ2Õ-à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ð 	�	‰	Œð ×'Ñ'¬
Ó3ˆØ�‰Ð'¨&°©)¯/©/×*>Ñ*>ÀÀqÁ	ÇÁ×@UÑ@UÐ)VÔWØ×Ñ˜œC ›KÔ(ð × Ñ  Ó+ˆØ	�‰ŒzÔØ×ÑÐ+¨Q¯W©W¯]©]Ô;ð 	�‰˜×(Ñ(×6Ñ6Õ7rJ   c                 ó’  — t        j                  t        «      }| j                  | j                  | j
                  t        i«       t        | j                  j                  d<   t        j                  | j                  d| j
                  | j                  | j                  |g| j                  t        d«      ¬«      }t!        «       }t"        |_        |j'                  |«      }| j)                  | j*                  | j                  j,                  d   d   «      \  }}}| j/                  |«      }| j1                  |j2                  «       y)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}  r   r=  N)r8   rŒ   r;   r{  r¨   r¥   rZ   r§   rd   r.   r;  r„   r£   r¤   r4  rt   r   r   rž   r@   rÇ   r�   r>  ræ   rç   r€   )	rG   ÚkeyrÒ   r�   rÓ   r˜   r¹   r–   rž   s	            rH   Útest_publicKeyAuthenticationz/NewConnectionTests.test_publicKeyAuthentication“  s  € ô
 �n‰nÔ/Ó0ˆØ×Ñ˜TŸ[™[¨4¯9©9Ô6HÐ*IÔJä/Aˆ�
‰
× Ñ  Ñ,Ü+×9Ñ9Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ�Ø—‘Ü˜uÓ%ô	
ˆô “)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ð ×'Ñ'¨	Ó2ˆØ×Ñ˜X×/Ñ/Õ0rJ   c                 ó(  — t        j                  | j                  d| j                  | j                  | j
                  | j                  t        d«      ¬«      }t        «       }t        |_
        |j                  |«      }| j                  | j                  | j                  j                  d   d   «      \  }}}|j                  «        | j!                  |«      }|j#                  t$        «       | j'                  |j(                  j*                  «       y)z†
        If the password is not specified, L{SSHCommandClientEndpoint} doesn't
        try it as an authentication mechanism.
        rß   FrW  r   r=  N)r.   r;  r„   r¥   r£   r¤   r4  rt   r   r   rž   r@   rÇ   r�   r>  r–   rÐ   rÑ   r,   rD  r€   rE  rÙ   s           rH   Útest_skipPasswordAuthenticationz2NewConnectionTests.test_skipPasswordAuthentication²  sÛ   € ô
 ,×9Ñ9Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ—‘Ü˜uÓ%ô
ˆô “)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ð 	�	‰	Œð × Ñ  Ó+ˆØ	�‰Ô#Ô$ð 	�‰˜×(Ñ(×6Ñ6Õ7rJ   c                 ób  — t        j                  t        «      }t        «       }t	        «       |_        |j                  «       |dfi|j
                  _        | j                  | j                  | j                  t        i«       t        |«      }t        j                  | j                  d| j                  | j                  | j                   | j"                  t%        d«      |¬«      }t&        | j(                  j*                  d<   t	        «       }t,        |_        |j1                  |«      }| j3                  | j
                  | j                  j4                  d   d   «      \  }}}	t7        d«      D ],  }
|j8                  j9                  «        |	j9                  «        Œ. | j;                  |«      }| j=                  |j>                  «       | jA                  ||||	«       | jC                  |j>                  jD                  «       | jC                  |j8                  jF                  jD                  «       y	)
a  
        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)r4  r:  ÚagentEndpointrØ   r   r=  é   N)$r8   rŒ   r<   r4   r   r�   Úblobr~  r{  r¨   r¥   r”   r.   r;  r„   r£   r¤   r4  rt   rZ   r§   rd   r   rž   r@   rÇ   r>  Úranger–   ræ   rç   r€   rB  rD  rE  ÚclientIO)rG   r„  ÚagentServerr‰  rÒ   r�   rÓ   r˜   r¹   r–   Úirž   s               rH   Útest_agentAuthenticationz+NewConnectionTests.test_agentAuthenticationÓ  s·  € ô �n‰nÔ/Ó0ˆÜ$Ó&ˆÜ%›iˆÔØ$'§H¡H£J°°c°
Ð#;ˆ×ÑÔ à×Ñ˜TŸ[™[¨4¯9©9Ô6HÐ*IÔJä/°Ó<ˆÜ+×9Ñ9Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ—‘Ü˜uÓ%Ø'ô	
ˆô 0Bˆ�
‰
× Ñ  Ñ,ä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×<Ñ<Ø�L‰L˜$Ÿ,™,×1Ñ1°!Ñ4°QÑ7ó 
Ñˆ�˜ô �r“ò 	ˆAØ×Ñ×#Ñ#Ô%Ø�I‰I�Kð	ð ×'Ñ'¨	Ó2ˆØ×Ñ˜X×/Ñ/Ô0ð 	×#Ñ# F¨F°H¸dÔCØ�‰˜×(Ñ(×6Ñ6Ô7Ø�‰˜×*Ñ*×3Ñ3×AÑAÕBrJ   c                 óf  — t         | j                  j                  d<   | j                  «       }t	        «       }t
        |_        |j                  |«      }| j                  «       \  }}}| j                  |«      }| j                  ||||«       | j                  |j                  j                  «       y)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)rZ   r§   rd   r¶   r   r   rž   r@   r½   ræ   rB  rD  r€   rE  rè   s           rH   Útest_loseConnectionz&NewConnectionTests.test_loseConnection  s–   € ô 0Bˆ�
‰
× Ñ  Ñ,Ø—;‘;“=ˆä“)ˆÜ#ˆÔØ×$Ñ$ WÓ-ˆ	à#×4Ñ4Ó6Ñˆ�˜à×'Ñ'¨	Ó2ˆØ×#Ñ# F¨F°H¸dÔCð 	�‰˜×(Ñ(×6Ñ6Õ7rJ   N)rK   rL   rM   rN   r±   r¶   r½   rB  r»   rJ  rO  rQ  rU  r[  r]  rd  rh  rj  rn  rs  r{  r€  r‚  r…  r‡  r�  r’  rO   rJ   rH   r/  r/  ½  s…   „ ñò
ò
ò 
ò!,òF<òGò5ò7ò:ò0=ò0 ò8*òX5ò< 9òDFò,&7òP(ò"#8òJ.8ò`1ò>8òB1Cóf8rJ   r/  c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚExistingConnectionTestsze
    Tests for L{SSHCommandClientEndpoint} when using the C{existingConnection}
    constructor.
    c                 ó  — t         j                  | «       t        t        | j	                  «       «      «      }|j                  | j                  | j                  j                  d   «       |j                  t        | j                  j                  «      | j                  j                  d   «       t        j                  | j                  d| j                  | j                  | j                   | j"                  |t%        d«      ¬«      | _        y)r1  r‹   rß   Fr9  N)r    r±   r+   r"   r2  r5  r£   r�   r�   r    r°   r6  r.   r;  r„   r¥   r¤   r¦   rt   rÒ   )rG   r4  s     rH   r±   zExistingConnectionTests.setUp#  sÂ   € ô
 	+×0Ñ0°Ô6ä#¤H¨T¯[©[«]Ó$;Ó<ˆ
Ø×Ñ˜dŸm™m¨T¯\©\×-DÑ-DÀZÑ-PÔQØ×ÑÜ˜$×,Ñ,×1Ñ1Ó2°D·L±L×4KÑ4KÈJÑ4Wô	
ô 1×>Ñ>Ø�L‰LØØ�I‰IØ�M‰MØ�I‰IØ—]‘]Ø!Ü˜uÓ%ô	
ˆ�rJ   c                 ó,  — t        «       }t        |_        | j                  j	                  |«      }| j
                  j                  j                  «       }	 t        | j
                  j                  d<   | j                  | j                  | j                  j                  d   d   «      \  }}}| j
                  j                  j                  «        | j
                  j                  j                  |«       || _        || _        || _        | j%                  |«      }|j&                  j(                  }t+        j,                  |d«      S # | j
                  j                  j                  «        | j
                  j                  j                  |«       w xY w)zz
        Create and return a new L{SSHCommandClientEndpoint} using the
        C{existingConnection} constructor.
        rØ   r   r=  rß   )r   r   rž   rÒ   r@   r§   rd   ÚcopyrZ   rÇ   r�   r„   r>  ÚclearÚupdater—   Ú_clientÚ_pumpræ   r€   Úconnr.   ÚexistingConnection)	rG   r�   rÓ   rd   r˜   r¹   r–   rž   Ú
connections	            rH   r¶   zExistingConnectionTests.create;  s9  € ô
 “)ˆÜ#ˆÔØ—M‘M×)Ñ)¨'Ó2ˆ	ð Ÿ
™
×0Ñ0×5Ñ5Ó7ˆð		;Ü3EˆD�J‰J×$Ñ$ ZÑ0à#'×#@Ñ#@Ø—‘˜dŸl™l×5Ñ5°aÑ8¸Ñ;ó$Ñ ˆF�F˜Dð
 �J‰J×$Ñ$×*Ñ*Ô,Ø�J‰J×$Ñ$×+Ñ+¨MÔ:àˆŒØˆŒØˆŒ
à×'Ñ'¨	Ó2ˆØ×'Ñ'×,Ñ,ˆ
Ü'×:Ñ:¸:À}ÓUÐUøð �J‰J×$Ñ$×*Ñ*Ô,Ø�J‰J×$Ñ$×+Ñ+¨MÕ:ús   ÁAE ÅAFc                 ó  — | j                   j                  «        | j                   j                  «        | j                   j                  «        | j                   j                  «        | j                  | j                  | j                   fS )z�
        Give back the connection established in L{create} over which the new
        command channel being tested will exchange data.
        )r›  r–   r—   rš  rF   s    rH   r½   z(ExistingConnectionTests.finishConnectionY  sU   € ð 	�
‰
�‰ÔØ�
‰
�‰ÔØ�
‰
�‰ÔØ�
‰
�‰ÔØ�|‰|˜TŸ\™\¨4¯:©:Ð5Ð5rJ   c                 ó˜   — | j                  |j                  j                  «       | j                  |j                  j                  «       y)a  
        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€   rE  rE   r¸   s      rH   r»   z2ExistingConnectionTests.assertClientTransportStateg  s8   € ð 	×Ñ˜×)Ñ)×7Ñ7Ô8Ø×Ñ˜×)Ñ)×1Ñ1Õ2rJ   N)rK   rL   rM   rN   r±   r¶   r½   r»   rO   rJ   rH   r”  r”    s   „ ñò

ò0Vò<6ó3rJ   r”  c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚExistingConnectionHelperTestsz1
    Tests for L{_ExistingConnectionHelper}.
    c                 óJ   — | j                  t        t        t        «      «       y)zT
        L{_ExistingConnectionHelper} implements L{_ISSHConnectionCreator}.
        N)rD  r   r0   r/   rF   s    rH   rJ  z,ExistingConnectionHelperTests.test_interfacew  s   € ð 	�‰œÔ$:Ô<UÓVÕWrJ   c                 óŒ   — t        «       }t        |«      }| j                  || j                  |j	                  «       «      «       y)z¸
        L{_ExistingConnectionHelper.secureConnection} returns a L{Deferred}
        which fires with whatever object was fed to
        L{_ExistingConnectionHelper.__init__}.
        N)Úobjectr/   ÚassertIsræ   ÚsecureConnection)rG   rv   Úhelpers      rH   Útest_secureConnectionz3ExistingConnectionHelperTests.test_secureConnection}  s7   € ô “ˆÜ*¨6Ó2ˆØ�‰�f˜d×2Ñ2°6×3JÑ3JÓ3LÓMÕNrJ   c                 ó^   — t        t        «       «      }|j                  t        «       d«       y)z�
        L{_ExistingConnectionHelper.cleanupConnection} does nothing to the
        existing connection if called with C{immediate} set to C{False}.
        FN©r/   r¦  ÚcleanupConnection©rG   r©  s     rH   Ú$test_cleanupConnectionNotImmediatelyzBExistingConnectionHelperTests.test_cleanupConnectionNotImmediately‡  s$   € ô
 +¬6«8Ó4ˆð 	× Ñ ¤£¨5Õ1rJ   c                 ó^   — t        t        «       «      }|j                  t        «       d«       y)zœ
        L{_ExistingConnectionHelper.cleanupConnection} does nothing to the
        existing connection if called with C{immediate} set to C{True}.
        TNr¬  r®  s     rH   Ú!test_cleanupConnectionImmediatelyz?ExistingConnectionHelperTests.test_cleanupConnectionImmediately’  s$   € ô
 +¬6«8Ó4ˆð 	× Ñ ¤£¨4Õ0rJ   N)rK   rL   rM   rN   rJ  rª  r¯  r±  rO   rJ   rH   r£  r£  r  s   „ ñòXòOò	2ó	1rJ   r£  c                   ó   — e Zd ZdZd„ Zd„ Zy)Ú_PTYPathzk
    A L{FilePath}-like object which can be opened to create a L{_ReadFile} with
    certain contents.
    c                 ó   — || _         y)zz
        @param contents: L{bytes} which will be the contents of the
            L{_ReadFile} this path can open.
        N)Úcontents)rG   rµ  s     rH   re   z_PTYPath.__init__¤  s   € ð
 !ˆ�rJ   c                 óV   — |dk(  rt        | j                  «      S t        t        d«      ‚)zÕ
        If the mode is r+, return a L{_ReadFile} with the contents given to
        this path's initializer.

        @raise OSError: If the mode is unsupported.

        @return: A L{_ReadFile} instance
        zrb+zFunction not implemented)r2   rµ  ÚOSErrorr   )rG   Úmodes     rH   Úopenz_PTYPath.open«  s(   € ð �5Š=Ü˜TŸ]™]Ó+Ð+Ü”fÐ8Ó9Ð9rJ   N)rK   rL   rM   rN   re   r¹  rO   rJ   rH   r³  r³  ž  s   „ ñò
!ó:rJ   r³  c                   óL   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zy)ÚNewConnectionHelperTestsz,
    Tests for L{_NewConnectionHelper}.
    c                 óJ   — | j                  t        t        t        «      «       y)zO
        L{_NewConnectionHelper} implements L{_ISSHConnectionCreator}.
        N)rD  r   r0   r1   rF   s    rH   rJ  z'NewConnectionHelperTests.test_interface¾  s   € ð 	�‰œÔ$:Ô<PÓQÕRrJ   c                 óD   — | j                  dt        j                  «       y)zK
        The default I{known_hosts} path is I{~/.ssh/known_hosts}.
        z~/.ssh/known_hostsN)rÎ   r1   Ú_KNOWN_HOSTSrF   s    rH   Útest_defaultPathz)NewConnectionHelperTests.test_defaultPathÄ  s   € ð 	×ÑÐ-Ô/C×/PÑ/PÕQrJ   c                 ó®   ‡— t        «       Š| j                  t        dˆfd„«       t        dddddddddd«
      }| j                  ‰|j                  «       y)zŒ
        L{_NewConnectionHelper._knownHosts} is used to create a
        L{KnownHostsFile} if one is not passed to the initializer.
        Ú_knownHostsc                 ó   •— ‰S rc   rO   )Úclsrv   s    €rH   rh   zANewConnectionHelperTests.test_defaultKnownHosts.<locals>.<lambda>Ð  s   ø€ ÀF€ rJ   N)r¦  Úpatchr1   r§  r4  )rG   r©  rv   s     @rH   Útest_defaultKnownHostsz/NewConnectionHelperTests.test_defaultKnownHostsÊ  sS   ø€ ô
 “ˆØ�
‰
Ô'¨Ó8JÔKä%Ø�$˜˜d D¨$°°d¸DÀ$ó
ˆð 	�‰�f˜f×/Ñ/Õ0rJ   c                 ó  — t        «       j                  d   }t        | j                  «       «      }t	        |«      }|j                  d|«       |j                  «        t        d|j                  ›�«       t        j                  j                  d«      }|j                  j                  |d«      }| j                  t        d|«       t        d|›�«       t        j                  «       }| j                  |j!                  d|«      «       y)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"   r2  r+   r5  r7  r#   ÚpathÚosÚ
expanduserÚreplacerÄ  r1   rÁ  rD  Ú
hasHostKey)rG   r„  rÇ  r4  ÚhomeÚdefaultÚloadeds          rH   Útest_readExistingz*NewConnectionHelperTests.test_readExistingØ  sÓ   € ô Ó×)Ñ)¨*Ñ5ˆÜ˜Ÿ™›Ó&ˆÜ# DÓ)ˆ
Ø×Ñ˜l¨CÔ0Ø�‰ÔäÐ*¨4¯9©9¨-Ð8Ô9ô �w‰w×!Ñ! $Ó'ˆØ—)‘)×#Ñ# D¨$Ó/ˆØ�
‰
Ô'¨¸ÔAÜÐ(¨¨Ð4Ô5ä%×1Ñ1Ó3ˆØ�‰˜×)Ñ)¨,¸Ó<Õ=rJ   c                 ól   — t        dddddddddd«
      }| j                  |j                  t        «       y)zz
        If L{None} is passed for the C{ui} parameter to
        L{_NewConnectionHelper}, a L{ConsoleUI} is used.
        N)r1   rà   r:  r*   r®  s     rH   Útest_defaultConsoleUIz.NewConnectionHelperTests.test_defaultConsoleUIï  s9   € ô
 &Ø�$˜˜d D¨$°°d¸DÀ$ó
ˆð 	×Ñ˜fŸi™i¬Õ3rJ   c                 óº   — t        d«      }t        dddddddddd|«      }| j                  |j                  j	                  d«      «      }| j                  |«       y)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æ   r:  rz   rD  ©rG   Úttyr©  rv   s       rH   Útest_ttyConsoleUIz*NewConnectionHelperTests.test_ttyConsoleUIù  s]   € ô �vÓˆÜ%Ø�$˜˜d D¨$°°d¸DÀ$Èó
ˆð ×%Ñ% f§i¡i×&6Ñ&6Ð7IÓ&JÓKˆØ�‰˜ÕrJ   c                 óÖ   — t        | j                  «       «      }t        dddddddddd|«      }| j                  |j                  j                  d«      «      }| j                  |«       y)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"   r2  r1   ræ   r:  rz   r¡  rÓ  s       rH   Útest_nottyUIz%NewConnectionHelperTests.test_nottyUI  se   € ô �t—{‘{“}Ó%ˆÜ%Ø�$˜˜d D¨$°°d¸DÀ$Èó
ˆð ×%Ñ% f§i¡i×&6Ñ&6Ð7IÓ&JÓKˆØ×Ñ˜Õ rJ   c                 óv   — t        dddddddddd«
      }| j                  t        d«      |j                  «       y)zy
        If not passed the name of a tty in the filesystem,
        L{_NewConnectionHelper} uses C{b"/dev/tty"}.
        Ns   /dev/tty)r1   rÎ   r"   rÔ  r®  s     rH   Útest_defaultTTYFilenamez0NewConnectionHelperTests.test_defaultTTYFilename  s>   € ô
 &Ø�$˜˜d D¨$°°d¸DÀ$ó
ˆð 	×Ñœ +Ó.°·
±
Õ;rJ   c                 óÌ   — t        dddddddddd«
      }t        «       }t        «       |_        |j	                  |d«       | j                  |j                  j                  «       y)z�
        L{_NewConnectionHelper.cleanupConnection} closes the transport cleanly
        if called with C{immediate} set to C{False}.
        NF)r1   r6   r   r€   r­  rD  rE  )rG   r©  rž  s      rH   r¯  z=NewConnectionHelperTests.test_cleanupConnectionNotImmediately  s_   € ô
 &Ø�$˜˜d D¨$°°d¸DÀ$ó
ˆô #“_ˆ
Ü.Ó0ˆ
ÔØ× Ñ  ¨UÔ3Ø�‰˜
×,Ñ,×:Ñ:Õ;rJ   c                 ó   —  G d„ d«      }t        dddddddddd«
      }t        «       }t        «       |_         |«       |j                  _        |j	                  |d«       | j                  |j                  j                  j                  «       y)zœ
        L{_NewConnectionHelper.cleanupConnection} closes the transport with
        C{abortConnection} if called with C{immediate} set to C{True}.
        c                   ó   — e Zd ZdZd„ Zy)úMNewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.AbortableFc                 ó   — d| _         y)z7
                Abort the connection.
                TNrD   rF   s    rH   rI   z]NewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.Abortable.abortConnection3  s   € ð  $�•rJ   N)rK   rL   rM   rE   rI   rO   rJ   rH   Ú	AbortablerÝ  0  s   „ ØˆGó$rJ   rß  NT)r1   r6   r9   r€   r­  rD  rE   )rG   rß  r©  rž  s       rH   r±  z:NewConnectionHelperTests.test_cleanupConnectionImmediately*  s   € ÷	$ñ 	$ô &Ø�$˜˜d D¨$°°d¸DÀ$ó
ˆô #“_ˆ
Ü1Ó3ˆ
ÔÙ)2«ˆ
×ÑÔ&Ø× Ñ  ¨TÔ2Ø�‰˜
×,Ñ,×6Ñ6×>Ñ>Õ?rJ   N)rK   rL   rM   rN   rJ  r¿  rÅ  rÏ  rÑ  rÕ  r×  rÙ  r¯  r±  rO   rJ   rH   r»  r»  ¹  s<   „ ñòSòRò1ò>ò.4ò ò!ò<ò<ó@rJ   r»  )wrN   Úos.pathrÈ  Úerrnor   Ústructr   Ú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   r2   Útwisted.conch.sshr3   Útwisted.conch.ssh.agentr4   Útwisted.conch.ssh.channelr5   Útwisted.conch.ssh.connectionr6   Útwisted.conch.ssh.factoryr7   Útwisted.conch.ssh.keysr8   Útwisted.conch.ssh.transportr9   Útwisted.conch.ssh.userauthr:   Útwisted.conch.test.keydatar;   r<   r=   r>   Úskipr¦  Útwisted.test.iosimr?   r@   rB   rQ   rZ   r^   ra   ro   rt   r~   rˆ   r’   r”   r    r/  r”  r£  r³  r»  rO   rJ   rH   ú<module>r     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3˜hÐ(Jô R3ôj)1 Hô )1÷X:ñ :ô6G@˜xõ G@rJ   