Ë
    ojHr  ã                   óB  — 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	  ed«      Z
ddlmZ e
r	dd	lmZmZ n
 G d
„ d«      Z G d„ dej                  «      Z G d„ d«      Z G d„ dej$                  «      Z G d„ de	j(                  «      Z G d„ de	j(                  «      Zy)z1
This module tests twisted.conch.ssh.connection.
é    N)Úchannel)Útest_userauth)ÚrequireModule)ÚunittestÚcryptography)Úerror)ÚcommonÚ
connectionc                   ó    — e Zd Z G d„ d«      Zy)r
   c                   ó   — e Zd Zy)úconnection.SSHConnectionN)Ú__name__Ú
__module__Ú__qualname__© ó    úD/usr/lib/python3/dist-packages/twisted/conch/test/test_connection.pyÚSSHConnectionr      s   „ Ør   r   N)r   r   r   r   r   r   r   r
   r
      s   „ ÷	ò 	r   r
   c                   óR   — 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y)Ú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| j                   z  S )NzTestChannel %i)Úid©Úselfs    r   Ú	logPrefixzTestChannel.logPrefix:   s   € Ø $§'¡'Ñ)Ð)r   c                 ót   — d| _         || _        g | _        g | _        d| _        d| _        d| _        d| _        y)zF
        The channel is open.  Set up the instance variables.
        Tr   FN)ÚgotOpenÚspecificDataÚinBufferÚ	extBufferÚnumberRequestsÚgotEOFÚgotOneCloseÚ	gotClosed)r   r   s     r   ÚchannelOpenzTestChannel.channelOpen=   s?   € ð ˆŒØ(ˆÔØˆŒØˆŒØˆÔØˆŒØ ˆÔØˆ�r   c                 ó   — || _         y)zD
        Opening the channel failed.  Store the reason why.
        N)ÚopenFailureReason)r   Úreasons     r   Ú
openFailedzTestChannel.openFailedJ   s   € ð "(ˆÕr   c                 ó6   — | xj                   dz  c_         |dk(  S )z_
        A test request.  Return True if data is 'data'.

        @type data: L{bytes}
        é   ó   data)r"   ©r   Údatas     r   Úrequest_testzTestChannel.request_testP   s   € ð 	×Ò˜qÑ ÕØ�w‰Ðr   c                 ó:   — | j                   j                  |«       y)z=
        Data was received.  Store it in the buffer.
        N)r    Úappendr.   s     r   ÚdataReceivedzTestChannel.dataReceivedY   s   € ð 	�‰×Ñ˜TÕ"r   c                 ó>   — | j                   j                  ||f«       y)zF
        Extended data was received.  Store it in the buffer.
        N)r!   r2   )r   Úcoder/   s      r   ÚextReceivedzTestChannel.extReceived_   s   € ð 	�‰×Ñ˜t T˜lÕ+r   c                 ó   — d| _         y)z1
        EOF was received.  Remember it.
        TN)r#   r   s    r   ÚeofReceivedzTestChannel.eofReceivede   s   € ð ˆ�r   c                 ó   — d| _         y)z3
        Close was received.  Remember it.
        TN)r$   r   s    r   ÚcloseReceivedzTestChannel.closeReceivedk   s   € ð  ˆÕr   c                 ó   — d| _         y)z7
        The channel is closed.  Rembember it.
        TN)r%   r   s    r   ÚclosedzTestChannel.closedq   s   € ð ˆ�r   N)r   r   r   Ú__doc__Únamer   r%   r   r&   r*   r0   r3   r6   r8   r:   r<   r   r   r   r   r      sE   „ ñð2 €DØ€GØ€Iò*òò(òò#ò,òò ór   r   c                   ó    — e Zd ZdZdZd„ Zd„ Zy)Ú
TestAvatarz?
    A mocked-up version of twisted.conch.avatar.ConchUser
    é{   c                 ó’   — |t         j                  k(  rt        |||| ¬«      S |dk(  r t        j                  | j                  d«      ‚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)r   r>   r   Ú
ConchErrorÚ_ARGS_ERROR_CODE)r   ÚchannelTypeÚ
windowSizeÚ	maxPacketr/   s        r   ÚlookupChannelzTestAvatar.lookupChannel   sW   € ð
 œ+×*Ñ*Ò*ÜØ'Ø )ØØô	ð ð Ð/Ò/ô
 ×"Ñ" 4×#8Ñ#8Ð:UÓVÐVð 0r   c                 ó"   — |dk(  ry|dk(  rd|fS y)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   ÚgotGlobalRequestzTestAvatar.gotGlobalRequest’   s$   € ð ˜-Ò'ØØ˜KÒ'Ø˜�:Ðàr   N)r   r   r   r=   rI   rM   rR   r   r   r   r@   r@   x   s   „ ñð ÐòWó&r   r@   c                   ó6   — e Zd ZdZesdZd„ Zd„ Zd„ Zd„ 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)NrT   r   r   s    r   r   zTestConnection.logPrefix¬   s   € Ør   c                  ó   — y)zT
        The other side made the 'TestGlobal' global request.  Return True.
        Tr   r.   s     r   Úglobal_TestGlobalz TestConnection.global_TestGlobal¯   s   € ð r   c                 ó
   — d|fS )zt
        The other side made the 'Test-Data' global request.  Return True and
        the data we received.
        Tr   r.   s     r   Úglobal_Test_DatazTestConnection.global_Test_Dataµ   s   € ð
 �TˆzÐr   c                 ó@   — t        |||¬«      | _        | j                  S )zƒ
        The other side is requesting the TestChannel.  Create a C{TestChannel}
        instance, store it, and return it.
        )rC   rD   r/   )r   r   ©r   rK   rL   r/   s       r   Úchannel_TestChannelz"TestConnection.channel_TestChannel¼   s#   € ô
 #Ø#°YÀTô
