%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/conch/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/conch/test/__pycache__/test_endpoints.cpython-312.pyc

�

Ϫ�f����dZddlZddlmZddlmZddlmZddl	m
Z
mZddlZddl
mZmZmZddlmZdd	lmZdd
lmZddlmZddlmZmZmZmZdd
lmZm Z m!Z!m"Z"ddl#m$Z$m%Z%ddl&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,ddl-m.Z.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;e9d�reddl<m=Z=ddl>m?Z?m@Z@ddlAmBZBmCZCddlDmEZEmFZFmGZGmHZHmIZImJZJmKZKddlLmMZMddlNmOZOddlPmQZQdd lRmSZSdd!lTmUZUdd"lVmWZWdd#lXmYZYdd$lZm[Z[dd%l\m]Z]m^Z^m_Z_m`Z`nd&ZaebZUebZ[ebZSebZWebZQebZOebZCebZ@ebZ=dd'lcmdZdmeZeGd(�d)ed�ZfGd*�d+eQ�ZgGd,�d-eQ�ZhGd.�d/eQ�ZiGd0�d1�ZjGd2�d3e'�ZkGd4�d5�ZlGd6�d7e[�ZmGd8�d9eU�Znee$�Gd:�d;��Zoee%�Gd<�d=��ZpGd>�d?�ZqGd@�dAe;eq�ZrGdB�dCe;eq�ZsGdD�dEe;�ZtGdF�dG�ZuGdH�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_opensshzcan't run w/o cryptography)�
FakeTransport�connectc��eZdZdZdZd�Zy)�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__rErI�rJrHrBrBVs����G�rJrBc��eZdZdZd�Zy)�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}
        rrO�rG�datas  rH�request_execzBrokenExecSession.request_execk���rJN�rKrLrMrNrUrOrJrHrQrQf����
rJrQc��eZdZdZd�Zy)�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}
        �rOrSs  rHrUzWorkingExecSession.request_exec}rVrJNrWrOrJrHrZrZxrXrJrZc��eZdZdZd�Zy)�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}
        )rrSs  rHrUz#UnsatisfiedExecSession.request_exec�s���z�rJNrWrOrJrHr^r^�s���

rJr^c��eZdZd�Zd�Zy)�TrivialRealmc��i|_y�N)�
channelLookuprFs rH�__init__zTrivialRealm.__init__�s
����rJc�L�t�}|j|_t|d�fS)Nc��yrcrOrOrJrH�<lambda>z,TrivialRealm.requestAvatar.<locals>.<lambda>�s�rJ)r'rdr)rG�avatarId�mind�
interfaces�avatars     rH�
requestAvatarzTrivialRealm.requestAvatar�s$�����#�1�1����F�L�1�1rJN)rKrLrMrermrOrJrHrara�s�� �2rJrac��eZdZdZd�Zy)�AddressSpyFactoryNc�<�||_tj||�Src)�addressr�
buildProtocol)rGrqs  rHrrzAddressSpyFactory.buildProtocol�s������$�$�T�7�3�3rJ)rKrLrMrqrrrOrJrHroro�s���G�4rJroc��eZdZd�Zd�Zd�Zy)�FixedResponseUIc��||_yrc)�result)rGrvs  rHrezFixedResponseUI.__init__�s	����rJc�,�t|j�Src)rrv�rG�texts  rH�promptzFixedResponseUI.prompt�s���t�{�{�#�#rJc��yrcrOrxs  rH�warnzFixedResponseUI.warn�s��rJN)rKrLrMrerzr|rOrJrHrtrt�s���$�
rJrtc�,�eZdZed��Zed��Zy)�FakeClockSSHUserAuthServerc�B�|jjjS)zy
        Use the C{attemptsBeforeDisconnect} value defined by the factory to make
        it easier to override.
        )�	transport�factory�attemptsBeforeDisconnectrFs rHr�z3FakeClockSSHUserAuthServer.attemptsBeforeDisconnect�s���~�~�%�%�>�>�>rJc�B�|jjjS)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��reactorrFs rH�clockz FakeClockSSHUserAuthServer.clock�s���~�~�%�%�-�-�-rJN)rKrLrM�propertyr�r�rOrJrHr~r~�s(��
�?��?��.��.rJr~c�:�eZdZed��Zed��Zeed�ZdZ	y)�CommandFactoryc�:�dtjt��iS�N�ssh-rsa)rT)r8�
fromStringr>rFs rH�
publicKeyszCommandFactory.publicKeys�s���C�N�N�0A�B�C�CrJc�:�dtjt��iSr�)r8r�r<rFs rH�privateKeyszCommandFactory.privateKeys�s���C�N�N�0B�C�D�DrJ)sssh-userauthsssh-connectionrN)
rKrLrMr�r�r�r~r6�servicesr�rOrJrHr�r��sC��
�D��D��E��E�4�(��H� !�rJr�c��eZdZy)�
MemoryAddressN)rKrLrMrOrJrHr�r��s��rJr�c��eZdZdZd�Zd�Zy)�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  rHrez SingleUseMemoryEndpoint.__init__�s����	���rJc	�&�|j�td��	|jt��}t	|j
t
|j
d��|t
|d���|_t|�S#t$r
t�cYSwxYw)Nz(SingleUseMemoryEndpoint was already usedT��isServerF)
r��	Exceptionrrr�r@r�rBr�
BaseExceptionr)rGr��protocols   rHr@zSingleUseMemoryEndpoint.connect�s����9�9� ��F�G�G�	%��,�,�]�_�=�H� ����&�t�|�|�d�C��&�x�%�@�	�D�I��8�$�$���	��6�M�	�s�A:�:B�BN)rKrLrMrNrer@rOrJrHr�r��s����%rJr�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zy)�"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�|_|jj|j|j�|jj|j�t�|_|j
|j_|j|j_	|jj!�|j#|jj$�t'ddd�|_t'ddd	�|_y)
Nsssh.example.comi&�suserspassword�TCPz10.0.0.1i90z192.168.100.200i1�)�hostname�port�user�passwordrr�ra�realmr
�portalr�passwdDB�addUser�registerCheckerr�r��doStart�
addCleanup�doStopr�
clientAddress�
serverAddressrFs rH�setUpz(SSHCommandClientEndpointTestsMixin.setUps���*��
���	���	�#��
�)�+���!�^��
��T�Z�Z�(���?�A��
��
�
���d�i�i����7����#�#�D�M�M�2�%�'���#�|�|�����"�k�k�����������������+�+�,�(��
�E�B���(��0A�5�I��rJc�F�t|jj�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__rKrFs rH�createz)SSHCommandClientEndpointTestsMixin.create1s'��
"��~�~�&�&�)�)B�C�
�	
rJc�F�t|jj�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#��"��~�~�&�&�
)�
�	
rJc�F�t|jj�d���)z�
        Do any remaining work necessary to complete an in-memory connection
        attempted initiated using C{self.reactor}.
        z# did not implement finishConnectionr�rFs rH�finishConnectionz3SSHCommandClientEndpointTestsMixin.finishConnectionJs'��
"��~�~�&�&�)�)L�M�
�	
rJc��|jd�}|jd�}t|d|j|j��}t|d|j|j��}t	||||�}|||fS)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)rrrBr�r�r@)rG�
serverFactory�
clientFactory�clientProtocol�serverProtocol�clientTransport�serverTransportr�s        rH�connectedServerAndClientz;SSHCommandClientEndpointTestsMixin.connectedServerAndClientSs���'�4�4�T�:��&�4�4�T�:��0����*�*��*�*�	
��1����*�*��*�*�	
���~����X���~�t�3�3rJc�8�|j�}t�}t|_|j	|�}|j�\}}}|j
t�}|jd|djj|djjf�|jdt|��|j|�}|jt�|jd|jj�|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 channelrr\�unknown channelFN)r�rrr�r@r��flushLoggedErrorsr�assertIn�valuerT�assertEqual�len�failureResultOf�trapr�)	rG�endpointr��	connectedr�r�r��errors�fs	         rH�test_channelOpenFailurez:SSHCommandClientEndpointTestsMixin.test_channelOpenFailureps����;�;�=���)��#����$�$�W�-�	�#�4�4�6������'�'�
�3���
�
�'�&��)�/�/�*>�*>��q�	���@U�@U�)V�W�����C��K�(�
� � ��+��	���z�����+�Q�W�W�]�]�;��'�'���6rJc��t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j|�}|jt�|jd|jj�|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.
        �sessionzchannel request failedFN)rQr�rdr�rrr�r@r�r�r�rr�r�r��rGr�r�r�r�r�r�r�s        rH�test_execFailurez3SSHCommandClientEndpointTestsMixin.test_execFailure�s���0A��
�
� � ��,��;�;�=���)��#����$�$�W�-�	�#�4�4�6������ � ��+��	���z�����1�1�7�7�=�=�A��'�'���6rJc�b�t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j�|j|�}|jt�|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�rdr�rrr�r@r��cancelr�r�rr�r�s        rH�test_execCancelledz5SSHCommandClientEndpointTestsMixin.test_execCancelled�s���0F��
�
� � ��,��;�;�=���)��#����$�$�W�-�	�#�4�4�6���������� � ��+��	���~���'�'���5rJc�:�t|jjd<|j�}t	�}t
|_|j|�|j�\}}}|j|jt�|j|jj�|jj�|j|j |jj"�|jd|jj$�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)rZr�rdr�rorr�r@r��assertIsInstancerqr-r�r��getHostr�r��username�command)rGr�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�$<�$<�=��������(?�(?�@rJc�*�t|jjd<|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)rZr�rdr�rrr�r@r��successResultOf�assertIsNotNoner��rGr�r�r�r�r�r�r�s        rH�test_makeConnectionz6SSHCommandClientEndpointTestsMixin.test_makeConnection�s|��0B��
�
� � ��,��;�;�=���)��#����$�$�W�-�	�#�4�4�6������'�'�	�2�����X�/�/�0rJc��t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j|�}g}|j|_|jj}	|jj|	j!d�|j#�|j%ddj'|��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, worldrJN)rZr�rdr�rrr�r@r�r��append�dataReceivedr��id�service�channels�writer�r��join)
rGr�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��	�	������#�(�(�<�*@�ArJc��t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j|�}g}|j|_|jj}	|jj|	j!�|j#�|dj%t&�|j)|d�y)zq
        When the command closes the channel, the protocol's C{connectionLost}
        method is called.
        r�rFN)rZr�rdr�rrr�r@r�r�r��connectionLostr�r�r�r��loseConnectionr�r�rr�)
rGr�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����~�.��'�'���6rJc��t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j|�}	g}
|
j|	_|	jj}|jj|}|jj!|||�|j#�|j%�|j'|d�|
dS)zJ
        Test handling of non-zero exit statuses or exit signals.
        r�Fr)rZr�rdr�rrr�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._exitStatusTests���0B��
�
� � ��,��;�;�=���)��#����$�$�W�-�	�#�4�4�6������'�'�	�2����"0�"7�"7���
�&�&�)�)�	��.�.�)�)�)�4�����"�"�7�G�Z�@���� ��	�	���'�'���6��a� � rJc�j�d}|jdtd|��}|jt�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�rr�r)rG�exitCode�excs   rH�test_zeroExitCodez4SSHCommandClientEndpointTestsMixin.test_zeroExitCode2s.�����"�"�>�4��h�3G�H������ rJc��d}d}|jdtd|��}|jt�|j	||j
j�|j	||j
j�y)r�{Nrr)r�rr�rr�r�r�signal)rGrrrs    rH�test_nonZeroExitStatusz9SSHCommandClientEndpointTestsMixin.test_nonZeroExitStatus<sh�������"�"�>�4��h�3G�H�����"�#�����3�9�9�#5�#5�6��������!1�!1�2rJc���t�}tj|�|jtj|�d}d}djt
jd�dt
jd�t
jd�g�}|jd|�}|jt�|j||jj�|j||jj�d	}tj |tj"tj$tj&t(j*�|dd
ddd����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�rJsTERM�smessagesen-USsexit-signalz'twisted.conch.endpoints._CommandChannelT�message)�	log_level�
log_namespace�shortSignalName�
coreDumped�errorMessage�languageTag)rr�addObserverr��removeObserverr�r3�NSr�r�rr�r�rr�hamcrest�assert_that�has_item�has_entries�equal_tor�info)rG�logObserverrr�packetr�logNamespaces       rH�test_nonZeroExitSignalz9SSHCommandClientEndpointTestsMixin.test_nonZeroExitSignalIs ��+�,���&�&�{�3����*�9�9�;�G���������	�	�'�"���	�	�*�%��	�	�(�#�
�
���"�"�>�6�:�����"�#�����3�9�9�#5�#5�6��������!1�!1�2�@����������$�$�%-�%6�%6�x�}�}�%E�)5�+2�&*�(1�'/�
�	�
�	
rJc���|jj}g�|r�fd�}n�j}t|jj
|||��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�&���jd�Src)r�)�recorders�rHrhz;SSHCommandClientEndpointTestsMixin.record.<locals>.<lambda>�s�������-�rJ)r�r�r��setattrr�r�)rGr�r��event�noArgsr�r�r#s       @rH�recordz)SSHCommandClientEndpointTestsMixin.recordwsL��� �&�&�)�)�	����-�A����A�����'�'�	�2�E�1�=��rJc��t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j|�}|j||d�}|jjd�|j�|jddj|��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�rJN)rZr�rdr�rrr�r@r�r�r'r�r�r�r�r��	rGr�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��	�	������#�(�(�<�*@�ArJc��t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j|�}|j||d�}|jjdg�|j�|jddj|��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�rJN)rZr�rdr�rrr�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�����(�(�/�):�;��	�	������#�(�(�<�*@�ArJN)F)rKrLrMrNr�r�r�r�r�r�r�r�r�r�r�r�r�rr	r r'r*r-rOrJrHr�r�sl���J�(
�
� 
�4�:7�47�*6�*A�.1�&B�67�8!�:!�3�,
�\�6B�*BrJr�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�NewConnectionTestsz`
    Tests for L{SSHCommandClientEndpoint} when using the C{newConnection}
    constructor.
    c���tj|�t|j��|_t|j�|_|jj|j|jjd�|jjt|jj�|jjd�|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�saverFs rHr�zNewConnectionTests.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�	
�	
�����rJc���tj|jd|j|j|j
|j|jtd���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�r4rtrFs rHr�zNewConnectionTests.create�sL��
(�5�5��L�L���I�I��M�M��I�I��]�]�����u�%�	
�		
rJc�n�|j|j|jjdd�S)z}
        Establish the first attempted TCP connection using the SSH server which
        C{self.factory} can create.
        r�)r�r�r��
tcpClientsrFs rHr�z#NewConnectionTests.finishConnection�s4��
�,�,��L�L�$�,�,�1�1�!�4�Q�7�
�	
rJc��|j||dd��}|jj�|j�|j	dg|�|j�|jj�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)rGr�r�r�r�r@s      rH�loseConnectionToServerz)NewConnectionTests.loseConnectionToServer�sf��*���V�X�x���E�����)�)�+��	�	�����$���(�
	
�	�	��	���)�)�+rJc��|r&|j|jj�y|j|jj�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   rHr�z-NewConnectionTests.assertClientTransportStates7����O�O�F�,�,�4�4�5��O�O�F�,�,�:�:�;rJc��tj|jdd|j|j�}|jt
t|��y)zY
        L{SSHCommandClientEndpoint} instances provide L{IStreamClientEndpoint}.
        �
dummy command�
dummy userN)r.r;r�r�r�rDrr�rGr�s  rH�test_interfacez!NewConnectionTests.test_interfacesB��,�9�9��L�L�*�M�4�=�=�$�)�)�
��	
����%:�H�E�FrJc��tj|jdd|j�}|j	d|j
j�y)z�
        L{SSHCommandClientEndpoint} uses the default port number for SSH when
        the C{port} argument is not specified.
        rGrH�N�r.r;r�r�r��_creatorr�rIs  rH�test_defaultPortz#NewConnectionTests.test_defaultPort$sD��
,�9�9��L�L�*�M�4�=�=�
��	
����X�.�.�3�3�4rJc��tj|jdd|jd��}|j	d|j
j�y)zU
        L{SSHCommandClientEndpoint} uses the C{port} argument if specified.
        rGrHi�)r�NrMrIs  rH�test_specifiedPortz%NewConnectionTests.test_specifiedPort.sF��,�9�9��L�L�*�M�4�=�=�t�
��	
����x�0�0�5�5�6rJc�2�tj|jd|j|j|j
|j|jtd���}t�}t|_|j|�|jjd\}}}}}|j|jt|��|j|j
|�|jdt!|jj��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�Fr9rr\N)r.r;r�r�r�r�r�r4rtrrr�r@r>r�r r�)rGr�r�r6r��timeout�bindAddresss       rH�test_destinationz#NewConnectionTests.test_destination7s���
,�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�9rJc��tj|jdd|j|j|j
t
d���}t�}t|_	|j|�}|jjdd}|jdtt���|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�rHF�r4r:rr=N)r.r;r�r�r�r4rtrrr�r@r>�clientConnectionFailedr!rr�r��rGr�r��ds    rH�test_connectionFailedz(NewConnectionTests.test_connectionFailedOs���,�9�9��L�L����M�M��I�I�����u�%�
���)��#������W�%���,�,�)�)�!�,�Q�/���&�&�t�W�5K�5M�-N�O����Q��$�$�%;�<rJc���tj|jdd|j|jt|j
��td���}t�}t|_
|j|�}|j|j|jjdd�\}}}|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�rHFrWrr=N)r.r;r�r�r�r+r2rtrrr�r@r�r�r>r�r�r
r�s        rH�test_userRejectedHostKeyz+NewConnectionTests.test_userRejectedHostKeygs���,�9�9��L�L����M�M��I�I�%�d�k�k�m�4��u�%�
���)��#����$�$�W�-�	�#�<�<��L�L�$�,�,�1�1�!�4�Q�7� 
�����
� � ��+��	����rJc
��tjt�j�}t	t|j
���}|jt|jj�|�tjtd��j�}|j|j|�td�}tj|j dd|j|j"d||��}t%�}t&|_|j+|�}|j-|j.|j j0dd	�\}}	}
|j3|�}|j5t6�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}.
        stestxp)�
passphraseTr�rH�dummy passwordr9rr=N)r8r�r<�publicr+r"r2r5r r�r6r=r�rtr.r;r�r�rrr�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� 
�����
� � ��+��	���~�rJc��tj|jdd|j|j|j
t
d���}t�}t|_	|j|�}t�}|jjdd}|jd�}|j|�|jt!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�rHFrWrr=N)r.r;r�r�r�r4rtrrr�r@rr>rr�makeConnectionr�r!rr�r��rGr�r�rZr�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��$�$�^�4rJc�b�tj|jdd|j|j|j
t
d���}t�}t|_	|j|�}tdd��}|jjdd}|jd�}|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�rHFrWNr�rr=)r.r;r�r�r�r4rtrrr�r@rBr>rrrfr�r�r�rrDrEr�r!rrgs      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�8rJc��tj|jdd|j|j|j
t
d���}t�}t|_	|j|�}|j�|j|�jt�|j|jj dj"�y)zz
        If the connection is cancelled before it finishes connecting, the
        connection attempt is stopped.
        r�rHFrWrN)r.r;r�r�r�r4rtrrr�r@r�r�r�rrD�
connectors�stoppedConnectingrYs    rH�'test_connectionCancelledBeforeConnectedz:NewConnectionTests.test_connectionCancelledBeforeConnected�s���
,�9�9��L�L����M�M��I�I�����u�%�
���)��#������W�%��	���
����Q��$�$�%=�>�������/�/��2�D�D�ErJc�N�tj|jdd|j|jd|j
t
d���}t�}t|_	|j|�}|j|j|jjdd�\}}}|jj|jj �|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�rHr`Fr9rr=N)r.r;r�r�r�r4rtrrr�r@r�r�r>�advancer��
passwordDelay�flushr�r�r,r�r�s        rH�"test_passwordAuthenticationFailurez5NewConnectionTests.test_passwordAuthenticationFailures���,�9�9��L�L����M�M��I�I�&�����u�%�	
���)��#����$�$�W�-�	�#�<�<��L�L�$�,�,�1�1�!�4�Q�7� 
�����	
�����V�^�^�9�9�:�	
�
�
��� � ��+��	���#�$�	
�'�'���6rJc���|j�D��cic]*\}}|tj|�j�g��,}}}t	t|��}|j
|�ycc}}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)�itemsr8r�rar)r(r�)rGr��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�'��Ns�/A,c��tjt�}|j|j|j
ti�tj|jd|j
|j|j|g|jtd���}t�}t|_|j#|�}|j%|j&|jj(dd�\}}}|j+|�}|j-t.�|j1|j2j4�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��keysr4r:rr=N)r8r�r<r{r�r�r;r.r;r�r�r�r4rtrrr�r@r�r�r>r�r�r,rDr�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�7rJc
�:�tjt�}|j|j|j
ti�tj|jd|j
|j|j|g|j|jtd���	}t�}t |_|j%|�}|j&xj(dz
c_|j+|j&|jj,dd�\}}}|j/�|j1t2�}|j5d|dj6j8|dj6j6f�|j;dt=|��|j?|�}	|	jAt2�|j;d|	j6j6�|jC|jDjF�y	)
z{
        If the SSH server does not accept any of the specified SSH keys, the
        specified password is tried.
        r�F)r~r�r4r:r\rr=r�r�N)$r8r�r<r{r�r�r;r.r;r�r�r�r�r4rtrrr�r@r�r�r�r>r�r�rr�r�rTr�r�r�r�rDr�rE)
