%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�fHr��B�dZddlZddlmZddlmZddlmZddlm	Z	ed�Z
ddlmZe
r	dd	lm
Z
mZn
Gd
�d�ZGd�d
ej�ZGd�d�ZGd�dej$�ZGd�de	j(�ZGd�de	j(�Zy)z1
This module tests twisted.conch.ssh.connection.
�N)�channel)�
test_userauth)�
requireModule)�unittest�cryptography)�error)�common�
connectionc� �eZdZGd�d�Zy)r
c��eZdZy)�connection.SSHConnectionN)�__name__�
__module__�__qualname__���D/usr/lib/python3/dist-packages/twisted/conch/test/test_connection.py�
SSHConnectionr
s��rrN)rrrrrrrr
r
s��	�	rr
c�R�eZdZdZdZdZdZd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zy
)�TestChannela�
    A mocked-up version of twisted.conch.ssh.channel.SSHChannel.

    @ivar gotOpen: True if channelOpen has been called.
    @type gotOpen: L{bool}
    @ivar specificData: the specific channel open data passed to channelOpen.
    @type specificData: L{bytes}
    @ivar openFailureReason: the reason passed to openFailed.
    @type openFailed: C{error.ConchError}
    @ivar inBuffer: a C{list} of strings received by the channel.
    @type inBuffer: C{list}
    @ivar extBuffer: a C{list} of 2-tuples (type, extended data) of received by
        the channel.
    @type extBuffer: C{list}
    @ivar numberRequests: the number of requests that have been made to this
        channel.
    @type numberRequests: L{int}
    @ivar gotEOF: True if the other side sent EOF.
    @type gotEOF: L{bool}
    @ivar gotOneClose: True if the other side closed the connection.
    @type gotOneClose: L{bool}
    @ivar gotClosed: True if the channel is closed.
    @type gotClosed: L{bool}
    �TestChannelFc� �d|jzS)NzTestChannel %i)�id��selfs r�	logPrefixzTestChannel.logPrefix:s���$�'�'�)�)rc�t�d|_||_g|_g|_d|_d|_d|_d|_y)zF
        The channel is open.  Set up the instance variables.
        TrFN)�gotOpen�specificData�inBuffer�	extBuffer�numberRequests�gotEOF�gotOneClose�	gotClosed)rrs  r�channelOpenzTestChannel.channelOpen=s?�����(�����
���������� �����rc��||_y)zD
        Opening the channel failed.  Store the reason why.
        N)�openFailureReason)r�reasons  r�
openFailedzTestChannel.openFailedJs��"(��rc�6�|xjdz
c_|dk(S)z_
        A test request.  Return True if data is 'data'.

        @type data: L{bytes}
        ��data)r"�r�datas  r�request_testzTestChannel.request_testPs��	
���q� ���w��rc�:�|jj|�y)z=
        Data was received.  Store it in the buffer.
        N)r �appendr.s  r�dataReceivedzTestChannel.dataReceivedYs��	
�
�
���T�"rc�>�|jj||f�y)zF
        Extended data was received.  Store it in the buffer.
        N)r!r2)r�coder/s   r�extReceivedzTestChannel.extReceived_s��	
�����t�T�l�+rc��d|_y)z1
        EOF was received.  Remember it.
        TN)r#rs r�eofReceivedzTestChannel.eofReceivedes����rc��d|_y)z3
        Close was received.  Remember it.
        TN)r$rs r�
closeReceivedzTestChannel.closeReceivedks�� ��rc��d|_y)z7
        The channel is closed.  Rembember it.
        TN)r%rs r�closedzTestChannel.closedqs����rN)rrr�__doc__�namerr%rr&r*r0r3r6r8r:r<rrrrrsE���2�D��G��I�*��(��#�,�� �rrc� �eZdZdZdZd�Zd�Zy)�
TestAvatarz?
    A mocked-up version of twisted.conch.avatar.ConchUser
    �{c��|tjk(rt||||��S|dk(r tj|jd��y)z�
        The server wants us to return a channel.  If the requested channel is
        our TestChannel, return it, otherwise return None.
        )�remoteWindow�remoteMaxPacketr/�avatar�conch-error-args�error args in wrong orderN)rr>r�
ConchError�_ARGS_ERROR_CODE)r�channelType�
windowSize�	maxPacketr/s     r�
lookupChannelzTestAvatar.lookupChannelsW��
�+�*�*�*��'� )���	�
��/�
/�
�"�"�4�#8�#8�:U�V�V�0rc�"�|dk(ry|dk(rd|fSy)z�
        The client has made a global request.  If the global request is
        'TestGlobal', return True.  If the global request is 'TestData',
        return True and the request-specific data we received.  Otherwise,
        return False.
        �
TestGlobalT�TestDataFr)r�requestTyper/s   r�gotGlobalRequestzTestAvatar.gotGlobalRequest�s$���-�'��
�K�
'���:��rN)rrrr=rIrMrRrrrr@r@xs�����W�&rr@c�6�eZdZdZesdZd�Zd�Zd�Zd�Z	d�Z
y)	�TestConnectionz}
    A subclass of SSHConnection for testing.

    @ivar channel: the current channel.
    @type channel. C{TestChannel}
    �Cannot run without cryptographyc��y)NrTrrs rrzTestConnection.logPrefix�s��rc��y)zT
        The other side made the 'TestGlobal' global request.  Return True.
        Trr.s  r�global_TestGlobalz TestConnection.global_TestGlobal�s��rc�
�d|fS)zt
        The other side made the 'Test-Data' global request.  Return True and
        the data we received.
        Trr.s  r�global_Test_DatazTestConnection.global_Test_Data�s��
�T�z�rc�@�t|||��|_|jS)z�
        The other side is requesting the TestChannel.  Create a C{TestChannel}
        instance, store it, and return it.
        )rCrDr/)rr�rrKrLr/s    r�channel_TestChannelz"TestConnection.channel_TestChannel�s#��
#�#�Y�T�
����|�|�rc��td��)zU
        The other side is requesting the ErrorChannel.  Raise an exception.
        z
no such thing)�AssertionErrorr\s    r�channel_ErrorChannelz#TestConnection.channel_ErrorChannel�s���_�-�-rN)rrrr=r�skiprrXrZr]r`rrrrTrT�s*����0�� ����.rrTc���eZdZesdZd�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�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d �Z#d!�Z$d"�Z%y#)$�ConnectionTestsrUc���tjd�|_t�|j_t�|_|j|j_|jj�y�N)r�
FakeTransport�	transportr@rErT�conn�serviceStartedrs r�setUpzConnectionTests.setUp�sL��&�4�4�T�:��� *������"�$��	�"�n�n��	�	���	�	� � �"rc��|jj|�|jjdd|j_|jj	tjd|jd�dz�y)z?
        Open the channel with the default connection.
        N���z>2L�s�)rh�openChannelrg�packets�ssh_CHANNEL_OPEN_CONFIRMATION�struct�packr�rrs  r�_openChannelzConnectionTests._openChannel�s_��	
�	�	���g�&�!%���!7�!7���!<������	�	�/�/��K�K��w�z�z�3�/�2U�U�	
rc�8�|jj�yre)rh�serviceStoppedrs r�tearDownzConnectionTests.tearDown�s���	�	� � �"rc�x�|j|jjj|j�y)z_
        Test that the connection links itself to the avatar in the
        transport.
        N)�assertIsrgrErhrs r�test_linkAvatarzConnectionTests.test_linkAvatar�s&��
	
�
�
�d�n�n�+�+�0�0�$�)�)�<rc��t�}t�}|jj|�|jj|�|jjd�|j	|j
�|j
|j�|j
|j
�|j
|j�|jj�|j	|j�|j
|j
�|j
|j�ddl	m
}|j|j|�y)zF
        Test that serviceStopped() closes any open channels.
        sr)�ConnectionLostN)