ˆŒð �|‰|Ðr   c                 ó   — t        d«      ‚)zU
        The other side is requesting the ErrorChannel.  Raise an exception.
        zno such thing)ÚAssertionErrorr\   s       r   Úchannel_ErrorChannelz#TestConnection.channel_ErrorChannelÆ   s   € ô ˜_Ó-Ð-r   N)r   r   r   r=   r   Úskipr   rX   rZ   r]   r`   r   r   r   rT   rT   ¡   s*   „ ññ Ø0ˆò òòòó.r   rT   c                   óÚ   — e Zd Zes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„ Zd„ Zd„ Zd„ Z d„ Z!d„ Z"d „ Z#d!„ Z$d"„ Z%y#)$ÚConnectionTestsrU   c                 óò   — t        j                  d «      | _        t        «       | j                  _        t        «       | _        | j                  | j                  _        | j                  j                  «        y ©N)r   ÚFakeTransportÚ	transportr@   rE   rT   ÚconnÚserviceStartedr   s    r   ÚsetUpzConnectionTests.setUpÑ   sL   € Ü&×4Ñ4°TÓ:ˆŒÜ *£ˆ�‰ÔÜ"Ó$ˆŒ	Ø"Ÿn™nˆ�	‰	ÔØ�	‰	× Ñ Õ"r   c                 ó  — | j                   j                  |«       | j                  j                  dd | j                  _        | j                   j	                  t        j                  d|j                  d«      dz   «       y)z?
        Open the channel with the default connection.
        Néÿÿÿÿz>2Léÿ   s        € )rh   ÚopenChannelrg   ÚpacketsÚssh_CHANNEL_OPEN_CONFIRMATIONÚstructÚpackr   ©r   r   s     r   Ú_openChannelzConnectionTests._openChannelØ   s_   € ð 	�	‰	×Ñ˜gÔ&Ø!%§¡×!7Ñ!7¸¸Ð!<ˆ�‰ÔØ�	‰	×/Ñ/Ü�K‰K˜˜wŸz™z¨3Ó/Ð2UÑUõ	
r   c                 ó8   — | j                   j                  «        y re   )rh   ÚserviceStoppedr   s    r   ÚtearDownzConnectionTests.tearDownâ   s   € Ø�	‰	× Ñ Õ"r   c                 óx   — | j                  | j                  j                  j                  | j                  «       y)z_
        Test that the connection links itself to the avatar in the
        transport.
        N)ÚassertIsrg   rE   rh   r   s    r   Útest_linkAvatarzConnectionTests.test_linkAvatarå   s&   € ð
 	�‰�d—n‘n×+Ñ+×0Ñ0°$·)±)Õ<r   c                 óÀ  — t        «       }t        «       }| j                  j                  |«       | j                  j                  |«       | j                  j                  d«       | j	                  |j
                  «       | j                  |j                  «       | j                  |j
                  «       | j                  |j                  «       | j                  j                  «        | j	                  |j                  «       | j                  |j
                  «       | j                  |j                  «       ddl	m
} | j                  |j                  |«       y)zF
        Test that serviceStopped() closes any open channels.
        s                   r   )ÚConnectionLostN)r   rh   rn   rp   Ú
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¸.ÕIr   c                 óŽ  — | j                   j                  t        j                  d«      dz   «       | j	                  | j
                  j                  t        j                  dfg«       g | j
                  _        | j                   j                  t        j                  d«      dz   dz   «       | j	                  | j
                  j                  t        j                  dfg«       g | j
                  _        | j                   j                  t        j                  d«      dz   «       | j	                  | j
                  j                  t        j                  dfg«       g | j
                  _        | j                   j                  t        j                  d«      dz   «       | 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   ó   ÿr   rP   s	   test datas   TestBadó    N)
