§
    Ètºf÷Ú  ã                   ó¢  — 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
 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/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z=  e;d¦  «        rcddl>m?Z? ddl@mAZAmBZB ddlCmDZDmEZE ddlFmGZGmHZHmIZImJZJmKZKmLZL ddlMmNZN ddlOmPZP dd lQmRZR dd!lSmTZT dd"lUmVZV dd#lWmXZX dd$lYmZZZ dd%l[m\Z\ dd&l]m^Z^m_Z_m`Z`maZa nd'ZbecZVecZ\ecZTecZXecZRecZPecZEecZBecZ?dd(ldmeZemfZf  G d)„ d*ee¦  «        Zg G d+„ d,eR¦  «        Zh G d-„ d.eR¦  «        Zi G d/„ d0eR¦  «        Zj G d1„ d2¦  «        Zk G d3„ d4e)¦  «        Zl G d5„ d6¦  «        Zm G d7„ d8e\¦  «        Zn G d9„ d:eV¦  «        Zo e
e&¦  «         G d;„ d<¦  «        ¦   «         Zp e
e'¦  «         G d=„ d>¦  «        ¦   «         Zq G d?„ d@¦  «        Zr G dA„ dBe=er¦  «        Zs G dC„ dDe=er¦  «        Zt G dE„ dFe=¦  «        Zu G dG„ dHe¦  «        Zv G dI„ dJ¦  «        Zw G dK„ dLe=¦  «        ZxdS )Mz'
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                   ó   — e Zd ZdZdZd„ ZdS )ÚAbortableFakeTransportzC
    A L{FakeTransport} with added C{abortConnection} support.
    Fc                 ó   — d| _         dS )z}
        Abort the connection in a fake manner.

        This should really be implemented in the underlying module.
        TN©Úaborted©Úselfs    ú`/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/conch/test/test_endpoints.pyÚabortConnectionz&AbortableFakeTransport.abortConnection]   s   € ð ˆŒˆˆó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rE   rI   © rJ   rH   rB   rB   V   s4   € € € € € ðð ð €Gðð ð ð ð rJ   rB   c                   ó   — e Zd ZdZd„ ZdS )ÚBrokenExecSessionzO
    L{BrokenExecSession} is a session on which exec requests always fail.
    c                 ó   — dS )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   ó	   € ð ˆqrJ   N©rK   rL   rM   rN   rU   rO   rJ   rH   rQ   rQ   f   ó-   € € € € € ðð ð
ð 
ð 
ð 
ð 
rJ   rQ   c                   ó   — e Zd ZdZd„ ZdS )ÚWorkingExecSessionzS
    L{WorkingExecSession} is a session on which exec requests always succeed.
    c                 ó   — dS )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dS )Ú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ŒzÐrJ   NrW   rO   rJ   rH   r^   r^   Š   s-   € € € € € ðð ð

ð 
ð 
ð 
ð 
rJ   r^   c                   ó   — e Zd Zd„ Zd„ ZdS )ÚTrivialRealmc                 ó   — i | _         d S ©N)ÚchannelLookuprF   s    rH   Ú__init__zTrivialRealm.__init__ž   s   € ØˆÔÐÐrJ   c                 óL   — t          ¦   «         }| j        |_        t          |d„ fS )Nc                  ó   — d S rc   rO   rO   rJ   rH   ú<lambda>z,TrivialRealm.requestAvatar.<locals>.<lambda>¤   s   € ¨D€ rJ   )r(   rd   r   )rG   ÚavatarIdÚmindÚ
interfacesÚavatars        rH   ÚrequestAvatarzTrivialRealm.requestAvatar¡   s%   € Ý‘”ˆØ#Ô1ˆÔÝ˜F L LÐ1Ð1rJ   N)rK   rL   rM   re   rm   rO   rJ   rH   ra   ra   �   s2   € € € € € ð ð  ð  ð2ð 2ð 2ð 2ð 2rJ   ra   c                   ó   — e Zd ZdZd„ ZdS )ÚAddressSpyFactoryNc                 ó:   — || _         t          j        | |¦  «        S rc   )Úaddressr   ÚbuildProtocol)rG   rq   s     rH   rr   zAddressSpyFactory.buildProtocolª   s   € ØˆŒÝÔ$ T¨7Ñ3Ô3Ð3rJ   )rK   rL   rM   rq   rr   rO   rJ   rH   ro   ro   §   s(   € € € € € Ø€Gð4ð 4ð 4ð 4ð 4rJ   ro   c                   ó    — e Zd Zd„ Zd„ Zd„ ZdS )ÚFixedResponseUIc                 ó   — || _         d S 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                 ó   — d S rc   rO   rx   s     rH   ÚwarnzFixedResponseUI.warn¶   s   € ØˆrJ   N)rK   rL   rM   re   rz   r|   rO   rJ   rH   rt   rt   ¯   sA   € € € € € ðð ð ð$ð $ð $ðð ð ð ð rJ   rt   c                   ó:   — e Zd Zed„ ¦   «         Zed„ ¦   «         ZdS )ÚFakeClockSSHUserAuthServerc                 ó$   — | 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                 ó$   — | 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~   º   sH   € € € € € àð?ð ?ñ „Xð?ð ð.ð .ñ „Xð.ð .ð .rJ   r~   c                   óH   — e Zd Zed„ ¦   «         Zed„ ¦   «         ZeedœZdZ	dS )ÚCommandFactoryc                 ó:   — dt          j        t          ¬¦  «        iS ©Nó   ssh-rsa)rT   )r8   Ú
fromStringr>   rF   s    rH   Ú
publicKeyszCommandFactory.publicKeysÏ   s   € à�CœNÕ0AÐBÑBÔBÐCÐCrJ   c                 ó:   — dt          j        t          ¬¦  «        iS rŠ   )r8   rŒ   r<   rF   s    rH   ÚprivateKeyszCommandFactory.privateKeysÓ   s   € à�CœNÕ0BÐCÑCÔCÐDÐDrJ   )s   ssh-userauths   ssh-connectionr   N)
rK   rL   rM   r†   r�   r�   r~   r6   Úservicesr‚   rO   rJ   rH   rˆ   rˆ   Î   sf   € € € € € ØðDð Dñ „XðDð ðEð Eñ „XðEð 4Ø(ðð €Hð  !ÐÐÐrJ   rˆ   c                   ó   — e Zd ZdS )ÚMemoryAddressN)rK   rL   rM   rO   rJ   rH   r’   r’   ã   s   € € € € € à€DrJ   r’   c                   ó   — e Zd ZdZd„ Zd„ ZdS )Ú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| _         || _        dS )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  — | j         �t          d¦  «        ‚	 |                     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Ð ÝÐFÑGÔGÐGð	%Ø×,Ò,­]©_¬_Ñ=Ô=ˆHõ  Ø”Ý& t¤|¸dÐCÑCÔCØÝ& x¸%Ð@Ñ@Ô@ñ	ô ˆDŒIõ ˜8Ñ$Ô$Ð$øõ ð 	ð 	ð 	Ý‘6”6ˆMˆMˆMð	øøøs   ˜!B Â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dS )Ú"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        ¦  «         t          ¦   «         | _        | j        | j        _        | j	        | j        _	        | j                             ¦   «          |                      | j        j        ¦  «         t'          ddd¦  «        | _        t'          ddd	¦  «        | _        d S )
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Ñ(Ô(ˆŒÝ?ÑAÔAˆŒØŒ×Ò˜dœi¨¬Ñ7Ô7Ð7ØŒ×#Ò# D¤MÑ2Ô2Ð2Ý%Ñ'Ô'ˆŒØ#œ|ˆŒÔØ"œkˆŒÔØŒ×ÒÑÔÐØ�Š˜œÔ+Ñ,Ô,Ð,å(¨°
¸EÑBÔBˆÔÝ(¨Ð0AÀ5ÑIÔIˆÔÐÐrJ   c                 ó:   — 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'   € õ
 "ØŒ~Ô&ÐCÐCÐCñ
ô 
ð 	
rJ   c                 ó:   — 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                 ó:   — 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'   € õ
 "ØŒ~Ô&ÐMÐMÐMñ
ô 
ð 	
rJ   c                 óø   — |                      d¦  «        }|                      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ÔXˆØ˜~¨tÐ3Ð3rJ   c                 óp  — |                       ¦   «         }t          ¦   «         }t          |_        |                     |¦  «        }|                      ¦   «         \  }}}|                      t          ¦  «        }|                      d|d         j	        j
        |d         j	        j	        f¦  «         |                      dt          |¦  «        ¦  «         |                      |¦  «        }|                     t          ¦  «         |                      d|j	        j	        ¦  «         |                      |d¦  «         dS )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Ô6Ñˆ�˜ð ×'Ò'­
Ñ3Ô3ˆØ�ŠÐ'¨&°¬)¬/Ô*>ÀÀqÄ	ÄÔ@UÐ)VÑWÔWÐWØ×Ò˜�C ™KœKÑ(Ô(Ð(ð × Ò  Ñ+Ô+ˆØ	�Š�zÑÔÐØ×ÒÐ+¨Q¬W¬]Ñ;Ô;Ð;à×'Ò'¨°Ñ6Ô6Ð6Ð6Ð6rJ   c                 ó®  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }| 
                    t          ¦  «         |                      d|j        j        ¦  «         |                      |d¦  «         dS )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Ô6Ñˆ�˜à× Ò  Ñ+Ô+ˆØ	�Š�zÑÔÐØ×ÒÐ1°1´7´=ÑAÔAÐAà×'Ò'¨°Ñ6Ô6Ð6Ð6Ð6rJ   c                 ó–  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}| 	                    ¦   «          |  
                    |¦  «        }|                     t          ¦  «         |                      |d¦  «         dS )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Ô6Ñˆ�˜à×ÒÑÔÐà× Ò  Ñ+Ô+ˆØ	�Š�~ÑÔÐà×'Ò'¨°Ñ5Ô5Ð5Ð5Ð5rJ   c                 ó  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «         |                      ¦   «         \  }}}|  	                    |j
        t          ¦  «         |                      |j                             ¦   «         |j
        j        ¦  «         |                      | j        |j
        j        ¦  «         |                      d|j
        j        ¦  «         dS )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Ô6Ñˆ�˜à×Ò˜gœoÕ/@ÑAÔAÐAØ×Ò˜Ô)×1Ò1Ñ3Ô3°W´_Ô5KÑLÔLÐLØ×Ò˜œ G¤OÔ$<Ñ=Ô=Ð=Ø×Ò˜¨¬Ô(?Ñ@Ô@Ð@Ð@Ð@rJ   c                 óB  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }|  
                    |j        ¦  «         dS )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Ô6Ñˆ�˜à×'Ò'¨	Ñ2Ô2ˆØ×Ò˜XÔ/Ñ0Ô0Ð0Ð0Ð0rJ   c                 ó  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }g }|j
        |_        |j        j        }	|j        j        |	                              d¦  «         |                     ¦   «          |                      dd                     |¦  «        ¦  «         dS )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Ô6Ñˆ�˜à×'Ò'¨	Ñ2Ô2ˆØˆØ ,Ô 3ˆÔð Ô&Ô)ˆ	àŒÔ 	Ô*×0Ò0°ÑAÔAÐAØ�	Š	‰ŒˆØ×Ò˜¨#¯(ª(°<Ñ*@Ô*@ÑAÔAÐAÐAÐArJ   c                 ó  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }g }|j
        |_        |j        j        }	|j        j        |	                              ¦   «          |                     ¦   «          |d                              t&          ¦  «         |                      |d¦  «         dS )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Ô6Ñˆ�˜à×'Ò'¨	Ñ2Ô2ˆØˆØ"0Ô"7ˆÔð Ô&Ô)ˆ	ØŒÔ 	Ô*×9Ò9Ñ;Ô;Ð;à�	Š	‰ŒˆØ�qÔ×Ò�~Ñ.Ô.Ð.à×'Ò'¨°Ñ6Ô6Ð6Ð6Ð6rJ   c                 ó&  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }	g }
|
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Ô6Ñˆ�˜à×'Ò'¨	Ñ2Ô2ˆØˆØ"0Ô"7ˆÔð
 Ô&Ô)ˆ	Ø”.Ô)¨)Ô4ˆàŒ×"Ò" 7¨G°ZÑ@Ô@Ð@Ø×ÒÑ Ô Ð Ø�	Š	‰ŒˆØ×'Ò'¨°Ñ6Ô6Ð6Ø˜aÔ Ð rJ   c                 ó†   — d}|                       dt          d|¦  «        ¦  «        }|                     t          ¦  «         dS )úÊ
        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Ô3GÑHÔHˆØ�Š•Ñ Ô Ð Ð Ð rJ   c                 ó
  — d}d}|                       dt          d|¦  «        ¦  «        }|                     t          ¦  «         |                      ||j        j        ¦  «         |                      ||j        j        ¦  «         dS )r   é{   Nr  r  )rþ   r   rÑ   r   rÎ   rÍ   r  Úsignal)rG   r  r  r  s       rH   Útest_nonZeroExitStatusz9SSHCommandClientEndpointTestsMixin.test_nonZeroExitStatus<  s|   € ð ˆØˆØ×"Ò" >µ4¸¸hÑ3GÔ3GÑHÔHˆØ�ŠÕ"Ñ#Ô#Ð#Ø×Ò˜ 3¤9Ô#5Ñ6Ô6Ð6Ø×Ò˜ ¤Ô!1Ñ2Ô2Ð2Ð2Ð2rJ   c                 óÌ  — t          ¦   «         }t          j        |¦  «         |                      t          j        |¦  «         d}d}d                     t          j        d¦  «        dt          j        d¦  «        t          j        d¦  «        g¦  «        }|                      d|¦  «        }| 	                    t          ¦  «         |                      ||j        j        ¦  «         |                      ||j        j        ¦  «         d	}t          j        |t          j        t          j        t          j        t(          j        ¦  «        |dd
dddœ¦  «        ¦  «        ¦  «         dS )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  sT  € õ +Ñ,Ô,ˆÝÔ& {Ñ3Ô3Ð3Ø�ŠÕ*Ô9¸;ÑGÔGÐGàˆØˆà—’å”	˜'Ñ"Ô"àÝ”	˜*Ñ%Ô%Ý”	˜(Ñ#Ô#ðñ
ô 
ˆð ×"Ò" >°6Ñ:Ô:ˆØ�ŠÕ"Ñ#Ô#Ð#Ø×Ò˜ 3¤9Ô#5Ñ6Ô6Ð6Ø×Ò˜ ¤Ô!1Ñ2Ô2Ð2à@ˆÝÔØÝÔÝÔ$å%-Ô%6µx´}Ñ%EÔ%EØ)5Ø+2Ø&*Ø(1Ø'/ðð ñ	ô 	ñô ñ	
ô 	
ð 	
ð 	
ð 	
rJ   Fc                 ó„   ‡— |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                  ó.   •— ‰                       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  sU   ø€ ð  Ô&Ô)ˆ	àˆØð 	 Ø-Ð-Ð-Ð-ˆAˆAà”ˆAå�”Ô'¨	Ô2°E¸1Ñ=Ô=Ð=ØˆrJ   c                 óê  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }|  
                    ||d¦  «        }|j                             d¦  «         |                     ¦   «          |                      dd                     |¦  «        ¦  «         dS )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Ô6Ñˆ�˜à×'Ò'¨	Ñ2Ô2ˆà—{’{ 6¨8°^ÑDÔDˆØÔ× Ò  Ñ1Ô1Ð1Ø�	Š	‰ŒˆØ×Ò˜¨#¯(ª(°<Ñ*@Ô*@ÑAÔAÐAÐAÐArJ   c                 óì  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }|  
                    ||d¦  «        }|j                             dg¦  «         |                     ¦   «          |                      dd                     |¦  «        ¦  «         dS )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Ô6Ñˆ�˜à×'Ò'¨	Ñ2Ô2ˆà—{’{ 6¨8°^ÑDÔDˆØÔ×(Ò(¨/Ð):Ñ;Ô;Ð;Ø�	Š	‰ŒˆØ×Ò˜¨#¯(ª(°<Ñ*@Ô*@ÑAÔAÐAÐAÐ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      sR  € € € € € ðð ðJð Jð Jð(
ð 
ð 
ð
ð 
ð 
ð 
ð 
ð 
ð4ð 4ð 4ð:7ð 7ð 7ð47ð 7ð 7ð*6ð 6ð 6ð*Að Að Að.1ð 1ð 1ð&Bð Bð Bð67ð 7ð 7ð8!ð !ð !ð:!ð !ð !ð3ð 3ð 3ð,
ð ,
ð ,
ð\ð ð ð ð6Bð Bð Bð*Bð Bð Bð 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dS )ÚNewConnectionTestsz`
    Tests for L{SSHCommandClientEndpoint} when using the C{newConnection}
    constructor.
    c                 óÎ  — t                                | ¦  «         t          |                      ¦   «         ¦  «        | _        t          | j        ¦  «        | _        | j                             | j        | j	        j
        d         ¦  «         | j                             t          | j        j        ¦  «        | j	        j
        d         ¦  «         | j                             ¦   «          dS )ú
        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Ô6Ð6å# D§K¢K¡M¤MÑ2Ô2ˆÔÝ(¨Ô)9Ñ:Ô:ˆŒØŒ×"Ò" 4¤=°$´,Ô2IÈ*Ô2UÑVÔVÐVØŒ×"Ò"Ý˜$Ô,Ô1Ñ2Ô2°D´LÔ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Ò  sJ   € õ
 (Ô5ØŒLØØŒIØŒMØŒIØ”]Ø”Ý˜uÑ%Ô%ð	