rGrr�r�r�r�r�r�r�r�s
          rH�test_authenticationFallbackz.NewConnectionTests.test_authenticationFallbackcs���
��� 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�7rJc��tjt�}|j|j|j
ti�t|jjd<tj|jd|j
|j|j|g|jtd���}t!�}t"|_|j'|�}|j)|j*|jj,dd�\}}}|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}rr=N)r8r�r;r{r�r�rZr�rdr.r;r�r�r�r4rtrrr�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�/�/�0rJc�(�tj|jd|j|j|j
|jtd���}t�}t|_
|j|�}|j|j|jjdd�\}}}|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�FrWrr=N)r.r;r�r�r�r�r4rtrrr�r@r�r�r>r�r�r�r,rDr�rEr�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�7rJc�b�tjt�}t�}t	�|_|j
�|dfi|j
_|j|j|jti�t|�}tj|jd|j|j|j |j"t%d�|��}t&|j(j*d<t	�}t,|_|j1|�}|j3|j
|jj4dd�\}}}	t7d�D],}
|j8j9�|	j9��.|j;|�}|j=|j>�|jA||||	�|jC|j>jD�|jC|j8jFjD�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.
        rJr�F)r4r:�
agentEndpointr�rr=�N)$r8r�r<r4rr��blobr~r{r�r�r�r.r;r�r�r�r4rtrZr�rdrr�r@r�r>�ranger�r�r�r�rBrDrE�clientIO)rGr��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�BrJc�f�t|jjd<|j�}t	�}t
|_|j|�}|j�\}}}|j|�}|j||||�|j|jj�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)rZr�rdr�rrr�r@r�r�rBrDr�rEr�s        rH�test_loseConnectionz&NewConnectionTests.test_loseConnections���0B��
�
� � ��,��;�;�=���)��#����$�$�W�-�	�#�4�4�6������'�'�	�2���#�#�F�F�H�d�C�	
����(�(�6�6�7rJN)rKrLrMrNr�r�r�rBr�rJrOrQrUr[r]rdrhrjrnrsr{r�r�r�r�r�r�rOrJrHr/r/�s����

�
� 
�!,�F<�G�5�7�:�0=�0 �8*�X5�< 9�DF�,&7�P(�"#8�J.8�`1�>8�B1C�f8rJr/c�(�eZdZdZd�Zd�Zd�Zd�Zy)�ExistingConnectionTestsze
    Tests for L{SSHCommandClientEndpoint} when using the C{existingConnection}
    constructor.
    c��tj|�tt|j	���}|j|j|jjd�|jt|jj�|jjd�tj|jd|j|j|j |j"|t%d���|_y)r1r�r�Fr9N)r�r�r+r"r2r5r�r�r�r r�r6r.r;r�r�r�r�rtr�)rGr4s  rHr�zExistingConnectionTests.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�%�	
��
rJc�,�t�}t|_|jj	|�}|j
jj�}	t|j
jd<|j|j|jjdd�\}}}|j
jj�|j
jj|�||_||_||_|j%|�}|j&j(}t+j,|d�S#|j
jj�|j
jj|�wxYw)zz
        Create and return a new L{SSHCommandClientEndpoint} using the
        C{existingConnection} constructor.
        r�rr=r�)rrr�r�r@r�rd�copyrZr�r�r�r>�clear�updater��_client�_pumpr�r��connr.�existingConnection)	rGr�r�rdr�r�r�r��
connections	         rHr�zExistingConnectionTests.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�AE�AFc��|jj�|jj�|jj�|jj�|j|j|jfS)z�
        Give back the connection established in L{create} over which the new
        command channel being tested will exchange data.
        )r�r�r�r�rFs rHr�z(ExistingConnectionTests.finishConnectionYsU��	
�
�
�����
�
�����
�
�����
�
�����|�|�T�\�\�4�:�:�5�5rJc��|j|jj�|j|jj�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�rErEr�s   rHr�z2ExistingConnectionTests.assertClientTransportStategs8��	
����)�)�7�7�8�����)�)�1�1�2rJN)rKrLrMrNr�r�r�r�rOrJrHr�r�s���

�0V�<6�3rJr�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�ExistingConnectionHelperTestsz1
    Tests for L{_ExistingConnectionHelper}.
    c�J�|jttt��y)zT
        L{_ExistingConnectionHelper} implements L{_ISSHConnectionCreator}.
        N)rDrr0r/rFs rHrJz,ExistingConnectionHelperTests.test_interfacews��	
����$:�<U�V�WrJc��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)rGrv�helpers   rH�test_secureConnectionz3ExistingConnectionHelperTests.test_secureConnection}s7�����*�6�2���
�
�f�d�2�2�6�3J�3J�3L�M�NrJc�^�tt��}|jt�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�rGr�s  rH�$test_cleanupConnectionNotImmediatelyzBExistingConnectionHelperTests.test_cleanupConnectionNotImmediately�s$��
+�6�8�4��	� � ���5�1rJc�^�tt��}|jt�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�0rJN)rKrLrMrNrJr�r�r�rOrJrHr�r�rs���X�O�	2�	1rJr�c��eZdZdZd�Zd�Zy)�_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)rGr�s  rHrez_PTYPath.__init__�s��
!��
rJc�V�|dk(rt|j�Sttd��)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
        zrb+zFunction not implemented)r2r��OSErrorr)rG�modes  rH�openz