rh   Ússh_GLOBAL_REQUESTr	   ÚNSÚassertEqualrg   ro   r
   ÚMSG_REQUEST_SUCCESSÚMSG_REQUEST_FAILUREr   s    r   Útest_GLOBAL_REQUESTz#ConnectionTests.test_GLOBAL_REQUEST  sN  € ð 	�	‰	×$Ñ$¤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Ø×Ñ˜Ÿ™×/Ñ/°Õ4r   c                 óÚ   ‡ — ‰ j                   j                  ddd«      }‰ j                   j                  d«       ˆ fd„}|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/   r   s    €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_SUCCESS  sW   ø€ ð
 �I‰I×'Ñ'¨
°G¸TÓBˆØ�	‰	×%Ñ% gÔ.ô	,ð 	
�‰�eÔØ	�‰�T—Y‘YÔØˆr   c                 óÚ   ‡ — ‰ j                   j                  ddd«      }‰ j                   j                  d«       ˆ fd„}|j                  ‰ j                  «       |j                  |«       |S )zg
        Test that global request failure packets cause the Deferred to be
        erred back.
        rŽ   r-   Tc                 óR   •— ‰j                  | j                  j                  d«       y r�   )r‰   Úvaluer/   )Úfr   s    €r   r‘   z3ConnectionTests.test_REQUEST_FAILURE.<locals>.check0  s   ø€ Ø×Ñ˜QŸW™WŸ\™\¨7Õ3r   )rh   r’   Ú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ÔØˆr   c                 ó  — | j                   `| j                  j                  t	        j
                  d«      dz   «       | j                  | j                  j                  j                  «       | j                  | j                  j                  j                  | j                  «       | j                  | j                  j                  j                  d«       | j                  | j                  j                  j                  d«       | j                  | j                  j                  j                  d«       | j                  | j                  j                  j                  d«       | j                  | j                   j                  t        j                   dfg«       g | j                   _        | j                  j                  t	        j
                  d«      dz   «       | j#                  «        | j                  | j                   j                  t        j$                  dt	        j
                  d	«      z   t	        j
                  d
«      z   fg«       g | j                   _        | j                  j                  t	        j
                  d«      dz   «       | j#                  «        | j                  | j                   j                  t        j$                  dt	        j
                  d«      z   t	        j
                  d
«      z   fg«       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               € ó
   BadChannels               s         s   unknown channelr   s   ErrorChannels         s   unknown failureN)rg   rE   rh   Ússh_CHANNEL_OPENr	   rˆ   r}   r   r   r‰   r/   r   ÚremoteWindowLeftrD   ro   r
   ÚMSG_CHANNEL_OPEN_CONFIRMATIONÚflushLoggedErrorsÚMSG_CHANNEL_OPEN_FAILUREr   s    r   Útest_CHANNEL_OPENz!ConnectionTests.test_CHANNEL_OPEN7  sF  € ð
 �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ñ%ððõ
	
r   c                 ó0  — || j                   j                  _        | j                  j	                  t        j                  d«      dz   «       | j                  t        j                  «      }| j                  t        |«      dd|›�«       | j                  |d   j                  j                  d«       | j                  | j                   j                  t        j                   dt        j                  d«      z   t        j                  d	«      z   fg«       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.
        rF   r¡   r,   zExpected one error, got: r   )rA   rG   s         {s   error args in wrong orderr   N)rg   rE   rI   rh   r¤   r	   rˆ   r§   r   rH   r‰   Úlenrœ   Úargsro   r
   r¨   )r   r5   Úerrorss      r   Ú_lookupChannelErrorTestz'ConnectionTests._lookupChannelErrorTestk  sç   € ð 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ñ%ðð
õ	
r   c                 ó&   — | j                  d«       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.
        rA   N)r®   r   s    r   Útest_lookupChannelErrorz'ConnectionTests.test_lookupChannelError‡  s   € ð 	×$Ñ$ SÕ)r   c                 óÐ  — t        «       }| j                  j                  |«       | j                  j                  d«       | j	                  |j
                  d«       | j	                  |j                  d«       | j	                  |j                  d«       | j	                  | j                  j                  |   d«       | j	                  | j                  j                  d   d«       y)zv
        Test that channel open confirmation packets cause the channel to be
        notified that it's open.
        s                       r   ó       N)
r   rh   rn   rp   r‰   r¥   rD   r   ÚchannelsToRemoteChannelÚlocalToRemoteChannelrs   s     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Õ>r   c                 ód  — t        «       }| j                  j                  |«       | j                  j                  dt	        j
                  d«      z   «       | j                  |j                  j                  d«       | j                  | j                  j                  j                  |«      «       y)zz
        Test that channel open failure packets cause the channel to be
        notified that its opening failed.
        ó          ó   failure!)r¸   r,   N)r   rh   rn   Ússh_CHANNEL_OPEN_FAILUREr	   rˆ   r‰   r(   r¬   ÚassertIsNoneÚchannelsÚgetrs   s     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Õ:r   c                 óÆ   — t        «       }| j                  |«       |j                  }| j                  j	                  d«       | j                  |j                  |dz   «       y)zc
        Test that channel window adjust messages add bytes to the channel
        window.
        r·   r,   N)r   rt   r¥   rh   Ússh_CHANNEL_WINDOW_ADJUSTr‰   )r   r   ÚoldWindowSizes      r   Útest_CHANNEL_WINDOW_ADJUSTz*ConnectionTests.test_CHANNEL_WINDOW_ADJUST¯  sR   € ô
 “-ˆØ×Ñ˜'Ô"Ø×0Ñ0ˆØ�	‰	×+Ñ+Ð,SÔTØ×Ñ˜×1Ñ1°=À1Ñ3DÕEr   c                 ó  — t        dd¬«      }| j                  |«       | j                  j                  dt	        j
                  d«      z   «       | j                  |j                  dg«       | j                  | j                  j                  t        j                  dfg«       g | j                  _	        d|j                  dz   z  }| j                  j                  dt	        j
                  |«      z   «       | j                  |j                  dg«       | j                  | j                  j                  t        j                  d	fg«       t        «       }| j                  |«       d|j                  dz   z  }g | j                  _	        | j                  j                  d
t	        j
                  |«      z   «       | j                  |j                  g «       | j                  | j                  j                  t        j                  d	fg«       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)r   rt   rh   Ússh_CHANNEL_DATAr	   rˆ   r‰   r    rg   ro   r
   ÚMSG_CHANNEL_WINDOW_ADJUSTÚlocalWindowLeftÚMSG_CHANNEL_CLOSErÇ   ©r   r   Ú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õ	
r   c                 ó  — t        dd¬«      }| j                  |«       | j                  j                  dt	        j
                  d«      z   «       | j                  |j                  dg«       | j                  | j                  j                  t        j                  dfg«       g | j                  _	        d|j                  d	z   z  }| j                  j                  dt	        j
                  |«      z   «       | j                  |j                  dg«       | j                  | j                  j                  t        j                  d
fg«       t        «       }| j                  |«       d|j                  d	z   z  }g | j                  _	        | j                  j                  dt	        j
                  |«      z   «       | j                  |j                  g «       | j                  | j                  j                  t        j                  d
fg«       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Å   s           r-   )r   r-   rÈ   rÉ   r,   rÊ   s          N)r   rt   rh   Ússh_CHANNEL_EXTENDED_DATAr	   rˆ   r‰   r!   rg   ro   r
   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õ	
r   c                 ó¦   — t        «       }| j                  |«       | j                  j                  d«       | j	                  |j
                  «       y)zN
        Test that channel eof messages are passed up to the channel.
        r²   N)r   rt   rh   Ússh_CHANNEL_EOFr}   r#   rs   s     r   Útest_CHANNEL_EOFz ConnectionTests.test_CHANNEL_EOF
  s<   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×!Ñ!Ð"5Ô6Ø�‰˜Ÿ™Õ'r   c                 ó´  — t        «       }| j                  |«       | j                  |j                  «       | j	                  |j
                  «       | j	                  |j                  «       | j                  j                  |«       | j                  j                  d«       | 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)
r   rt   r}   r   r~   r$   r%   rh   Ú	sendCloseÚssh_CHANNEL_CLOSErs   s     r   Útest_CHANNEL_CLOSEz"ConnectionTests.test_CHANNEL_CLOSE  sš   € ô “-ˆØ×Ñ˜'Ô"Ø�‰˜Ÿ™Ô(Ø×Ñ˜×,Ñ,Ô-Ø×Ñ˜×*Ñ*Ô+Ø�	‰	×Ñ˜GÔ$Ø�	‰	×#Ñ#Ð$7Ô8Ø�‰˜×+Ñ+Ô,Ø�‰˜×)Ñ)Õ*r   c                 óx  ‡ — t        «       }‰ j                  |«       ‰ j                  j                  dt	        j
                  d«      z   dz   «       ‰ j                  |j                  d«       ‰ j                  j                  dt	        j
                  d«      z   dz   dz   «      }ˆ fd„}|j                  |«       |S )zS
        Test that channel requests that succeed send MSG_CHANNEL_SUCCESS.
        r²   ó   testr†   r,   r…   r-   c                 ót   •— ‰j                  ‰j                  j                  t        j                  dfg«       y ©NrÊ   )r‰   rg   ro   r
   ÚMSG_CHANNEL_SUCCESS©Úresultr   s    €r   r‘   z;ConnectionTests.test_CHANNEL_REQUEST_success.<locals>.check1  ó0   ø€ Ø×ÑØ—‘×&Ñ&Ü×0Ñ0Ð2EÐFÐGõr   )	r   rt   rh   Ússh_CHANNEL_REQUESTr	   rˆ   r‰   r"   r”   ©r   r   r˜   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ÔØˆr   c                 ó  ‡ — t        «       }‰ j                  |«       ‰ j                  j                  dt	        j
                  d«      z   dz   «      }ˆ fd„}|j                  ‰ j                  «       |j                  |«       |S )zP
        Test that channel requests that fail send MSG_CHANNEL_FAILURE.
        r²   rÞ   r…   c                 ót   •— ‰j                  ‰j                  j                  t        j                  dfg«       y rà   )r‰   rg   ro   r
   ÚMSG_CHANNEL_FAILURErâ   s    €r   r‘   z;ConnectionTests.test_CHANNEL_REQUEST_failure.<locals>.checkD  rä   r   )	r   rt   rh   rå   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ÔØˆr   c                 óº   ‡ — t        «       }‰ j                  |«       ‰ j                  j                  |ddd«      }‰ j                  j	                  d«       ˆ fd„}|S )zj
        Test that channel request success messages cause the Deferred to be
        called back.
        rÞ   r-   Tr²   c                 ó(   •— ‰j                  | «       y re   )r}   râ   s    €r   r‘   z;ConnectionTests.test_CHANNEL_REQUEST_SUCCESS.<locals>.checkX  s   ø€ Ø�O‰O˜FÕ#r   )r   rt   rh   ÚsendRequestÚssh_CHANNEL_SUCCESSræ   s   `   r   Útest_CHANNEL_REQUEST_SUCCESSz,ConnectionTests.test_CHANNEL_REQUEST_SUCCESSN  sS   ø€ ô
 “-ˆØ×Ñ˜'Ô"Ø�I‰I×!Ñ! '¨7°G¸TÓBˆØ�	‰	×%Ñ%Ð&9Ô:ô	$ð ˆr   c                 ó  ‡ — t        «       }‰ j                  |«       ‰ j                  j                  |ddd«      }‰ j                  j	                  d«       ˆ fd„}|j                  ‰ j                  «       |j                  |«       |S )zi
        Test that channel request failure messages cause the Deferred to be
        erred back.
        rÞ   r   Tr²   c                 óR   •— ‰j                  | j                  j                  d«       y )Nzchannel request failed)r‰   rœ   râ   s    €r   r‘   z;ConnectionTests.test_CHANNEL_REQUEST_FAILURE.<locals>.checkg  s   ø€ Ø×Ñ˜VŸ\™\×/Ñ/Ð1IÕJr   )r   rt   rh   rî   Ú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ÔØˆr   c                 óÖ  — | j                   j                  ddd«      }|j                  d„ «       | j                   j                  ddd«       | j                  | j                  j
                  t        j                  t        j                  d«      dz   ft        j                  t        j                  d«      d	z   fg«       | j                  | j                   j                  d