ñ 	
ô 	
ð 		
rJ   c                 ód   — |                       | 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â  s2   € ð
 ×,Ò,ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ
ô 
ð 	
rJ   c                 ó  — |                       ||dd¬¦  «        }|j                             ¦   «          |                     ¦   «          |                      dg|¦  «         |                     ¦   «          |j                             ¦   «          dS )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ë  sƒ   € ð* —’˜V X¨xÀ�ÑEÔEˆØÔ×)Ò)Ñ+Ô+Ð+Ø�	Š	‰ŒˆØ×Ò˜$˜ Ñ(Ô(Ð(ð
 	�	Š	‰Œˆð 	Ô×)Ò)Ñ+Ô+Ð+Ð+Ð+rJ   c                 óŠ   — |r!|                       |j        j        ¦  «         dS |                       |j        j        ¦  «         dS )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  sH   € ð ð 	<Ø�OŠO˜FÔ,Ô4Ñ5Ô5Ð5Ð5Ð5à�OŠO˜FÔ,Ô:Ñ;Ô;Ð;Ð;Ð;rJ   c                 ó¤   — t          j        | j        dd| j        | j        ¦  «        }|                      t          t          |¦  «        ¦  «         dS )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  sM   € õ ,Ô9ØŒLÐ*¨M¸4¼=È$Ì)ñ