_PTYPath.open�s(���5�=��T�]�]�+�+��f�8�9�9rJN)rKrLrMrNrer�rOrJrHr�r��s���
!�:rJr�c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�NewConnectionHelperTestsz,
    Tests for L{_NewConnectionHelper}.
    c�J�|jttt��y)zO
        L{_NewConnectionHelper} implements L{_ISSHConnectionCreator}.
        N)rDrr0r1rFs rHrJz'NewConnectionHelperTests.test_interface�s��	
����$:�<P�Q�RrJc�D�|jdtj�y)zK
        The default I{known_hosts} path is I{~/.ssh/known_hosts}.
        z~/.ssh/known_hostsN)r�r1�_KNOWN_HOSTSrFs rH�test_defaultPathz)NewConnectionHelperTests.test_defaultPath�s��	
���-�/C�/P�/P�QrJc���t��|jtd�fd��tdddddddddd�
}|j�|j�y)z�
        L{_NewConnectionHelper._knownHosts} is used to create a
        L{KnownHostsFile} if one is not passed to the initializer.
        �_knownHostsc����SrcrO)�clsrvs �rHrhzANewConnectionHelperTests.test_defaultKnownHosts.<locals>.<lambda>�s���F�rJN)r��patchr1r�r4)rGr�rvs  @rH�test_defaultKnownHostsz/NewConnectionHelperTests.test_defaultKnownHosts�sS���
����
�
�'��8J�K�%��$��d�D�$��d�D�$�
��	
�
�
�f�f�/�/�0rJc��t�jd}t|j��}t	|�}|jd|�|j
�td|j���tjjd�}|jj|d�}|jtd|�td|���tj�}|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.1zCreated known_hosts file at z~/r�zPatched _KNOWN_HOSTS with N)r�r�r"r2r+r5r7r#�path�os�
expanduser�replacer�r1r�rD�
hasHostKey)rGr�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������)�)�,��<�=rJc�l�tdddddddddd�
}|j|jt�y)zz
        If L{None} is passed for the C{ui} parameter to
        L{_NewConnectionHelper}, a L{ConsoleUI} is used.
        N)r1r�r:r*r�s  rH�test_defaultConsoleUIz.NewConnectionHelperTests.test_defaultConsoleUI�s9��
&��$��d�D�$��d�D�$�
��	
���f�i�i��3rJc
��td�}tdddddddddd|�}|j|jj	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.
        syesNsdoes this work?)r�r1r�r:rzrD�rG�ttyr�rvs    rH�test_ttyConsoleUIz*NewConnectionHelperTests.test_ttyConsoleUI�s]���v���%��$��d�D�$��d�D�$��
���%�%�f�i�i�&6�&6�7I�&J�K������rJc
���t|j��}tdddddddddd|�}|j|jjd��}|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.
        Nsdid this break?)r"r2r1r�r:rzr�r�s    rH�test_nottyUIz%NewConnectionHelperTests.test_nottyUIse���t�{�{�}�%��%��$��d�D�$��d�D�$��
���%�%�f�i�i�&6�&6�7I�&J�K������ rJc�v�tdddddddddd�
}|jtd�|j�y)zy
        If not passed the name of a tty in the filesystem,
        L{_NewConnectionHelper} uses C{b"/dev/tty"}.
        Ns/dev/tty)r1r�r"r�r�s  rH�test_defaultTTYFilenamez0NewConnectionHelperTests.test_defaultTTYFilenames>��
&��$��d�D�$��d�D�$�
��	
����+�.��
�
�;rJc���tdddddddddd�
}t�}t�|_|j	|d�|j|jj�y)z�
        L{_NewConnectionHelper.cleanupConnection} closes the transport cleanly
        if called with C{immediate} set to C{False}.
        NF)r1r6rr�r�rDrE)rGr�r�s   rHr�z=NewConnectionHelperTests.test_cleanupConnectionNotImmediatelys_��
&��$��d�D�$��d�D�$�
��#�_�
�.�0�
��� � ��U�3����
�,�,�:�:�;rJc� �Gd�d�}tdddddddddd�
}t�}t�|_|�|j_|j	|d�|j|jjj�y)z�
        L{_NewConnectionHelper.cleanupConnection} closes the transport with
        C{abortConnection} if called with C{immediate} set to C{True}.
        c��eZdZdZd�Zy)�MNewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.AbortableFc��d|_y)z7
                Abort the connection.
                TNrDrFs rHrIz]NewConnectionHelperTests.test_cleanupConnectionImmediately.<locals>.Abortable.abortConnection3s�� $��rJN)rKrLrMrErIrOrJrH�	Abortabler�0s���G�
$rJr�NT)r1r6r9r�r�rDrE)rGr�r�r�s    rHr�z:NewConnectionHelperTests.test_cleanupConnectionImmediately*s��	$�	$�&��$��d�D�$��d�D�$�
��#�_�
�1�3�
��)2��
���&�� � ��T�2����
�,�,�6�6�>�>�?rJN)rKrLrMrNrJr�r�r�r�r�r�r�r�r�rOrJrHr�r��s<���S�R�1�>�.4� �!�<�<�@rJr�)wrN�os.pathr��errnor�structr�zope.interfacer�zope.interface.verifyrrr�twisted.conch.errorrr	r
�twisted.conch.interfacesr�twisted.cred.checkersr�twisted.cred.portalr
�twisted.internet.addressr�twisted.internet.deferrrrr�twisted.internet.errorrrrr�twisted.internet.interfacesrr�twisted.internet.protocolrr�twisted.internet.testingrrr�twisted.loggerrr�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/r0r1r2�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@rBrQrZr^rarortr~r�r�r�r�r/r�r�r�r�rOrJrH�<module>rs�������&�;��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��	�	��	�
�
"�#�#%�#%�$�#%�LkB�kB�\
]	8��#E�]	8�@R3�h�(J�R3�j)1�H�)1�X:�:�6G@�x�G@rJ

Zerion Mini Shell 1.0