|gi«       y)zQ
        Test that global request messages are sent in the right format.
        s	   wantReplyr-   Tc                  ó   — y re   r   ©Úfailures    r   ú<lambda>z8ConnectionTests.test_sendGlobalRequest.<locals>.<lambda>t  ó   � r   s   noReplyr   Fs   ÿdatar†   ÚglobalN)rh   r’   r•   r‰   rg   ro   r
   ÚMSG_GLOBAL_REQUESTr	   rˆ   Ú	deferreds©r   r˜   s     r   Útest_sendGlobalRequestz&ConnectionTests.test_sendGlobalRequestn  s¹   € ð �I‰I×'Ñ'¨°g¸tÓDˆà	�‰Ñ)Ô*Ø�	‰	×#Ñ# J°°UÔ;Ø×ÑØ�N‰N×"Ñ"ä×.Ñ.´·	±	¸,Ó0GÈ+Ñ0UÐVÜ×.Ñ.´·	±	¸*Ó0EÈÑ0OÐPðô	
ð 	×Ñ˜Ÿ™×,Ñ,¨x¸!¸¨oÕ>r   c                 ón  — t        «       }| j                  j                  |d«       | j                  | j                  j
                  t        j                  t        j                  d«      dz   fg«       | j                  |j                  d«       | j                  | j                  j                  d«       y)zO
        Test that open channel messages are sent in the right format.
        s   aaaar   s            € aaaar   r,   N)r   rh   rn   r‰   rg   ro   r
   ÚMSG_CHANNEL_OPENr	   rˆ   r   ÚlocalChannelIDrs   s     r   Útest_openChannelz ConnectionTests.test_openChannel  s”   € ô “-ˆØ�	‰	×Ñ˜g wÔ/Ø×ÑØ�N‰N×"Ñ"ô ×/Ñ/Ü—I‘I˜nÓ-ØMñNððô		