ô 
ˆð 	�Š�Õ%:¸HÑEÔEÑFÔFÐFÐFÐFrJ   c                 óˆ   — t          j        | j        dd| j        ¦  «        }|                      d|j        j        ¦  «         dS )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$  sH   € õ
 ,Ô9ØŒLÐ*¨M¸4¼=ñ
ô 
ˆð 	×Ò˜˜XÔ.Ô3Ñ4Ô4Ð4Ð4Ð4rJ   c                 óŒ   — t          j        | j        dd| j        d¬¦  «        }|                      d|j        j        ¦  «         dS )zU
        L{SSHCommandClientEndpoint} uses the C{port} argument if specified.
        rG  rH  i®  )r¤   NrM  rI  s     rH   Útest_specifiedPortz%NewConnectionTests.test_specifiedPort.  sO   € õ ,Ô9ØŒLÐ*¨M¸4¼=Ètð
ñ 
ô 
ˆð 	×Ò˜˜xÔ0Ô5Ñ6Ô6Ð6Ð6Ð6rJ   c                 ó  — t          j        | j        d| j        | j        | j        | j        | j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_        |                     |¦  «         | j        j        d         \  }}}}}|                      | j        t          |¦  «        ¦  «         |                      | j        |¦  «         |                      dt!          | j        j        ¦  «        ¦  «         dS )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ØŒLØØŒIØŒMØŒIØ”]Ø”Ý˜uÑ%Ô%ð	
ñ 	
ô 	
ˆõ ‘)”)ˆÝ#ˆÔØ×Ò˜Ñ!Ô!Ð!à48´LÔ4KÈAÔ4NÑ1ˆˆd�G˜W kØ×Ò˜œ­°dÑ(;Ô(;Ñ<Ô<Ð<Ø×Ò˜œ DÑ)Ô)Ð)Ø×Ò˜�C ¤Ô 7Ñ8Ô8Ñ9Ô9Ð9Ð9Ð9rJ   c                 óÄ  — t          j        | j        dd| j        | j        | j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_	        | 
                    |¦  «        }| j        j        d         d         }|                     dt          t          ¦   «         ¦  «        ¦  «         |                      |¦  «                             t          ¦  «         dS )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ØŒLØØØŒMØŒIØ”Ý˜uÑ%Ô%ð
