
    tfHr                     F   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	  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dS )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dS )r
   c                       e Zd ZdS )connection.SSHConnectionN)__name__
__module____qualname__     a/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/conch/test/test_connection.pySSHConnectionr      s        Dr   r   N)r   r   r   r   r   r   r   r
   r
      s<        	 	 	 	 	 	 	 	 	 	r   r
   c                   T    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd ZdS )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                 v    d| _         || _        g | _        g | _        d| _        d| _        d| _        d| _        dS )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=   sC     ( r   c                     || _         dS )zD
        Opening the channel failed.  Store the reason why.
        N)openFailureReason)r   reasons     r   
openFailedzTestChannel.openFailedJ   s     "(r   c                 .    | 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                             |           dS )z=
        Data was received.  Store it in the buffer.
        N)r    appendr.   s     r   dataReceivedzTestChannel.dataReceivedY   s      	T"""""r   c                 >    | j                             ||f           dS )zF
        Extended data was received.  Store it in the buffer.
        N)r!   r2   )r   coder/   s      r   extReceivedzTestChannel.extReceived_   s$     	tTl+++++r   c                     d| _         dS )z1
        EOF was received.  Remember it.
        TN)r#   r   s    r   eofReceivedzTestChannel.eofReceivede   s     r   c                     d| _         dS )z3
        Close was received.  Remember it.
        TN)r$   r   s    r   closeReceivedzTestChannel.closeReceivedk   s      r   c                     d| _         dS )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      s         2 DGI* * *  ( ( (  # # #, , ,           r   r   c                   "    e Zd ZdZdZd Zd ZdS )
TestAvatarz?
    A mocked-up version of twisted.conch.avatar.ConchUser
    {   c                     |t           j        k    rt          ||||           S |dk    rt          j        | j        d          dS )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   sd    
 +***' )	    ///
 "4#8:UVVV 0/r   c                 *    |dk    rdS |dk    rd|fS dS )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.     -''4K'':5r   N)r   r   r   r=   rI   rM   rR   r   r   r   r@   r@   x   sG          W W W&    r   r@   c                   8    e Zd ZdZesdZd Zd Zd Zd Z	d Z
dS )	TestConnectionz}
    A subclass of SSHConnection for testing.

    @ivar channel: the current channel.
    @type channel. C{TestChannel}
    Cannot run without cryptographyc                     dS )NrT   r   r   s    r   r   zTestConnection.logPrefix   s    r   c                     dS )zT
        The other side made the 'TestGlobal' global request.  Return True.
        Tr   r.   s     r   global_TestGlobalz TestConnection.global_TestGlobal   s	     tr   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    
 Tz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+    
 ##YT
 
 
 |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      sx           1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%d#S )$ConnectionTestsrU   c                     t          j        d           | _        t                      | j        _        t                      | _        | j        | j        _        | j                                         d S N)r   FakeTransport	transportr@   rE   rT   connserviceStartedr   s    r   setUpzConnectionTests.setUp   sU    &4T:: *"$$	"n		  """""r   c                     | j                             |           | j        j        dd         | j        _        | j                             t          j        d|j        d          dz              dS )z?
        Open the channel with the default connection.
        Nz>2L   s         )rh   openChannelrg   packetsssh_CHANNEL_OPEN_CONFIRMATIONstructpackr   r   r   s     r   _openChannelzConnectionTests._openChannel   so     		g&&&!%!7!<	//Kwz3//2UU	
 	
 	
 	
 	
r   c                 8    | j                                          d S re   )rh   serviceStoppedr   s    r   tearDownzConnectionTests.tearDown   s    	  """""r   c                 Z    |                      | j        j        j        | j                   dS )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(    
 	dn+0$)<<<<<r   c                    t                      }t                      }| j                            |           | j                            |           | j                            d           |                     |j                   |                     |j                   |                     |j                   |                     |j                   | j                                         |                     |j                   |                     |j                   |                     |j                   ddl	m
} |                     |j        |           dS )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HH()))+,,,)***+,,,	  """*+++)***+,,,999999h8.IIIIIr   c                    | j                             t          j        d          dz              |                     | j        j        t          j        dfg           g | j        _        | j                             t          j        d          dz   dz              |                     | j        j        t          j        dfg           g | j        _        | j                             t          j        d          dz              |                     | j        j        t          j	        dfg           g | j        _        | j                             t          j        d          dz              |                     | j        j        g            dS )	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  si    		$$VY}%=%=%GHHHN"j&Dc%J$K	
 	
 	
 "$	$$VY{%;%;g%E%TUUUN"j&Dl%S$T	
 	
 	
 "$	$$VYz%:%:W%DEEEN"j&Dc%J$K	
 	
 	
 "$	$$VY}%=%=%GHHH/44444r   c                       j                             ddd          } j                             d            fd}|                    |           |                     j                   |S )zh
        Test that global request success packets cause the Deferred to be
        called back.
           requestr-   Tc                 4                         | d           d S Nr-   )r   )r/   r   s    r   checkz3ConnectionTests.test_REQUEST_SUCCESS.<locals>.check!  s    T7+++++r   )rh   sendGlobalRequestssh_REQUEST_SUCCESSaddCallback