rrhrnrp�
assertTruer�assertFalser%rv�twisted.internet.errorr|�assertIsInstancer()r�channel1�channel2r|s    r�test_serviceStoppedz#ConnectionTests.test_serviceStopped�s����=���=���	�	���h�'��	�	���h�'��	�	�/�/�0G�H�����(�(�)�����+�+�,�����)�)�*�����+�+�,��	�	� � �"�����*�*�+�����)�)�*�����+�+�,�9����h�8�8�.�Irc��|jjtjd�dz�|j	|j
jtjdfg�g|j
_|jjtjd�dzdz�|j	|j
jtjdfg�g|j
_|jjtjd�dz�|j	|j
jtjdfg�g|j
_|jjtjd�dz�|j	|j
jg�y)	z�
        Test that global request packets are dispatched to the global_*
        methods and the return values are translated into success or failure
        messages.
        rO��rrPs	test datasTestBad�N)
rh�ssh_GLOBAL_REQUESTr	�NS�assertEqualrgror
�MSG_REQUEST_SUCCESS�MSG_REQUEST_FAILURErs r�test_GLOBAL_REQUESTz#ConnectionTests.test_GLOBAL_REQUESTsN��	
�	�	�$�$�V�Y�Y�}�%=��%G�H�����N�N�"�"�j�&D�&D�c�%J�$K�	
�"$������	�	�$�$�V�Y�Y�{�%;�g�%E��%T�U�����N�N�"�"�j�&D�&D�l�%S�$T�	
�"$������	�	�$�$�V�Y�Y�z�%:�W�%D�E�����N�N�"�"�j�&D�&D�c�%J�$K�	
�"$������	�	�$�$�V�Y�Y�}�%=��%G�H�������/�/��4rc�����jjddd�}�jjd��fd�}|j|�|j	�j
�|S)zh
        Test that global request success packets cause the Deferred to be
        called back.
        �requestr-Tc�*���j|d�y�Nr-)r�)r/rs �r�checkz3ConnectionTests.test_REQUEST_SUCCESS.<locals>.check!s������T�7�+r)rh�sendGlobalRequest�ssh_REQUEST_SUCCESS�addCallback�
addErrback�fail�r�dr�s`  r�test_REQUEST_SUCCESSz$ConnectionTests.test_REQUEST_SUCCESSsW���

�I�I�'�'�
�G�T�B���	�	�%�%�g�.�	,�	
�
�
�e��	���T�Y�Y���rc�����jjddd�}�jjd��fd�}|j�j�|j|�|S)zg
        Test that global request failure packets cause the Deferred to be
        erred back.
        r�r-Tc�R���j|jjd�yr�)r��valuer/)�frs �rr�z3ConnectionTests.test_REQUEST_FAILURE.<locals>.check0s������Q�W�W�\�\�7�3r)rhr��ssh_REQUEST_FAILUREr�r�r�r�s`  r�test_REQUEST_FAILUREz$ConnectionTests.test_REQUEST_FAILURE(sW���

�I�I�'�'�
�G�T�B���	�	�%�%�g�.�	4�	
�
�
�d�i�i� �	���U���rc��|j`|jjt	j
d�dz�|j
|jjj�|j|jjj|j�|j|jjjd�|j|jjjd�|j|jjjd�|j|jjjd�|j|jjtj dfg�g|j_|jjt	j
d�dz�|j#�|j|jjtj$dt	j
d	�zt	j
d
�zfg�g|j_|jjt	j
d�dz�|j#�|j|jjtj$dt	j
d
�zt	j
d
�zfg�y)z�
        Test that open channel packets cause a channel to be created and
        opened or a failure message to be returned.
        r��r,s��
BadChannelsssunknown channelrsErrorChannelssunknown failureN)rgrErh�ssh_CHANNEL_OPENr	r�r}rrr�r/r�remoteWindowLeftrDror
�MSG_CHANNEL_OPEN_CONFIRMATION�flushLoggedErrors�MSG_CHANNEL_OPEN_FAILURErs r�test_CHANNEL_OPENz!ConnectionTests.test_CHANNEL_OPEN7sF��

�N�N�!��	�	�"�"�6�9�9�^�#<�?V�#V�W�����	�	�)�)�1�1�2�������*�*�/�/����;�������*�*�/�/�1D�E�������*�*�7�7�9L�M�������*�*�;�;�Q�?�������*�*�:�:�A�>�����N�N�"�"��<�<�(��
�		
�"$������	�	�"�"�6�9�9�]�#;�>U�#U�V���� �����N�N�"�"��7�7�7��i�i� 2�3�4��i�i��n�%��
�
	
�"$������	�	�"�"�6�9�9�_�#=�@W�#W�X���� �����N�N�"�"��7�7�7��i�i� 2�3�4��i�i��n�%��
�
	
rc�0�||jj_|jj	tjd�dz�|jtj�}|jt|�dd|���|j|djjd�|j|jjtj dtjd�ztjd	�zfg�y
)z�
        Deliver a request for a channel open which will result in an exception
        being raised during channel lookup.  Assert that an error response is
        delivered as a result.
        rFr�r,zExpected one error, got: r)rArGs{serror args in wrong orderrN)rgrErIrhr�r	r�r�rrHr��lenr��argsror
r�)rr5�errorss   r�_lookupChannelErrorTestz'ConnectionTests._lookupChannelErrorTestks���26������.��	�	�"�"��I�I�)�*�-D�D�	
��'�'��(8�(8�9������V��a�+D�V�J�)O�P���������-�-�/Q�R�����N�N�"�"��7�7�8��i�i� <�=�>��i�i��n�%��

�
	
rc�&�|jd�y)a�
        If a C{lookupChannel} implementation raises L{error.ConchError} with the
        arguments in the wrong order, a C{MSG_CHANNEL_OPEN} failure is still
        sent in response to the message.

        This is a temporary work-around until L{error.ConchError} is given
        better attributes and all of the Conch code starts constructing
        instances of it properly.  Eventually this functionality should be
        deprecated and then removed.
        rAN)r�rs r�test_lookupChannelErrorz'ConnectionTests.test_lookupChannelError�s��	
�$�$�S�)rc���t�}|jj|�|jjd�|j	|j
d�|j	|jd�|j	|jd�|j	|jj|d�|j	|jjdd�y)zv
        Test that channel open confirmation packets cause the channel to be
        notified that it's open.
        sr�N)
rrhrnrpr�r�rDr�channelsToRemoteChannel�localToRemoteChannelrss  r�test_CHANNEL_OPEN_CONFIRMATIONz.ConnectionTests.test_CHANNEL_OPEN_CONFIRMATION�s���
�-���	�	���g�&��	�	�/�/�0G�H�����1�1�1�5�����0�0�!�4�����-�-�/B�C�������:�:�7�C�Q�G�������7�7��:�A�>rc�d�t�}|jj|�|jjdt	j
d�z�|j
|jjd�|j|jjj|��y)zz
        Test that channel open failure packets cause the channel to be
        notified that its opening failed.
        ��failure!)r�r,N)rrhrn�ssh_CHANNEL_OPEN_FAILUREr	r�r�r(r��assertIsNone�channels�getrss  r�test_CHANNEL_OPEN_FAILUREz)ConnectionTests.test_CHANNEL_OPEN_FAILURE�s���
�-���	�	���g�&��	�	�*�*�3�f�i�i��6L�L�	
�	
����2�2�7�7�9I�J����$�)�)�,�,�0�0��9�:rc���t�}|j|�|j}|jj	d�|j|j|dz�y)zc
        Test that channel window adjust messages add bytes to the channel
        window.
        r�r,N)rrtr�rh�ssh_CHANNEL_WINDOW_ADJUSTr�)rr�
oldWindowSizes   r�test_CHANNEL_WINDOW_ADJUSTz*ConnectionTests.test_CHANNEL_WINDOW_ADJUST�sR��
�-�����'�"��0�0�
��	�	�+�+�,S�T�����1�1�=�1�3D�Erc��tdd��}|j|�|jjdt	j
d�z�|j
|jdg�|j
|jjtjdfg�g|j_	d|jdzz}|jjdt	j
|�z�|j
|jdg�|j
|jjtjd	fg�t�}|j|�d|jdzz}g|j_	|jjd
t	j
|�z�|j
|jg�|j
|jjtjd	fg�y)z�
        Test that channel data messages are passed up to the channel, or
        cause the channel to be closed if the data is too large.
        ����localWindow�localMaxPacketr�r-���ar,��r�N)rrtrh�ssh_CHANNEL_DATAr	r�r�r rgror
�MSG_CHANNEL_WINDOW_ADJUST�localWindowLeft�MSG_CHANNEL_CLOSEr��rr�longData�bigDatas    r�test_CHANNEL_DATAz!ConnectionTests.test_CHANNEL_DATA�s���
�!�A�>�����'�"��	�	�"�"�#6����7�9K�#K�L�����)�)�G�9�5�����N�N�"�"��8�8�;��
�	
�"$������7�2�2�Q�6�7���	�	�"�"�#6����8�9L�#L�M�����)�)�G�9�5�����N�N�"�"��*�*�,?�
@�A�	
��-�����'�"��'�0�0�1�4�5��!#������	�	�"�"�#6����7�9K�#K�L�����)�)�2�.�����N�N�"�"��*�*�,?�
@�A�	
rc��tdd��}|j|�|jjdt	j
d�z�|j
|jdg�|j
|jjtjdfg�g|j_	d|jd	zz}|jjdt	j
|�z�|j
|jdg�|j
|jjtjd
fg�t�}|j|�d|jd	zz}g|j_	|jjdt	j
|�z�|j
|jg�|j
|jjtjd
fg�y)
z�
        Test that channel extended data messages are passed up to the channel,
        or cause the channel to be closed if they're too big.
        r�r�r�sr-)rr-r�r�r,r�sN)rrtrh�ssh_CHANNEL_EXTENDED_DATAr	r�r�r!rgror
r�r�r�r�r�s    r�test_CHANNEL_EXTENDED_DATAz*ConnectionTests.test_CHANNEL_EXTENDED_DATA�s���
�!�A�>�����'�"��	�	�+�+�3�f�i�i��6H�H�	
�	
����*�*�\�N�;�����N�N�"�"��8�8�;��
�	
�"$������7�2�2�Q�6�7���	�	�+�+�3�f�i�i��6I�I�	
�	
����*�*�\�N�;�����N�N�"�"��*�*�,?�
@�A�	
��-�����'�"��'�0�0�1�4�5��!#������	�	�+�+�3�f�i�i��6H�H�	
�	
����*�*�B�/�����N�N�"�"��*�*�,?�
@�A�	
rc��t�}|j|�|jjd�|j	|j
�y)zN
        Test that channel eof messages are passed up to the channel.
        r�N)rrtrh�ssh_CHANNEL_EOFr}r#rss  r�test_CHANNEL_EOFz ConnectionTests.test_CHANNEL_EOF
s<���-�����'�"��	�	�!�!�"5�6�������'rc��t�}|j|�|j|j�|j	|j
�|j	|j�|jj|�|jjd�|j|j
�|j|j�y)z�
        Test that channel close messages are passed up to the channel.  Also,
        test that channel.close() is called if both sides are closed when this
        message is received.
        r�N)
rrtr}rr~r$r%rh�	sendClose�ssh_CHANNEL_CLOSErss  r�test_CHANNEL_CLOSEz"ConnectionTests.test_CHANNEL_CLOSEs����-�����'�"�������(�����,�,�-�����*�*�+��	�	���G�$��	�	�#�#�$7�8�����+�+�,�����)�)�*rc�x��t�}�j|��jjdt	j
d�zdz��j
|jd��jjdt	j
d�zdzdz�}�fd�}|j|�|S)zS
        Test that channel requests that succeed send MSG_CHANNEL_SUCCESS.
        r��testr�r,r�r-c�t���j�jjtjdfg�y�Nr�)r�rgror
�MSG_CHANNEL_SUCCESS��resultrs �rr�z;ConnectionTests.test_CHANNEL_REQUEST_success.<locals>.check1�0���������&�&��0�0�2E�F�G�
r)	rrtrh�ssh_CHANNEL_REQUESTr	r�r�r"r��rrr�r�s`   r�test_CHANNEL_REQUEST_successz,ConnectionTests.test_CHANNEL_REQUEST_success#s�����-�����'�"��	�	�%�%��&�)�)�G�"4�4�w�>�	
�	
����/�/��3��I�I�)�)��&�)�)�G�"4�4�w�>��H�
��	�	
�
�
�e���rc���t�}�j|��jjdt	j
d�zdz�}�fd�}|j
�j�|j|�|S)zP
        Test that channel requests that fail send MSG_CHANNEL_FAILURE.
        r�r�r�c�t���j�jjtjdfg�yr�)r�rgror