ð 	×Ñ˜Ÿ™ QÔ'Ø×Ñ˜Ÿ™×1Ñ1°1Õ5r   c           	      óh  — t        «       }| j                  |«       | j                  j                  |ddd«      }|j	                  d„ «       | j                  j                  |ddd«       d|_        | j                  j                  |ddd«       | j                  | j                  j                  t        j                  dt        j                  d«      z   d	z   ft        j                  dt        j                  d«      z   d
z   fg«       | j                  | j                  j                  d   |g«       y)zR
        Test that channel request messages are sent in the right format.
        rÞ   Tc                  ó   — y re   r   r÷   s    r   rù   z2ConnectionTests.test_sendRequest.<locals>.<lambda>š  rú   r   ó   test2r   Fs   test3rÊ   s   testr†   r   N)r   rt   rh   rî   r•   ÚlocalClosedr‰   rg   ro   r
   ÚMSG_CHANNEL_REQUESTr	   rˆ   rý   ©r   r   r˜   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Ñ/°!°Õ5r   c                 ó¨  — t        d¬«      }| j                  |«       d|_        | j                  j	                  |d«       | j                  |j                  d«       d|_        | j                  j	                  |d«       | j                  |j                  d«       | j                  | j                  j                  t        j                  dfg«       y)	zi
        Test that channel window adjust messages cause bytes to be added
        to the window.
        rÄ   )rÆ   r   r,   Té   ó      ÿ   N)r   rt   rÍ   rh   ÚadjustWindowr‰   r  rg   ro   r
   rÌ   rs   s     r   Útest_adjustWindowz!ConnectionTests.test_adjustWindow­  s³   € ô
 ¨!Ô,ˆØ×Ñ˜'Ô"Ø"#ˆÔØ�	‰	×Ñ˜w¨Ô*Ø×Ñ˜×0Ñ0°!Ô4Ø"ˆÔØ�	‰	×Ñ˜w¨Ô*Ø×Ñ˜×0Ñ0°!Ô4Ø×ÑØ�N‰N×"Ñ"ô ×8Ñ8Ø;ððõ	