addErrbackfailr   dr   s   `  r   test_REQUEST_SUCCESSz$ConnectionTests.test_REQUEST_SUCCESS  sz    
 I''
GTBB	%%g...	, 	, 	, 	, 	, 	
e	TYr   c                       j                             ddd          } j                             d            fd}|                     j                   |                    |           |S )zg
        Test that global request failure packets cause the Deferred to be
        erred back.
        r   r-   Tc                 H                         | j        j        d           d S r   )r   valuer/   )fr   s    r   r   z3ConnectionTests.test_REQUEST_FAILURE.<locals>.check0  s#    QW\733333r   )rh   r   ssh_REQUEST_FAILUREr   r   r   r   s   `  r   test_REQUEST_FAILUREz$ConnectionTests.test_REQUEST_FAILURE(  sz    
 I''
GTBB	%%g...	4 	4 	4 	4 	4 	
di   	Ur   c                 (   | j         `| j                            t	          j        d          dz              |                     | j        j        j                   | 	                    | j        j        j        | j                   | 	                    | j        j        j
        d           | 	                    | j        j        j        d           | 	                    | j        j        j        d           | 	                    | j        j        j        d           | 	                    | j         j        t          j        dfg           g | j         _        | j                            t	          j        d          dz              |                                  | 	                    | j         j        t          j        dt	          j        d	          z   t	          j        d
          z   fg           g | j         _        | j                            t	          j        d          dz              |                                  | 	                    | j         j        t          j        dt	          j        d          z   t	          j        d
          z   fg           dS )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  s_   
 N!	""69^#<#<?V#VWWW	)1222*/;;;*/1DEEE*79LMMM*;Q???*:A>>>N" <(		
 		
 		
 "$	""69]#;#;>U#UVVV   N" 77i 2334inn%
	
 
	
 
	
 "$	""69_#=#=@W#WXXX   N" 77i 2334inn%
	
 
	
 
	
 
	
 
	
r   c                    || j         j        _        | j                            t          j        d          dz              |                     t          j	                  }| 
                    t          |          dd|           | 
                    |d         j        j        d           | 
                    | j         j        t          j        dt          j        d          z   t          j        d	          z   fg           d
S )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)**-DD	
 	
 	
 ''(899Va)OV)O)OPPP-/QRRRN" 7 8i <==>inn%
	
 	
 	
 	
 	
r   c                 0    |                      d           dS )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                            d           |                     |j        d           |                     |j        d           |                     |j        d           |                     | j        j        |         d           |                     | j        j	        d         d           dS )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HH115550!444-/BCCC:7CQGGG7:A>>>>>r   c                 X   t                      }| j                            |           | j                            dt	          j        d          z              |                     |j        j        d           | 	                    | j        j
                            |                     dS )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&&&	**3fi6L6LL	
 	
 	
 	279IJJJ$),0099:::::r   c                     t                      }|                     |           |j        }| j                            d           |                     |j        |dz              dS )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  sd    
 --'"""0	++,STTT1=13DEEEEEr   c                    t          dd          }|                     |           | j                            dt	          j        d          z              |                     |j        dg           |                     | j        j	        t          j        dfg           g | j        _	        d|j        dz   z  }| j                            dt	          j        |          z              |                     |j        dg           |                     | j        j	        t          j        d	fg           t                      }|                     |           d|j        dz   z  }g | j        _	        | j                            d
t	          j        |          z              |                     |j        g            |                     | j        j	        t          j        d	fg           dS )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79K9K#KLLL)G9555N" 8;	
 	
 	
 "$72Q67	""#689L9L#LMMM)G9555N"*,?@A	
 	
 	
 --'"""'0145!#	""#679K9K#KLLL)2...N"*,?@A	
 	
 	
 	
 	
r   c                    t          dd          }|                     |           | j                            dt	          j        d          z              |                     |j        dg           |                     | j        j	        t          j        dfg           g | j        _	        d|j        d	z   z  }| j                            dt	          j        |          z              |                     |j        dg           |                     | j        j	        t          j        d
fg           t                      }|                     |           d|j        d	z   z  }g | j        _	        | j                            dt	          j        |          z              |                     |j        g            |                     | j        j	        t          j        d
fg           dS )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>>>'"""	++3fi6H6HH	
 	
 	
 	*\N;;;N" 8;	
 	
 	
 "$72Q67	++3fi6I6II	
 	
 	
 	*\N;;;N"*,?@A	
 	
 	
 --'"""'0145!#	++3fi6H6HH	
 	
 	
 	*B///N"*,?@A	
 	
 	
 	
 	
r   c                     t                      }|                     |           | j                            d           |                     |j                   dS )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
  sR     --'"""	!!"5666'''''r   c                    t                      }|                     |           |                     |j                   |                     |j                   |                     |j                   | j                            |           | j        	                    d           |                     |j                   |                     |j                   dS )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88+,,,)*****r   c                     t                      }                     |            j                            dt	          j        d          z   dz                                   |j        d            j                            dt	          j        d          z   dz   dz             } fd}|                    |           |S )zS
        Test that channel requests that succeed send MSG_CHANNEL_SUCCESS.
        r      testr   r,   r   r-   c                 b                         j        j        t          j        dfg           d S Nr   )r   rg   ro   r
   MSG_CHANNEL_SUCCESSresultr   s    r   r   z;ConnectionTests.test_CHANNEL_REQUEST_success.<locals>.check1  <    &02E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4w>	
 	
 	
 	/333I))&)G"4"44w>H
 
	 	 	 	 	 	
er   c                     t                      }                     |            j                            dt	          j        d          z   dz             } fd}|                     j                   |                    |           |S )zP
        Test that channel requests that fail send MSG_CHANNEL_FAILURE.
        r   r   r   c                 b                         j        j        t          j        dfg           d S 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:  s     --'"""I))&)G"4"44w>
 
	 	 	 	 	 	
di   	Ur   c                      t                      }                     |            j                            |ddd          } j                            d            fd}|S )zj
        Test that channel request success messages cause the Deferred to be
        called back.
        r   r-   Tr   c                 2                         |            d S re   )r}   r   s    r   r   z;ConnectionTests.test_CHANNEL_REQUEST_SUCCESS.<locals>.checkX  s    OOF#####r   )r   rt   rh   sendRequestssh_CHANNEL_SUCCESSr   s   `   r   test_CHANNEL_REQUEST_SUCCESSz,ConnectionTests.test_CHANNEL_REQUEST_SUCCESSN  st    
 --'"""I!!'7GTBB	%%&9:::	$ 	$ 	$ 	$ 	$ r   c                 $    t                      }                     |            j                            |ddd          } j                            d            fd}|                     j                   |                    |           |S )zi
        Test that channel request failure messages cause the Deferred to be
        erred back.
        r   r   Tr   c                 H                         | j        j        d           d S )Nzchannel request failed)r   r   r   s    r   r   z;ConnectionTests.test_CHANNEL_REQUEST_FAILURE.<locals>.checkg  s%    V\/1IJJJJJr   )r   rt   rh   r   ssh_CHANNEL_FAILUREr   r   r   r   s   `   r   test_CHANNEL_REQUEST_FAILUREz,ConnectionTests.test_CHANNEL_REQUEST_FAILURE]  s    
 --'"""I!!'7C>>	%%&9:::	K 	K 	K 	K 	K 	
di   	Ur   c                    | j                             ddd          }|                    d            | j                             ddd           |                     | j        j        t          j        t          j	        d          dz   ft          j        t          j	        d          d	z   fg           |                     | j         j
        d
|gi           dS )zQ
        Test that global request messages are sent in the right format.
        s	   wantReplyr-   Tc                     d S re   r   failures    r   <lambda>z8ConnectionTests.test_sendGlobalRequest.<locals>.<lambda>t      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''gtDD	))***	##JU;;;N".	,0G0G+0UV.	*0E0E0OP	
 	
 	
 	,x!o>>>>>r   c                 R   t                      }| j                            |d           |                     | j        j        t          j        t          j	        d          dz   fg           |                     |j
        d           |                     | j        j        d           dS )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     --	gw///N" /In--MN		
 		
 		
 	Q'''1155555r   c           	      V   t                      }|                     |           | j                            |ddd          }|                    d            | j                            |ddd           d|_        | j                            |ddd           |                     | 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        d         |g           dS )zR
        Test that channel request messages are sent in the right format.
        r   Tc                     d S 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!!'7GTBB	))***	gxe<<<"	gxd;;;N" 2'&)G*<*<<{J
 2'&)H*=*==G		
 	
 	
 	,Q/!55555r   c                    t          d          }|                     |           d|_        | j                            |d           |                     |j        d           d|_        | j                            |d           |                     |j        d           |                     | j        j        t          j
        dfg           dS )	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!444"	w***0!444N" 8;	
 	
 	
 	
 	
r   c                 J   t                      }|                     |           | j                            |d           d|_        | j                            |d           |                     | j        j        t          j	        dt          j        d          z   fg           dS )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     --'"""	7D)))"	7D)))N")+>4+PQR	
 	
 	
 	
 	
r   c                 N   t                      }|                     |           | j                            |dd           d|_        | j                            |dd           |                     | j        j        t          j	        dt          j        d          z   fg           dS )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     --'"""	""7Aw777"	""7Ax888N" 8=	'@R@RR	
 	
 	
 	
 	
r   c                 v   t                      }|                     |           | j                            |           |                     | j        j        t          j        dfg           d|_	        | j                            |           |                     | j        j        t          j        dfg           dS )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"j&@BU%V$W	
 	
 	
 #	'"""N"j&@BU%V$W	
 	
 	
 	
 	
r   c                    t                      }|                     |           | j                            |           |                     |j                   |                     | j        j        t          j
        dfg           | j                            |           |                     | j        j        t          j
        dfg           t                      }|                     |           |                     |j                   |                     |j                   d|_        | j                            |           |                     |j                   dS )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  sF    --'"""	G$$$+,,,N"*,?@A	
 	
 	
 		G$$$N"*,?@A	
 	
 	

 ==(###()))+,,, $	H%%%*+++++r   c                 >   | j                             dddd          }|                     |j        d           |                     |j        d           |                     |j        d           |                     t          j        | j         j        dddd           dS )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     )&&~r2wGGw///126660"555di2M2r7	
 	
 	
 	
 	
r   c                 *   | j         `|                     | j                            dd                     |                     | j                            dd          d           |                     | j                            dd                     dS )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  s     N!	22='JJKKKI&&|W==	
 	
 	
 	33L'JJKKKKKr   c                     t                      }|                     |           | j                            |ddd          }|                     |t
          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(  ss    
 --'"""I!!'?LTU!VVq%"23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        10# # #
 
 
# # #= = =J J J*5 5 50    2
 2
 2
h
 
 
8* * *? ? ?; ; ;	F 	F 	F#
 #
 #
J)
 )
 )
V( ( (+ + +   .  (    "? ? ?"6 6 6&6 6 66
 
 
.
 
 

 
 
&
 
 
 , , ,4
 
 
	L 	L 	L    r   rc   c                   &    e Zd ZdZesdZd Zd ZdS )CleanConnectionShutdownTestszL
    Check whether correct cleanup is performed on connection shutdown.
    rU   c                     t          j        d           | _        t                      | j        _        t                      | _        | j        | j        _        d S re   )r   rf   rg   r@   rE   rT   rh   r   s    r   rj   z"CleanConnectionShutdownTests.setUp>  sA    &4T:: *"$$	"n	r   c                     | j                                          | j                             ddd          }|                     |t          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  sf    
 		  """I''QR'SSq%"233	  """r   N)r   r   r   r=   r   ra   rj   r4  r   r   r   r1  r1  6  sK           1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 0 0 0 0 0 " " " " " "}^,,       444444444       
Y Y Y Y Y'$ Y Y Yx& & & & & & & &R). ). ). ). ).Z- ). ). ).Xf	 f	 f	 f	 f	h' f	 f	 f	R    8#4     r   