�MSG_CHANNEL_FAILUREr�s �rr�z;ConnectionTests.test_CHANNEL_REQUEST_failure.<locals>.checkDr�r)	rrtrhr�r	r�r�r�r�r�s`   r�test_CHANNEL_REQUEST_failurez,ConnectionTests.test_CHANNEL_REQUEST_failure:sl����-�����'�"��I�I�)�)��&�)�)�G�"4�4�w�>�
��	�	
�
�
�d�i�i� �	���U���rc���t�}�j|��jj|ddd�}�jj	d��fd�}|S)zj
        Test that channel request success messages cause the Deferred to be
        called back.
        r�r-Tr�c�(���j|�yre)r}r�s �rr�z;ConnectionTests.test_CHANNEL_REQUEST_SUCCESS.<locals>.checkXs����O�O�F�#r)rrtrh�sendRequest�ssh_CHANNEL_SUCCESSr�s`   r�test_CHANNEL_REQUEST_SUCCESSz,ConnectionTests.test_CHANNEL_REQUEST_SUCCESSNsS���
�-�����'�"��I�I�!�!�'�7�G�T�B���	�	�%�%�&9�:�	$��rc���t�}�j|��jj|ddd�}�jj	d��fd�}|j�j�|j|�|S)zi
        Test that channel request failure messages cause the Deferred to be
        erred back.
        r�rTr�c�R���j|jjd�y)Nzchannel request failed)r�r�r�s �rr�z;ConnectionTests.test_CHANNEL_REQUEST_FAILURE.<locals>.checkgs������V�\�\�/�/�1I�Jr)rrtrhr��ssh_CHANNEL_FAILUREr�r�r�r�s`   r�test_CHANNEL_REQUEST_FAILUREz,ConnectionTests.test_CHANNEL_REQUEST_FAILURE]sp���
�-�����'�"��I�I�!�!�'�7�C��>���	�	�%�%�&9�:�	K�	
�
�
�d�i�i� �	���U���rc���|jjddd�}|jd��|jjddd�|j|jj
tjtjd�dzftjtjd�d	zfg�|j|jjd
|gi�y)zQ
        Test that global request messages are sent in the right format.
        s	wantReplyr-Tc��yrer��failures r�<lambda>z8ConnectionTests.test_sendGlobalRequest.<locals>.<lambda>t��rsnoReplyrFs�datar��globalN)rhr�r�r�rgror
�MSG_GLOBAL_REQUESTr	r��	deferreds�rr�s  r�test_sendGlobalRequestz&ConnectionTests.test_sendGlobalRequestns���
�I�I�'�'��g�t�D��	���)�*��	�	�#�#�J��U�;�����N�N�"�"��.�.��	�	�,�0G�+�0U�V��.�.��	�	�*�0E��0O�P�
�	
�	
������,�,�x�!��o�>rc�n�t�}|jj|d�|j|jj
tjtjd�dzfg�|j|jd�|j|jjd�y)zO
        Test that open channel messages are sent in the right format.
        saaaars�aaaarr,N)rrhrnr�rgror
�MSG_CHANNEL_OPENr	r�r�localChannelIDrss  r�test_openChannelz ConnectionTests.test_openChannels����-���	�	���g�w�/�����N�N�"�"��/�/��I�I�n�-�M�N��
�		
�	
������Q�'�������1�1�1�5rc	�h�t�}|j|�|jj|ddd�}|j	d��|jj|ddd�d|_|jj|ddd�|j
|jjtjdtjd�zd	zftjdtjd�zd
zfg�|j
|jjd|g�y)
zR
        Test that channel request messages are sent in the right format.
        r�Tc��yrerr�s rr�z2ConnectionTests.test_sendRequest.<locals>.<lambda>�r�r�test2rFstest3r�stestr�rN)rrtrhr�r��localClosedr�rgror
�MSG_CHANNEL_REQUESTr	r�r��rrr�s   r�test_sendRequestz ConnectionTests.test_sendRequest�s���-�����'�"��I�I�!�!�'�7�G�T�B��	���)�*��	�	���g�x��e�<�"����	�	���g�x��d�;�����N�N�"�"��2�2�'�&�)�)�G�*<�<�{�J��
�2�2�'�&�)�)�H�*=�=��G��	
�	
�	
������,�,�Q�/�!��5rc��td��}|j|�d|_|jj	|d�|j|jd�d|_|jj	|d�|j|jd�|j|jjtjdfg�y)	zi
        Test that channel window adjust messages cause bytes to be added
        to the window.
        r�)r�rr,T���N)rrtr�rh�adjustWindowr�rrgror
r�rss  r�test_adjustWindowz!ConnectionTests.test_adjustWindow�s���
�!�,�����'�"�"#����	�	���w��*�����0�0�!�4�"����	�	���w��*�����0�0�!�4�����N�N�"�"��8�8�;��
�	
rc�R�t�}|j|�|jj|d�d|_|jj|d�|j|jjtjdtjd�zfg�y)zO
        Test that channel data messages are sent in the right format.
        r�T�br�N)rrtrh�sendDatarr�rgror
�MSG_CHANNEL_DATAr	r�rss  r�
test_sendDatazConnectionTests.test_sendData�s����-�����'�"��	�	���7�D�)�"����	�	���7�D�)�����N�N�"�"��)�)�+>����4��+P�
Q�R�	
rc�V�t�}|j|�|jj|dd�d|_|jj|dd�|j|jjtjdtjd�zfg�y)zX
        Test that channel extended data messages are sent in the right format.
        r,r�Trrr
N)rrtrh�sendExtendedDatarr�rgror
�MSG_CHANNEL_EXTENDED_DATAr	r�rss  r�test_sendExtendedDataz%ConnectionTests.test_sendExtendedData�s����-�����'�"��	�	�"�"�7�A�w�7�"����	�	�"�"�7�A�x�8�����N�N�"�"��8�8�=��	�	�'�@R�R��
�	
rc��t�}|j|�|jj|�|j	|j
jtjdfg�d|_	|jj|�|j	|j
jtjdfg�y)zN
        Test that channel EOF messages are sent in the right format.
        r�TN)
rrtrh�sendEOFr�rgror
�MSG_CHANNEL_EOFrrss  r�test_sendEOFzConnectionTests.test_sendEOF�s����-�����'�"��	�	���'�"�����N�N�"�"�j�&@�&@�BU�%V�$W�	
�#����	�	���'�"�����N�N�"�"�j�&@�&@�BU�%V�$W�	
rc���t�}|j|�|jj|�|j	|j
�|j
|jjtjdfg�|jj|�|j
|jjtjdfg�t�}|j|�|j	|j�|j|j�d|_|jj|�|j	|j�y)zP
        Test that channel close messages are sent in the right format.
        r�TN)rrtrhr�r}rr�rgror
r�rr~r%�remoteClosed)rrr�s   r�test_sendClosezConnectionTests.test_sendClose�s���-�����'�"��	�	���G�$�����+�+�,�����N�N�"�"��*�*�,?�
@�A�	
�	
�	�	���G�$�����N�N�"�"��*�*�,?�
@�A�	
�
�=�����(�#�����(�(�)�����+�+�,� $����	�	���H�%�����*�*�+rc�X�|jjdddd�}|j|jd�|j|jd�|j|j
d�|j
tj|jjdddd�y)z�
        Test that getChannel dispatches to the avatar when an avatar is
        present. Correct functioning without the avatar is verified in
        test_CHANNEL_OPEN.
        r�2�r-r�N)	rh�
getChannelr�r/r�rD�assertRaisesrrHrss  r�test_getChannelWithAvatarz)ConnectionTests.test_getChannelWithAvatars����)�)�&�&�~�r�2�w�G��������w�/�����1�1�2�6�����0�0�"�5�������d�i�i�2�2�M�2�r�7�	
rc� �|j`|j|jj	dd��|j|jj	dd�d�|j
|jj	dd��y)zW
        Test that gotGlobalRequests dispatches to global_* without an avatar.
        rOr-s	Test-Data)Tr-s	BadGlobalN)rgrEr}rhrRr�r~rs r�"test_gotGlobalRequestWithoutAvatarz2ConnectionTests.test_gotGlobalRequestWithoutAvatarsp��
�N�N�!�����	�	�2�2�=�'�J�K�����I�I�&�&�|�W�=��	
�	
������3�3�L�'�J�Krc���t�}|j|�|jj|ddd��}|j	|t
j�}|jj|�|S)z�
        Whenever an SSH channel gets closed any Deferred that was returned by a
        sendRequest() on its parent connection must be errbacked.
        �dummyrequest�	dummydatar,��	wantReply)rrtrhr��
assertFailurerrH�
channelClosedr	s   r�9test_channelClosedCausesLeftoverChannelDeferredsToErrbackzIConnectionTests.test_channelClosedCausesLeftoverChannelDeferredsToErrback(sf��
�-�����'�"��I�I�!�!�'�?�L�TU�!�V�����q�%�"2�"2�3���	�	����(��rN)&rrrrrarjrtrwrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrrrr%r'r/rrrrcrc�s����0��#�
�#�=�J�*5�0
�
�2
�h
�8*�?�;�	F�#
�J)
�V(�+� �.�(
��"?�"6�&6�6
�.
�
�&
� ,�4
�	L�rrcc�$�eZdZdZesdZd�Zd�Zy)�CleanConnectionShutdownTestszL
    Check whether correct cleanup is performed on connection shutdown.
    rUc��tjd�|_t�|j_t�|_|j|j_yre)rrfrgr@rErTrhrs rrjz"CleanConnectionShutdownTests.setUp>s<��&�4�4�T�:��� *������"�$��	�"�n�n��	�	�rc���|jj�|jjddd��}|j|tj
�}|jj
�|S)z�
        Once the service is stopped any leftover global deferred returned by
        a sendGlobalRequest() call must be errbacked.
        r)r*r,r+)rhrir�r-rrHrvr�s  r�9test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackzVCleanConnectionShutdownTests.test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackDs]��
	
�	�	� � �"��I�I�'�'���QR�'�S�����q�%�"2�"2�3���	�	� � �"��rN)rrrr=rrarjr4rrrr1r16s����0��-�
rr1)r=rq�twisted.conch.sshr�twisted.conch.testr�twisted.python.reflectr�
twisted.trialrr�
twisted.conchrr	r
�
SSHChannelrr@rrT�TestCasercr1rrr�<module>r<s�����%�,�0�"��^�,����4�4���
Y�'�$�$�Y�x&�&�R).�Z�-�-�).�Xf	�h�'�'�f	�R�8�#4�#4�r

Zerion Mini Shell 1.0