r   c                 óR  — t        «       }| j                  |«       | j                  j                  |d«       d|_        | j                  j                  |d«       | j                  | j                  j                  t        j                  dt        j                  d«      z   fg«       y)zO
        Test that channel data messages are sent in the right format.
        rÉ   Tó   brÊ   N)r   rt   rh   ÚsendDatar  r‰   rg   ro   r
   ÚMSG_CHANNEL_DATAr	   rˆ   rs   s     r   Útest_sendDatazConnectionTests.test_sendDataÄ  sƒ   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×Ñ˜7 DÔ)Ø"ˆÔØ�	‰	×Ñ˜7 DÔ)Ø×ÑØ�N‰N×"Ñ"Ü×)Ñ)Ð+>ÄÇÁÈ4ÃÑ+PÐQÐRõ	
r   c                 óV  — t        «       }| j                  |«       | j                  j                  |dd«       d|_        | j                  j                  |dd«       | j                  | j                  j                  t        j                  dt        j                  d«      z   fg«       y)zX
        Test that channel extended data messages are sent in the right format.
        r,   rÞ   Tr  r  r  N)r   rt   rh   ÚsendExtendedDatar  r‰   rg   ro   r
   ÚMSG_CHANNEL_EXTENDED_DATAr	   rˆ   rs   s     r   Útest_sendExtendedDataz%ConnectionTests.test_sendExtendedDataÒ  sŽ   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×"Ñ" 7¨A¨wÔ7Ø"ˆÔØ�	‰	×"Ñ" 7¨A¨xÔ8Ø×ÑØ�N‰N×"Ñ"ô ×8Ñ8Ø=ÄÇ	Á	È'Ó@RÑRððõ	