ñ 
ô 
ˆõ ‘)”)ˆÝ#ˆÔØ×Ò˜WÑ%Ô%ˆà”,Ô)¨!Ô,¨QÔ/ˆØ×&Ò& t­WÕ5KÑ5MÔ5MÑ-NÔ-NÑOÔOÐOà×Ò˜QÑÔ×$Ò$Õ%;Ñ<Ô<Ð<Ð<Ð<rJ   c                 óØ  — t          j        | j        dd| j        | j        t          |                      ¦   «         ¦  «        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_
        |                     |¦  «        }|                      | j        | j        j        d         d         ¦  «        \  }}}|                      |¦  «        }|                     t"          ¦  «         dS )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ØŒLØØØŒMØŒIÝ% d§k¢k¡m¤mÑ4Ô4Ý˜uÑ%Ô%ð
ñ 
ô 
ˆõ ‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜ð × Ò  Ñ+Ô+ˆØ	�Š�ÑÔÐÐÐrJ   c           
      ó<  — t          j        t          ¦  «                             ¦   «         }t	          t          |                      ¦   «         ¦  «        ¦  «        }|                     t          | j	        j
        ¦  «        |¦  «         t          j        t          d¬¦  «                             ¦   «         }|                     | j        |¦  «         t          d¦  «        }t          j        | j        dd| j        | j        d||¬¦  «        }t%          ¦   «         }t&          |_        |                     |¦  «        }|                      | j        | j        j        d         d	         ¦  «        \  }}	}
|                      |¦  «        }|                     t6          ¦  «         d
S )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ƒ  sk  € õ ”>Õ"4Ñ5Ô5×<Ò<Ñ>Ô>ˆÝ#¥H¨T¯[ª[©]¬]Ñ$;Ô$;Ñ<Ô<ˆ
Ø×Ò�m¨DÔ,>Ô,CÑDÔDÀhÑOÔOÐOå”~Ý,¸ð
ñ 
ô 
ç
Š&‰(Œ(ð 	ð 	×Ò˜dœm¨\Ñ:Ô:Ð:õ
 ˜TÑ"Ô"ˆå+Ô9ØŒLØØØŒMØŒIØ&Ø!Øð	
ñ 	
ô 	
ˆõ ‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜ð × Ò  Ñ+Ô+ˆØ	�Š�~ÑÔÐÐÐrJ   c                 ó2  — t          j        | j        dd| j        | j        | j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_	        | 
                    |¦  «        }t          ¦   «         }| j        j        d         d         }|                     d¦  «        }|                     |¦  «         |                     t!          t#          ¦   «         ¦  «        ¦  «         |                      |¦  «                             t"          ¦  «         dS )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ØŒLØØØŒMØŒIØ”Ý˜uÑ%Ô%ð
ñ 
ô 
ˆõ ‘)”)ˆÝ#ˆÔØ×Ò˜WÑ%Ô%ˆå#Ñ%Ô%ˆ	Ø”,Ô)¨!Ô,¨QÔ/ˆØ×&Ò& tÑ,Ô,ˆØ×Ò˜iÑ(Ô(Ð(à×Ò�g¥nÑ&6Ô&6Ñ7Ô7Ñ8Ô8Ð8Ø×Ò˜QÑÔ×$Ò$¥^Ñ4Ô4Ð4Ð4Ð4rJ   c                 ó”  — t          j        | j        dd| j        | j        | j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_	        | 
                    |¦  «        }t          dd¬¦  «        }| j        j        d         d         }|                     d¦  «        }|                     |¦  «         |                     ¦   «          |                      |¦  «                             t$          ¦  «         |                      |j        ¦  «         |                     t-          t/          ¦   «         ¦  «        ¦  «         dS )	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ØŒLØØØŒMØŒIØ”Ý˜uÑ%Ô%ð
ñ 
ô 
ˆõ ‘)”)ˆÝ#ˆÔØ×Ò˜WÑ%Ô%ˆå*¨4¸%Ð@Ñ@Ô@ˆ	Ø”,Ô)¨!Ô,¨QÔ/ˆØ×&Ò& tÑ,Ô,ˆØ×Ò˜iÑ(Ô(Ð(Ø	�Š‰
Œ
ˆ
à×Ò˜QÑÔ×$Ò$¥^Ñ4Ô4Ð4Ø�Š˜	Ô)Ñ*Ô*Ð*ð 	×Ò�g¥nÑ&6Ô&6Ñ7Ô7Ñ8Ô8Ð8Ð8Ð8rJ   c                 ó²  — t          j        | j        dd| j        | j        | j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_	        | 
                    |¦  «        }|                     ¦   «          |                      |¦  «                             t          ¦  «         |                      | j        j        d         j        ¦  «         dS )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ØŒLØØØŒMØŒIØ”Ý˜uÑ%Ô%ð
ñ 
ô 
ˆõ ‘)”)ˆÝ#ˆÔØ×Ò˜WÑ%Ô%ˆØ	�Š‰
Œ
ˆ
Ø×Ò˜QÑÔ×$Ò$Õ%=Ñ>Ô>Ð>Ø�Š˜œÔ/°Ô2ÔDÑEÔEÐEÐEÐErJ   c                 óB  — t          j        | j        dd| j        | j        d| j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_	        | 
                    |¦  «        }|                      | j        | j        j        d         d         ¦  «        \  }}}| j                             |j        j        ¦  «         |                     ¦   «          |                      |¦  «        }|                     t(          ¦  «         |                      |d¦  «         dS )	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ØŒLØØØŒMØŒIØ&Ø”Ý˜uÑ%Ô%ð	