r   c                 ó�  — t        «       }| j                  |«       | j                  j                  |«       | j	                  | j
                  j                  t        j                  dfg«       d|_	        | j                  j                  |«       | j	                  | j
                  j                  t        j                  dfg«       y)zN
        Test that channel EOF messages are sent in the right format.
        rÊ   TN)
r   rt   rh   ÚsendEOFr‰   rg   ro   r
   ÚMSG_CHANNEL_EOFr  rs   s     r   Útest_sendEOFzConnectionTests.test_sendEOFå  sŸ   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×Ñ˜'Ô"Ø×ÑØ�N‰N×"Ñ"¤j×&@Ñ&@ÐBUÐ%VÐ$Wô	
ð #ˆÔØ�	‰	×Ñ˜'Ô"Ø×ÑØ�N‰N×"Ñ"¤j×&@Ñ&@ÐBUÐ%VÐ$Wõ	
r   c                 óÔ  — t        «       }| j                  |«       | j                  j                  |«       | j	                  |j
                  «       | j                  | j                  j                  t        j                  dfg«       | j                  j                  |«       | j                  | j                  j                  t        j                  dfg«       t        «       }| j                  |«       | j	                  |j                  «       | j                  |j                  «       d|_        | j                  j                  |«       | j	                  |j                  «       y)zP
        Test that channel close messages are sent in the right format.
        rÊ   TN)r   rt   rh   rÚ   r}   r  r‰   rg   ro   r
   rÎ   r   r~   r%   ÚremoteClosed)r   r   r‚   s      r   Útest_sendClosezConnectionTests.test_sendCloseõ  s  € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×Ñ˜GÔ$Ø�‰˜×+Ñ+Ô,Ø×ÑØ�N‰N×"Ñ"Ü×*Ñ*Ð,?Ð@ÐAô	
ð 	�	‰	×Ñ˜GÔ$Ø×ÑØ�N‰N×"Ñ"Ü×*Ñ*Ð,?Ð@ÐAô	
ô
 “=ˆØ×Ñ˜(Ô#Ø�‰˜×(Ñ(Ô)Ø×Ñ˜×+Ñ+Ô,Ø $ˆÔØ�	‰	×Ñ˜HÔ%Ø�‰˜×*Ñ*Õ+r   c                 óX  — | j                   j                  dddd«      }| j                  |j                  d«       | j                  |j                  d«       | j                  |j
                  d«       | j                  t        j                  | j                   j                  dddd«       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   ÚassertRaisesr   rH   rs   s     r   Útest_getChannelWithAvatarz)ConnectionTests.test_getChannelWithAvatar  s‰   € ð —)‘)×&Ñ& ~°r¸2¸wÓGˆØ×Ñ˜Ÿ™ wÔ/Ø×Ñ˜×1Ñ1°2Ô6Ø×Ñ˜×0Ñ0°"Ô5Ø×ÑÜ×Ñ˜dŸi™i×2Ñ2°MÀ2ÀrÈ7õ	