ñ 	
ô 	
ˆõ ‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜ð 	Œ×Ò˜Vœ^Ô9Ñ:Ô:Ð:ð 	�
Š
‰Œˆà× Ò  Ñ+Ô+ˆØ	�ŠÕ#Ñ$Ô$Ð$ð 	×'Ò'¨°Ñ6Ô6Ð6Ð6Ð6rJ   c                 ó¤   — d„ |                      ¦   «         D ¦   «         }t          t          |¦  «        ¦  «        }|                     |¦  «         dS )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}
        c                 ód   — i | ]-\  }}|t          j        |¦  «                             ¦   «         g“Œ.S rO   )r8   rŒ   ra  )Ú.0ÚkÚvs      rH   ú
<dictcomp>z6NewConnectionTests.setupKeyChecker.<locals>.<dictcomp>:  s7   € ÐMÐMÐM±t°q¸!�1•s”~ aÑ(Ô(×/Ò/Ñ1Ô1Ð2ÐMÐMÐMrJ   N)Úitemsr*   r)   r«   )rG   r¨   ÚusersÚmappingÚcheckers        rH   ÚsetupKeyCheckerz"NewConnectionTests.setupKeyChecker-  sP   € ð NÐM¸u¿{º{¹}¼}ÐMÑMÔMˆÝ%Õ&6°wÑ&?Ô&?Ñ@Ô@ˆØ×Ò˜wÑ'Ô'Ð'Ð'Ð'rJ   c                 óp  — t          j        t          ¦  «        }|                      | j        | j        t          i¦  «         t          j        | j	        d| j        | j
        | j        |g| j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_        |                     |¦  «        }|                      | j        | j	        j        d         d         ¦  «        \  }}}|                      |¦  «        }|                     t.          ¦  «         |                      |j        j        ¦  «         dS )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Ô3ˆØ×Ò˜Tœ[¨4¬9Õ6HÐ*IÑJÔJÐJå+Ô9ØŒLØØŒIØŒMØŒIØ�Ø”Ý˜uÑ%Ô%ð	
ñ 	
ô 	
ˆõ ‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜ð × Ò  Ñ+Ô+ˆØ	�ŠÕ#Ñ$Ô$Ð$ð 	�Š˜Ô(Ô6Ñ7Ô7Ð7Ð7Ð7rJ   c                 óø  — t          j        t          ¦  «        }|                      | j        | j        t          i¦  «         t          j        | j	        d| j        | j
        | j        |g| j        | j        t          d¦  «        ¬¦	  «	        }t          ¦   «         }t           |_        |                     |¦  «        }| j        xj        dz  c_        |                      | j        | j	        j        d         d         ¦  «        \  }}}|                     ¦   «          |                      t2          ¦  «        }|                      d|d         j        j        |d         j        j        f¦  «         |                      dt=          |¦  «        ¦  «         |                      |¦  «        }	|	                      t2          ¦  «         |                      d|	j        j        ¦  «         |  !                    |j"        j#        ¦  «         d	S )
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Ô3ˆØ×Ò˜Tœ[¨4¬9Õ6HÐ*IÑJÔJÐJå+Ô9ØŒLØØŒIØŒMØŒIØ�Ø”]Ø”Ý˜uÑ%Ô%ð

ñ 

ô 

ˆõ ‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	ð 	ŒÐ-Ô-°Ñ2Ð-Ô-à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜ð 	�	Š	‰Œˆð ×'Ò'­
Ñ3Ô3ˆØ�ŠÐ'¨&°¬)¬/Ô*>ÀÀqÄ	ÄÔ@UÐ)VÑWÔWÐWØ×Ò˜�C ™KœKÑ(Ô(Ð(ð × Ò  Ñ+Ô+ˆØ	�Š�zÑÔÐØ×ÒÐ+¨Q¬W¬]Ñ;Ô;Ð;ð 	�Š˜Ô(Ô6Ñ7Ô7Ð7Ð7Ð7rJ   c                 óZ  — t          j        t          ¦  «        }|                      | j        | j        t          i¦  «         t          | j        j        d<   t          j
        | j        d| j        | j        | j        |g| j        t          d¦  «        ¬¦  «        }t!          ¦   «         }t"          |_        |                     |¦  «        }|                      | j        | j        j        d         d         ¦  «        \  }}}|                      |¦  «        }|                      |j        ¦  «         dS )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Õ/Ñ0Ô0ˆØ×Ò˜Tœ[¨4¬9Õ6HÐ*IÑJÔJÐJå/AˆŒ
Ô  Ñ,Ý+Ô9ØŒLØØŒIØŒMØŒIØ�Ø”Ý˜uÑ%Ô%ð	
ñ 	
ô 	
ˆõ ‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜ð ×'Ò'¨	Ñ2Ô2ˆØ×Ò˜XÔ/Ñ0Ô0Ð0Ð0Ð0rJ   c                 ó  — t          j        | j        d| j        | j        | j        | j        t          d¦  «        ¬¦  «        }t          ¦   «         }t          |_
        |                     |¦  «        }|                      | j        | j        j        d         d         ¦  «        \  }}}|                     ¦   «          |                      |¦  «        }|                     t$          ¦  «         |                      |j        j        ¦  «         dS )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ØŒLØØŒIØŒMØŒIØ”Ý˜uÑ%Ô%ð
ñ 
ô 
ˆõ ‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜ð 	�	Š	‰Œˆð × Ò  Ñ+Ô+ˆØ	�ŠÕ#Ñ$Ô$Ð$ð 	�Š˜Ô(Ô6Ñ7Ô7Ð7Ð7Ð7rJ   c                 ó0  — t          j        t          ¦  «        }t          ¦   «         }t	          ¦   «         |_        |                     ¦   «         |dfi|j        _        |                      | j	        | j
        t          i¦  «         t          |¦  «        }t          j        | j        d| j
        | j        | j        | j        t%          d¦  «        |¬¦  «        }t&          | j        j        d<   t	          ¦   «         }t,          |_        |                     |¦  «        }|                      | j        | j        j        d         d         ¦  «        \  }}}	t7          d¦  «        D ]/}
|j                             ¦   «          |	                     ¦   «          Œ0|                      |¦  «        }|                      |j        ¦  «         |                       ||||	¦  «         |  !                    |j        j"        ¦  «         |  !                    |j        j#        j"        ¦  «         d	S )
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Õ/Ñ0Ô0ˆÝ$Ñ&Ô&ˆÝ%™iœiˆÔØ$'§H¢H¡J¤J°°c°
Ð#;ˆÔÔ à×Ò˜Tœ[¨4¬9Õ6HÐ*IÑJÔJÐJå/°Ñ<Ô<ˆÝ+Ô9ØŒLØØŒIØŒMØŒIØ”Ý˜uÑ%Ô%Ø'ð	
ñ 	
ô 	
ˆõ 0BˆŒ
Ô  Ñ,å‘)”)ˆÝ#ˆÔØ×$Ò$ WÑ-Ô-ˆ	à#×<Ò<ØŒL˜$œ,Ô1°!Ô4°QÔ7ñ 
ô  
Ñˆ�˜õ �r‘”ð 	ð 	ˆAØÔ×#Ò#Ñ%Ô%Ð%Ø�IŠI‰KŒKˆKˆKà×'Ò'¨	Ñ2Ô2ˆØ×Ò˜XÔ/Ñ0Ô0Ð0ð 	×#Ò# F¨F°H¸dÑCÔCÐCØ�Š˜Ô(Ô6Ñ7Ô7Ð7Ø�Š˜Ô*Ô3ÔAÑBÔBÐBÐBÐBrJ   c                 ó|  — t           | j        j        d<   |                      ¦   «         }t	          ¦   «         }t
          |_        |                     |¦  «        }|                      ¦   «         \  }}}|  	                    |¦  «        }|  
                    ||||¦  «         |                      |j        j        ¦  «         dS )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Ô6Ñˆ�˜à×'Ò'¨	Ñ2Ô2ˆØ×#Ò# F¨F°H¸dÑCÔCÐCð 	�Š˜Ô(Ô6Ñ7Ô7Ð7Ð7Ð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ð Gð Gð5ð 5ð 5ð7ð 7ð 7ð:ð :ð :ð0=ð =ð =ð0 ð  ð  ð8*ð *ð *ðX5ð 5ð 5ð< 9ð  9ð  9ðDFð Fð Fð,&7ð &7ð &7ðP(ð (ð (ð"#8ð #8ð #8ðJ.8ð .8ð .8ð`1ð 1ð 1ð>8ð 8ð 8ðB1Cð 1Cð 1Cðf8ð 8ð 8ð 8ð 8rJ   r/  c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚExistingConnectionTestsze
    Tests for L{SSHCommandClientEndpoint} when using the C{existingConnection}
    constructor.
    c                 óô  — t                                | ¦  «         t          t          |                      ¦   «         ¦  «        ¦  «        }|                     | j        | j        j        d         ¦  «         |                     t          | j
        j        ¦  «        | j        j        d         ¦  «         t          j        | j        d| j        | j        | j        | j        |t%          d¦  «        ¬¦  «        | _        dS )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Ô6Ð6å#¥H¨T¯[ª[©]¬]Ñ$;Ô$;Ñ<Ô<ˆ
Ø×Ò˜dœm¨T¬\Ô-DÀZÔ-PÑQÔQÐQØ×ÒÝ˜$Ô,Ô1Ñ2Ô2°D´LÔ4KÈJÔ4Wñ	
ô 	
ð 	
õ 1Ô>ØŒLØØŒIØŒMØŒIØ”]Ø!Ý˜uÑ%Ô%ð	
ñ 	
ô 	
ˆŒˆˆrJ   c                 óÐ  — t          ¦   «         }t          |_        | j                             |¦  «        }| j        j                             ¦   «         }	 t          | j        j        d<   |  	                    | j
        | j        j        d         d         ¦  «        \  }}}| j        j                             ¦   «          | j        j                             |¦  «         nB# | j        j                             ¦   «          | j        j                             |¦  «         w xY w|| _        || _        || _        |                      |¦  «        }|j        j        }t+          j        |d¦  «        S )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;  s<  € õ
 ‘)”)ˆÝ#ˆÔØ”M×)Ò)¨'Ñ2Ô2ˆ	ð œ
Ô0×5Ò5Ñ7Ô7ˆð		;Ý3EˆDŒJÔ$ ZÑ0à#'×#@Ò#@Ø”˜dœlÔ5°aÔ8¸Ô;ñ$ô $Ñ ˆF�F˜Dð
 ŒJÔ$×*Ò*Ñ,Ô,Ð,ØŒJÔ$×+Ò+¨MÑ:Ô:Ð:Ð:øð ŒJÔ$×*Ò*Ñ,Ô,Ð,ØŒJÔ$×+Ò+¨MÑ:Ô:Ð:Ð:øøøàˆŒØˆŒØˆŒ
à×'Ò'¨	Ñ2Ô2ˆØÔ'Ô,ˆ
Ý'Ô:¸:À}ÑUÔUÐUs   ÁA	C Ã?Dc                 óò   — | 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  s_   € ð 	Œ
�ŠÑÔÐØŒ
�ŠÑÔÐØŒ
�ŠÑÔÐØŒ
�ŠÑÔÐØŒ|˜Tœ\¨4¬:Ð5Ð5rJ   c                 ó‚   — |                       |j        j        ¦  «         |                       |j        j        ¦  «         dS )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  s>   € ð 	×Ò˜Ô)Ô7Ñ8Ô8Ð8Ø×Ò˜Ô)Ô1Ñ2Ô2Ð2Ð2Ð2rJ   N)rK   rL   rM   rN   r±   r¶   r½   r»   rO   rJ   rH   r—  r—    s]   € € € € € ðð ð

ð 
ð 
ð0Vð Vð Vð<6ð 6ð 6ð3ð 3ð 3ð 3ð 3rJ   r—  c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚExistingConnectionHelperTestsz1
    Tests for L{_ExistingConnectionHelper}.
    c                 ó`   — |                       t          t          t          ¦  «        ¦  «         dS )zT
        L{_ExistingConnectionHelper} implements L{_ISSHConnectionCreator}.
        N)rD  r   r1   r0   rF   s    rH   rJ  z,ExistingConnectionHelperTests.test_interfacew  s(   € ð 	�Š�Õ$:Õ<UÑVÔVÑWÔWÐWÐWÐWrJ   c                 ó¶   — t          ¦   «         }t          |¦  «        }|                      ||                      |                     ¦   «         ¦  «        ¦  «         dS )z¸
        L{_ExistingConnectionHelper.secureConnection} returns a L{Deferred}
        which fires with whatever object was fed to
        L{_ExistingConnectionHelper.__init__}.
        N)Úobjectr0   ÚassertIsræ   ÚsecureConnection)rG   rv   Úhelpers      rH   Útest_secureConnectionz3ExistingConnectionHelperTests.test_secureConnection}  sN   € õ ‘”ˆÝ*¨6Ñ2Ô2ˆØ�Š�f˜d×2Ò2°6×3JÒ3JÑ3LÔ3LÑMÔMÑNÔNÐNÐNÐNrJ   c                 ó€   — t          t          ¦   «         ¦  «        }|                     t          ¦   «         d¦  «         dS )z�
        L{_ExistingConnectionHelper.cleanupConnection} does nothing to the
        existing connection if called with C{immediate} set to C{False}.
        FN©r0   r©  ÚcleanupConnection©rG   r¬  s     rH   Ú$test_cleanupConnectionNotImmediatelyzBExistingConnectionHelperTests.test_cleanupConnectionNotImmediately‡  s7   € õ
 +­6©8¬8Ñ4Ô4ˆð 	× Ò ¥¡¤¨5Ñ1Ô1Ð1Ð1Ð1rJ   c                 ó€   — t          t          ¦   «         ¦  «        }|                     t          ¦   «         d¦  «         dS )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’  s7   € õ
 +­6©8¬8Ñ4Ô4ˆð 	× Ò ¥¡¤¨4Ñ0Ô0Ð0Ð0Ð0rJ   N)rK   rL   rM   rN   rJ  r­  r²  r´  rO   rJ   rH   r¦  r¦  r  s`   € € € € € ðð ðXð Xð XðOð Oð Oð	2ð 	2ð 	2ð	1ð 	1ð 	1ð 	1ð 	1rJ   r¦  c                   ó   — e Zd Zdedefd„ZdS )Ú_WriteDiscarderrT   Úreturnc                ó   — dS )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.
        r   rO   rS   s     rH   rñ   z_WriteDiscarder.writeŸ  s	   € ð
 ˆqrJ   N)rK   rL   rM   r©  Úintrñ   rO   rJ   rH   r¶  r¶  ž  s6   € € € € € ð˜&ð ¨ð ð ð ð ð ð rJ   r¶  c                   ó>   — e Zd ZdZdeddfd„Zdedee         fd„ZdS )Ú_PTYPathzk
    A L{FilePath}-like object which can be opened to create a L{_ReadFile} with
    certain contents.
    Úcontentsr·  Nc                 ó   — || _         dS )zz
        @param contents: L{bytes} which will be the contents of the
            L{_ReadFile} this path can open.
        N)r¼  )rG   r¼  s     rH   re   z_PTYPath.__init__­  s   € ð
 !ˆŒˆˆrJ   Úmodec                 ó:   — |dk    sJ ‚t          | j        ¦  «        S )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¼  )rG   r¾  s     rH   Úopenz_PTYPath.open´  s!   € ð �tŠ|ˆ|ˆ|ˆ|Ý˜tœ}Ñ-Ô-Ð-rJ   )	rK   rL   rM   rN   Úbytesre   Ústrr   rÀ  rO   rJ   rH   r»  r»  §  sf   € € € € € ðð ð