r   c                 ó   — | j                   `| j                  | j                  j	                  dd«      «       | j                  | j                  j	                  dd«      d«       | j                  | j                  j	                  dd«      «       y)zW
        Test that gotGlobalRequests dispatches to global_* without an avatar.
        rO   r-   s	   Test-Data)Tr-   s	   BadGlobalN)rg   rE   r}   rh   rR   r‰   r~   r   s    r   Ú"test_gotGlobalRequestWithoutAvatarz2ConnectionTests.test_gotGlobalRequestWithoutAvatar  sp   € ð �N‰NÐ!Ø�‰˜Ÿ	™	×2Ñ2°=À'ÓJÔKØ×ÑØ�I‰I×&Ñ& |°WÓ=¸ô	
ð 	×Ñ˜Ÿ™×3Ñ3°LÀ'ÓJÕKr   c                 óð   — t        «       }| j                  |«       | j                  j                  |ddd¬«      }| j	                  |t
        j                  «      }| j                  j                  |«       |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)r   rt   rh   rî   ÚassertFailurer   rH   ÚchannelClosedr	  s      r   Ú9test_channelClosedCausesLeftoverChannelDeferredsToErrbackzIConnectionTests.test_channelClosedCausesLeftoverChannelDeferredsToErrback(  sf   € ô
 “-ˆØ×Ñ˜'Ô"à�I‰I×!Ñ! '¨?¸LÐTUÐ!ÓVˆØ×Ñ˜q¤%×"2Ñ"2Ó3ˆØ�	‰	×Ñ Ô(Øˆr   N)&r   r   r   r   ra   rj   rt   rw   rz   rƒ   rŒ   r™   rŸ   r©   r®   r°   rµ   r½   rÁ   rÒ   rÕ   rØ   rÜ   rç   rë   rð   rô   rÿ   r  r
  r  r  r  r  r  r%  r'  r/  r   r   r   rc   rc   Í   sµ   „ ÙØ0ˆò#ò
ò#ò=òJò*5ò0òò2
òh
ò8*ò?ò;ò	Fò#
òJ)
òV(ò+ò ò.ò(òò"?ò"6ò&6ò6
ò.
ò
ò&
ò ,ò4
ò	Lór   rc   c                   ó$   — e Zd ZdZesdZd„ Zd„ Zy)ÚCleanConnectionShutdownTestszL
    Check whether correct cleanup is performed on connection shutdown.
    rU   c                 ó¾   — t        j                  d «      | _        t        «       | j                  _        t        «       | _        | j                  | j                  _        y re   )r   rf   rg   r@   rE   rT   rh   r   s    r   rj   z"CleanConnectionShutdownTests.setUp>  s<   € Ü&×4Ñ4°TÓ:ˆŒÜ *£ˆ�‰ÔÜ"Ó$ˆŒ	Ø"Ÿn™nˆ�	‰	Õr   c                 óê   — | j                   j                  «        | j                   j                  ddd¬«      }| j                  |t        j
                  «      }| j                   j                  «        |S )zŒ
        Once the service is stopped any leftover global deferred returned by
        a sendGlobalRequest() call must be errbacked.
        r)  r*  r,   r+  )rh   ri   r’   r-  r   rH   rv   rþ   s     r   Ú9test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackzVCleanConnectionShutdownTests.test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackD  s]   € ð
 	�	‰	× Ñ Ô"à�I‰I×'Ñ'¨¸ÐQRÐ'ÓSˆØ×Ñ˜q¤%×"2Ñ"2Ó3ˆØ�	‰	× Ñ Ô"Øˆr   N)r   r   r   r=   r   ra   rj   r4  r   r   r   r1  r1  6  s   „ ññ Ø0ˆò-ó
r   r1  )r=   rq   Útwisted.conch.sshr   Útwisted.conch.testr   Útwisted.python.reflectr   Útwisted.trialr   r   Útwisted.conchr   r	   r
   Ú
SSHChannelr   r@   r   rT   ÚTestCaserc   r1  r   r   r   ú<module>r<     s•   ðñó å %Ý ,Ý 0Ý "á˜^Ó,€å áß4Ð4÷ñ ô
Y�'×$Ñ$ô Y÷x&ñ &ôR).�Z×-Ñ-ô ).ôXf	�h×'Ñ'ô f	ôR 8×#4Ñ#4õ r   