! ð !¨4ð !ð !ð !ð !ð.˜ð .  E¤ð .ð .ð .ð .ð .ð .rJ   r»  c                   óN   — 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S )ÚNewConnectionHelperTestsz,
    Tests for L{_NewConnectionHelper}.
    c                 ó`   — |                       t          t          t          ¦  «        ¦  «         dS )zO
        L{_NewConnectionHelper} implements L{_ISSHConnectionCreator}.
        N)rD  r   r1   r2   rF   s    rH   rJ  z'NewConnectionHelperTests.test_interfaceÄ  s(   € ð 	�Š�Õ$:Õ<PÑQÔQÑRÔRÐRÐRÐRrJ   c                 óF   — |                       dt          j        ¦  «         dS )zK
        The default I{known_hosts} path is I{~/.ssh/known_hosts}.
        z~/.ssh/known_hostsN)rÎ   r2   Ú_KNOWN_HOSTSrF   s    rH   Útest_defaultPathz)NewConnectionHelperTests.test_defaultPathÊ  s%   € ð 	×ÒÐ-Õ/CÔ/PÑQÔQÐQÐQÐQrJ   c                 óÈ   ‡— t          ¦   «         Š|                      t          dˆfd„¦  «         t          dddddddddd¦
  «
        }|                      ‰|j        ¦  «         dS )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©  Úpatchr2   rª  r4  )rG   r¬  rv   s     @rH   Útest_defaultKnownHostsz/NewConnectionHelperTests.test_defaultKnownHostsÐ  sr   ø€ õ
 ‘”ˆØ�
Š
Õ'¨Ð8JÐ8JÐ8JÐ8JÑKÔKÐKå%Ø�$˜˜d D¨$°°d¸DÀ$ñ
ô 
ˆð 	�Š�f˜fÔ/Ñ0Ô0Ð0Ð0Ð0rJ   c                 ób  — t          ¦   «         j        d         }t          |                      ¦   «         ¦  «        }t	          |¦  «        }|                     d|¦  «         |                     ¦   «          t          d|j        ›�¦  «         t          j         
                    d¦  «        }|j                             |d¦  «        }|                      t          d|¦  «         t          d|›�¦  «         t          j        ¦   «         }|                      |                     d|¦  «        ¦  «         dS )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Í  r2   rÊ  rD  Ú
hasHostKey)rG   r‡  rÐ  r4  ÚhomeÚdefaultÚloadeds          rH   Útest_readExistingz*NewConnectionHelperTests.test_readExistingÞ  s
  € õ ÑÔÔ)¨*Ô5ˆÝ˜Ÿš™œÑ&Ô&ˆÝ# DÑ)Ô)ˆ
Ø×Ò˜l¨CÑ0Ô0Ð0Ø�ŠÑÔÐåÐ8¨4¬9Ð8Ð8Ñ9Ô9Ð9õ Œw×!Ò! $Ñ'Ô'ˆØ”)×#Ò# D¨$Ñ/Ô/ˆØ�
Š
Õ'¨¸ÑAÔAÐAÝÐ4¨Ð4Ð4Ñ5Ô5Ð5å%Ô1Ñ3Ô3ˆØ�Š˜×)Ò)¨,¸Ñ<Ô<Ñ=Ô=Ð=Ð=Ð=rJ   c                 óv   — t          dddddddddd¦
  «
        }|                      |j        t          ¦  «         dS )zz
        If L{None} is passed for the C{ui} parameter to
        L{_NewConnectionHelper}, a L{ConsoleUI} is used.
        N)r2   rà   r:  r+   r±  s     rH   Útest_defaultConsoleUIz.NewConnectionHelperTests.test_defaultConsoleUIõ  sH   € õ
 &Ø�$˜˜d D¨$°°d¸DÀ$ñ
ô 
ˆð 	×Ò˜fœi­Ñ3Ô3Ð3Ð3Ð3rJ   c                 óÚ   — t          d¦  «        }t          dddddddddd|¦  «        }|                      |j                             d¦  «        ¦  «        }|                      |¦  «         dS )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»  r2   ræ   r:  rz   rD  ©rG   Úttyr¬  rv   s       rH   Útest_ttyConsoleUIz*NewConnectionHelperTests.test_ttyConsoleUIÿ  su   € õ �vÑÔˆÝ%Ø�$˜˜d D¨$°°d¸DÀ$Èñ
ô 
ˆð ×%Ò% f¤i×&6Ò&6Ð7IÑ&JÔ&JÑKÔKˆØ�Š˜ÑÔÐÐÐrJ   c                 óþ   — t          |                      ¦   «         ¦  «        }t          dddddddddd|¦  «        }|                      |j                             d¦  «        ¦  «        }|                      |¦  «         dS )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  r2   ræ   r:  rz   r¤  rÜ  s       rH   Útest_nottyUIz%NewConnectionHelperTests.test_nottyUI  s   € õ �t—{’{‘}”}Ñ%Ô%ˆÝ%Ø�$˜˜d D¨$°°d¸DÀ$Èñ
ô 
ˆð ×%Ò% f¤i×&6Ò&6Ð7IÑ&JÔ&JÑKÔKˆØ×Ò˜Ñ Ô Ð Ð Ð rJ   c                 ó†   — t          dddddddddd¦
  «
        }|                      t          d¦  «        |j        ¦  «         dS )zy
        If not passed the name of a tty in the filesystem,
        L{_NewConnectionHelper} uses C{b"/dev/tty"}.
        Ns   /dev/tty)r2   rÎ   r#   rÝ  r±  s     rH   Útest_defaultTTYFilenamez0NewConnectionHelperTests.test_defaultTTYFilename  sP   € õ
 &Ø�$˜˜d D¨$°°d¸DÀ$ñ
ô 
ˆð 	×Ò� +Ñ.Ô.°´
Ñ;Ô;Ð;Ð;Ð;rJ   c                 óâ   — t          dddddddddd¦
  «
        }t          ¦   «         }t          ¦   «         |_        |                     |d¦  «         |                      |j        j        ¦  «         dS )z�
        L{_NewConnectionHelper.cleanupConnection} closes the transport cleanly
        if called with C{immediate} set to C{False}.
        NF)r2   r6   r   r€   r°  rD  rE  )rG   r¬  r¡  s      rH   r²  z=NewConnectionHelperTests.test_cleanupConnectionNotImmediately#  su   € õ
 &Ø�$˜˜d D¨$°°d¸DÀ$ñ
ô 
ˆõ #‘_”_ˆ
Ý.Ñ0Ô0ˆ
ÔØ× Ò  ¨UÑ3Ô3Ð3Ø�Š˜
Ô,Ô:Ñ;Ô;Ð;Ð;Ð;rJ   c                 ó.  —  G d„ d¦  «        }t          dddddddddd¦
  «
        }t          ¦   «         }t          ¦   «         |_         |¦   «         |j        _        |                     |d¦  «         |                      |j        j        j        ¦  «         dS )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dS )úMNewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.AbortableFc                 ó   — d| _         dS )z7
                Abort the connection.
                TNrD   rF   s    rH   rI   z]NewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.Abortable.abortConnection9  s   € ð  $�”��rJ   N)rK   rL   rM   rE   rI   rO   rJ   rH   Ú	Abortableræ  6  s(   € € € € € ØˆGð$ð $ð $ð $ð $rJ   rè  NT)r2   r6   r9   r€   r°  rD  rE   )rG   rè  r¬  r¡  s       rH   r´  z:NewConnectionHelperTests.test_cleanupConnectionImmediately0  s±   € ð	$ð 	$ð 	$ð 	$ð 	$ñ 	$ô 	$ð 	$õ &Ø�$˜˜d D¨$°°d¸DÀ$ñ
ô 
ˆõ #‘_”_ˆ
Ý1Ñ3Ô3ˆ
ÔØ)2¨©¬ˆ
ÔÔ&Ø× Ò  ¨TÑ2Ô2Ð2Ø�Š˜
Ô,Ô6Ô>Ñ?Ô?Ð?Ð?Ð?rJ   N)rK   rL   rM   rN   rJ  rÈ  rÎ  rØ  rÚ  rÞ  rà  râ  r²  r´  rO   rJ   rH   rÄ  rÄ  ¿  s¿   € € € € € ðð ðSð Sð SðRð Rð Rð1ð 1ð 1ð>ð >ð >ð.4ð 4ð 4ð ð  ð  ð!ð !ð !ð<ð <ð <ð<ð <ð <ð@ð @ð @ð @ð @rJ   rÄ  )yrN   Ú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/   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»  rÄ  rO   rJ   rH   ú<module>r     sZ  ððð ð €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à &Ð &Ð &Ð &Ð &Ð &Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;à €€€à KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KØ /Ð /Ð /Ð /Ð /Ð /Ø IÐ IÐ IÐ IÐ IÐ IØ &Ð &Ð &Ð &Ð &Ð &Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ Jðð ð ð ð ð ð ð ð ð ð ð ð HÐ GÐ GÐ GÐ GÐ GÐ GÐ GØ 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7ðð ð ð ð ð ð ð ð ð ð
 8Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø /Ð /Ð /Ð /Ð /Ð /Ø *Ð *Ð *Ð *Ð *Ð *Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø "Ð "Ð "Ð "Ð "Ð "Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø +Ð +Ð +Ð +Ð +Ð +à€=�Ñ Ô ð $Ø.Ð.Ð.Ð.Ð.Ð.ØLÐLÐLÐLÐLÐLÐLÐLØIÐIÐIÐIÐIÐIÐIÐIðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð )Ð(Ð(Ð(Ð(Ð(Ø6Ð6Ð6Ð6Ð6Ð6Ø4Ð4Ð4Ð4Ð4Ð4Ø:Ð:Ð:Ð:Ð:Ð:Ø4Ð4Ð4Ð4Ð4Ð4Ø*Ð*Ð*Ð*Ð*Ð*Ø>Ð>Ð>Ð>Ð>Ð>Ø<Ð<Ð<Ð<Ð<Ð<ðð ð ð ð ð ð ð ð ð ð ð ð ð (€DØ€JØÐØ€MØ
€CØ€JØ€NØ€NØ ÐØ€Ià 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5ðð ð ð ð ˜]ñ ô ð ð ð ð ð ð ˜
ñ ô ð ð$ð ð ð ð ˜ñ ô ð ð$ð ð ð ð ˜Zñ ô ð ð&2ð 2ð 2ð 2ð 2ñ 2ô 2ð 2ð4ð 4ð 4ð 4ð 4˜ñ 4ô 4ð 4ðð ð ð ð ñ ô ð ð.ð .ð .ð .ð .Ð!2ñ .ô .ð .ð(!ð !ð !ð !ð !�Zñ !ô !ð !ð* €ˆXÑÔð	ð 	ð 	ð 	ð 	ñ 	ô 	ñ Ôð	ð €Ð"Ñ#Ô#ð#%ð #%ð #%ð #%ð #%ñ #%ô #%ñ $Ô#ð#%ðLkBð kBð kBð kBð kBñ kBô kBð kBð\]	8ð ]	8ð ]	8ð ]	8ð ]	8˜Ð#Eñ ]	8ô ]	8ð ]	8ð@R3ð R3ð R3ð R3ð R3˜hÐ(Jñ R3ô R3ð R3ðj)1ð )1ð )1ð )1ð )1 Hñ )1ô )1ð )1ðXð ð ð ð �gñ ô ð ð.ð .ð .ð .ð .ñ .ô .ð .ð0G@ð G@ð G@ð G@ð G@˜xñ G@ô G@ð G@ð G@ð G@rJ   