U
    n5{iHr  ć                   @   sĪ   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
rfdd	lmZmZ nG d
d dZG dd dejZG dd dZG dd dejZG dd de	jZG d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                   @   s   e Zd ZG dd dZdS )r	   c                   @   s   e Zd ZdS )zconnection.SSHConnectionN)Ś__name__Ś
__module__Ś__qualname__© r   r   śF/tmp/pip-unpacked-wheel-mnhg7r0q/twisted/conch/test/test_connection.pyŚSSHConnection   s   r   N)r
   r   r   r   r   r   r   r   r	      s   r	   c                   @   sd   e Zd ZdZdZdZdZdd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zd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                 C   s
   d| j  S )NzTestChannel %i)Śid©Śselfr   r   r   Ś	logPrefix:   s    zTestChannel.logPrefixc                 C   s4   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   r   r   r   ŚchannelOpen=   s    zTestChannel.channelOpenc                 C   s
   || _ dS )zD
        Opening the channel failed.  Store the reason why.
        N)ŚopenFailureReason)r   Śreasonr   r   r   Ś
openFailedJ   s    zTestChannel.openFailedc                 C   s   |  j d7  _ |dkS )z_
        A test request.  Return True if data is 'data'.

        @type data: L{bytes}
        é   ó   data)r   ©r   Śdatar   r   r   Śrequest_testP   s    zTestChannel.request_testc                 C   s   | j  |” dS )z=
        Data was received.  Store it in the buffer.
        N)r   Śappendr$   r   r   r   ŚdataReceivedY   s    zTestChannel.dataReceivedc                 C   s   | j  ||f” dS )zF
        Extended data was received.  Store it in the buffer.
        N)r   r'   )r   Ścoder%   r   r   r   ŚextReceived_   s    zTestChannel.extReceivedc                 C   s
   d| _ dS )z1
        EOF was received.  Remember it.
        TN)r   r   r   r   r   ŚeofReceivede   s    zTestChannel.eofReceivedc                 C   s
   d| _ dS )z3
        Close was received.  Remember it.
        TN)r   r   r   r   r   ŚcloseReceivedk   s    zTestChannel.closeReceivedc                 C   s
   d| _ dS )z7
        The channel is closed.  Rembember it.
        TN)r   r   r   r   r   Śclosedq   s    zTestChannel.closedN)r
   r   r   Ś__doc__Śnamer   r   r   r   r!   r&   r(   r*   r+   r,   r-   r   r   r   r   r      s   	r   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )Ś
TestAvatarz?
    A mocked-up version of twisted.conch.avatar.ConchUser
    é{   c                 C   s4   |t jkrt |||| dS |dkr0t | 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   ZchannelTypeŚ
windowSizeŚ	maxPacketr%   r   r   r   ŚlookupChannel   s    
üzTestAvatar.lookupChannelc                 C   s$   |dkrdS |dkrd|fS d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ó   TestDataFNr   )r   ZrequestTyper%   r   r   r   ŚgotGlobalRequest   s
    zTestAvatar.gotGlobalRequestN)r
   r   r   r.   r8   r;   r>   r   r   r   r   r0   x   s   r0   c                   @   s@   e Zd ZdZesdZdd Zdd Zdd Zd	d
 Z	dd Z
dS )ŚTestConnectionz}
    A subclass of SSHConnection for testing.

    @ivar channel: the current channel.
    @type channel. C{TestChannel}
    śCannot run without cryptographyc                 C   s   dS )Nr?   r   r   r   r   r   r   ¬   s    zTestConnection.logPrefixc                 C   s   dS )zT
        The other side made the 'TestGlobal' global request.  Return True.
        Tr   r$   r   r   r   Śglobal_TestGlobalÆ   s    z TestConnection.global_TestGlobalc                 C   s   d|fS )zt
        The other side made the 'Test-Data' global request.  Return True and
        the data we received.
        Tr   r$   r   r   r   Śglobal_Test_Dataµ   s    zTestConnection.global_Test_Datac                 C   s   t |||d| _| jS )z
        The other side is requesting the TestChannel.  Create a C{TestChannel}
        instance, store it, and return it.
        )r2   r3   r%   )r   r   ©r   r9   r:   r%   r   r   r   Śchannel_TestChannel¼   s      ’z"TestConnection.channel_TestChannelc                 C   s   t ddS )zU
        The other side is requesting the ErrorChannel.  Raise an exception.
        zno such thingN)ŚAssertionErrorrC   r   r   r   Śchannel_ErrorChannelĘ   s    z#TestConnection.channel_ErrorChannelN)r
   r   r   r.   r   Śskipr   rA   rB   rD   rF   r   r   r   r   r?   ”   s   
r?   c                   @   s  e Zd ZesdZdd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDS )EŚConnectionTestsr@   c                 C   s6   t  d ”| _t | j_t | _| j| j_| j ”  d S ©N)r   ŚFakeTransportŚ	transportr0   r4   r?   ŚconnŚserviceStartedr   r   r   r   ŚsetUpŃ   s
    

zConnectionTests.setUpc                 C   s@   | j  |” | jjdd | j_| j  t d|jd”d ” dS )z?
        Open the channel with the default connection.
        Né’’’’z>2Lé’   s         )rL   ŚopenChannelrK   ŚpacketsŚssh_CHANNEL_OPEN_CONFIRMATIONŚstructŚpackr   ©r   r   r   r   r   Ś_openChannelŲ   s
    ’zConnectionTests._openChannelc                 C   s   | j  ”  d S rI   )rL   ŚserviceStoppedr   r   r   r   ŚtearDownā   s    zConnectionTests.tearDownc                 C   s   |   | jjj| j” dS )z_
        Test that the connection links itself to the avatar in the
        transport.
        N)ZassertIsrK   r4   rL   r   r   r   r   Śtest_linkAvatarå   s    zConnectionTests.test_linkAvatarc                 C   s¬   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   rL   rQ   rS   Ś
assertTruer   ŚassertFalser   rX   Ztwisted.internet.errorr[   ZassertIsInstancer   )r   Zchannel1Śchannel2r[   r   r   r   Śtest_serviceStoppedģ   s    
z#ConnectionTests.test_serviceStoppedc                 C   sŠ   | j  t d”d ” |  | jjtjdfg” g | j_| j  t d”d d ” |  | jjtjdfg” g | j_| j  t d”d ” |  | jjtj	dfg” g | j_| j  t d”d ” |  | 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.
        r<   ó   ’ó    r=   s	   test datas   TestBadó    N)
rL   Zssh_GLOBAL_REQUESTr   ŚNSŚassertEqualrK   rR   r	   ZMSG_REQUEST_SUCCESSZMSG_REQUEST_FAILUREr   r   r   r   Śtest_GLOBAL_REQUEST  s(     
’ 
’ 
’z#ConnectionTests.test_GLOBAL_REQUESTc                    sB    j  ddd”} j  d”  fdd}| |” |  j” |S )zh
        Test that global request success packets cause the Deferred to be
        called back.
        ó   requestr#   Tc                    s      | d” d S ©Nr#   )rd   )r%   r   r   r   Ścheck!  s    z3ConnectionTests.test_REQUEST_SUCCESS.<locals>.check)rL   ŚsendGlobalRequestZssh_REQUEST_SUCCESSŚaddCallbackŚ
addErrbackŚfail©r   Śdrh   r   r   r   Śtest_REQUEST_SUCCESS  s    
z$ConnectionTests.test_REQUEST_SUCCESSc                    sB    j  ddd”} j  d”  fdd}|  j” | |” |S )zg
        Test that global request failure packets cause the Deferred to be
        erred back.
        rf   r#   Tc                    s      | jjd” d S rg   )rd   Śvaluer%   )Śfr   r   r   rh   0  s    z3ConnectionTests.test_REQUEST_FAILURE.<locals>.check)rL   ri   Zssh_REQUEST_FAILURErj   rl   rk   rm   r   r   r   Śtest_REQUEST_FAILURE(  s    
z$ConnectionTests.test_REQUEST_FAILUREc                 C   sH  | j `| j t d”d ” |  | 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 d”d ” |  ”  |  	| j jtjdt d	” t d
” fg” g | j _| j t d”d ” |  ”  |  	| j jtjdt d” t d
” 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 channelra   s   ErrorChannels         s   unknown failureN)rK   r4   rL   Śssh_CHANNEL_OPENr   rc   r\   r   r   rd   r%   r   ŚremoteWindowLeftr3   rR   r	   ZMSG_CHANNEL_OPEN_CONFIRMATIONŚflushLoggedErrorsŚMSG_CHANNEL_OPEN_FAILUREr   r   r   r   Śtest_CHANNEL_OPEN7  sV    ž’ž
’žž’ž’žž’žz!ConnectionTests.test_CHANNEL_OPENc                 C   s   || j j_| j t d”d ” |  tj	”}|  
t|dd|” |  
|d jjd” |  
| j jtjdt d” t d	” 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.
        r5   rs   r"   zExpected one error, got: r   )r1   r6   s         {s   error args in wrong orderra   N)rK   r4   r8   rL   rv   r   rc   rx   r   r7   rd   Ślenrp   ŚargsrR   r	   ry   )r   r)   Śerrorsr   r   r   Ś_lookupChannelErrorTestk  s$    
’’žū’žz'ConnectionTests._lookupChannelErrorTestc                 C   s   |   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.
        r1   N)r~   r   r   r   r   Śtest_lookupChannelError  s    z'ConnectionTests.test_lookupChannelErrorc                 C   st   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   rL   rQ   rS   rd   rw   r3   r   ZchannelsToRemoteChannelZlocalToRemoteChannelrV   r   r   r   Śtest_CHANNEL_OPEN_CONFIRMATION  s    z.ConnectionTests.test_CHANNEL_OPEN_CONFIRMATIONc                 C   sP   t  }| j |” | j dt d” ” |  |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   rL   rQ   Zssh_CHANNEL_OPEN_FAILUREr   rc   rd   r   r|   ZassertIsNoneZchannelsŚgetrV   r   r   r   Śtest_CHANNEL_OPEN_FAILURE¢  s    ’z)ConnectionTests.test_CHANNEL_OPEN_FAILUREc                 C   s8   t  }|  |” |j}| j d” |  |j|d ” dS )zc
        Test that channel window adjust messages add bytes to the channel
        window.
        r   r"   N)r   rW   rw   rL   Zssh_CHANNEL_WINDOW_ADJUSTrd   )r   r   ZoldWindowSizer   r   r   Śtest_CHANNEL_WINDOW_ADJUSTÆ  s
    
z*ConnectionTests.test_CHANNEL_WINDOW_ADJUSTc                 C   s  t ddd}|  |” | j dt d” ” |  |jdg” |  | jj	t
jdfg” g | j_	d|jd  }| j dt |” ” |  |jdg” |  | jj	t
jd	fg” t  }|  |” d|jd  }g | j_	| j d
t |” ” |  |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"   ó      ’rt   N)r   rW   rL   Zssh_CHANNEL_DATAr   rc   rd   r   rK   rR   r	   ŚMSG_CHANNEL_WINDOW_ADJUSTŚlocalWindowLeftŚMSG_CHANNEL_CLOSEr   ©r   r   ZlongDataZbigDatar   r   r   Śtest_CHANNEL_DATAŗ  s:    
ž’ž	
ž

žz!ConnectionTests.test_CHANNEL_DATAc                 C   s  t ddd}|  |” | j dt d” ” |  |jdg” |  | jj	t
jdfg” g | j_	d|jd	  }| j dt |” ” |  |jdg” |  | jj	t
jd
fg” t  }|  |” d|jd	  }g | j_	| j dt |” ” |  |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   rW   rL   Zssh_CHANNEL_EXTENDED_DATAr   rc   rd   r   rK   rR   r	   r   r   r   r   r   r   r   r   Śtest_CHANNEL_EXTENDED_DATAß  sF    
’ž’ž	’
ž
’
žz*ConnectionTests.test_CHANNEL_EXTENDED_DATAc                 C   s,   t  }|  |” | j d” |  |j” dS )zN
        Test that channel eof messages are passed up to the channel.
        r   N)r   rW   rL   Zssh_CHANNEL_EOFr\   r   rV   r   r   r   Śtest_CHANNEL_EOF
  s    
z ConnectionTests.test_CHANNEL_EOFc                 C   sh   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   rW   r\   r   r]   r   r   rL   Ś	sendCloseZssh_CHANNEL_CLOSErV   r   r   r   Śtest_CHANNEL_CLOSE  s    
z"ConnectionTests.test_CHANNEL_CLOSEc                    sp   t  }  |”  j dt d” d ”   |jd”  j dt d” d d ”} fdd}| |” |S )	zS
        Test that channel requests that succeed send MSG_CHANNEL_SUCCESS.
        r   ó   testrb   r"   r`   r#   c                    s       jjtjdfg” d S ©Nr   )rd   rK   rR   r	   ZMSG_CHANNEL_SUCCESS©Śresultr   r   r   rh   1  s    
žz;ConnectionTests.test_CHANNEL_REQUEST_success.<locals>.check)	r   rW   rL   Śssh_CHANNEL_REQUESTr   rc   rd   r   rj   ©r   r   rn   rh   r   r   r   Śtest_CHANNEL_REQUEST_success#  s    
’’
z,ConnectionTests.test_CHANNEL_REQUEST_successc                    sP   t  }  |”  j dt d” d ”} fdd}|  j” | |” |S )zP
        Test that channel requests that fail send MSG_CHANNEL_FAILURE.
        r   r   r`   c                    s       jjtjdfg” d S r   )rd   rK   rR   r	   ZMSG_CHANNEL_FAILUREr   r   r   r   rh   D  s    
žz;ConnectionTests.test_CHANNEL_REQUEST_failure.<locals>.check)	r   rW   rL   r   r   rc   rj   rl   rk   r   r   r   r   Śtest_CHANNEL_REQUEST_failure:  s    
’
z,ConnectionTests.test_CHANNEL_REQUEST_failurec                    s>   t  }  |”  j |ddd”} j d”  fdd}|S )zj
        Test that channel request success messages cause the Deferred to be
        called back.
        r   r#   Tr   c                    s      | ” d S rI   )r\   r   r   r   r   rh   X  s    z;ConnectionTests.test_CHANNEL_REQUEST_SUCCESS.<locals>.check)r   rW   rL   ŚsendRequestZssh_CHANNEL_SUCCESSr   r   r   r   Śtest_CHANNEL_REQUEST_SUCCESSN  s    
z,ConnectionTests.test_CHANNEL_REQUEST_SUCCESSc                    sT   t  }  |”  j |ddd”} j d”  fdd}|  j” | |” |S )zi
        Test that channel request failure messages cause the Deferred to be
        erred back.
        r   ra   Tr   c                    s      | jjd” d S )Nzchannel request failed)rd   rp   r   r   r   r   rh   g  s    z;ConnectionTests.test_CHANNEL_REQUEST_FAILURE.<locals>.check)r   rW   rL   r    Zssh_CHANNEL_FAILURErj   rl   rk   r   r   r   r   Śtest_CHANNEL_REQUEST_FAILURE]  s    

z,ConnectionTests.test_CHANNEL_REQUEST_FAILUREc                 C   s|   | j  ddd”}| dd ” | j  ddd” |  | jjtjt 	d”d	 ftjt 	d”d
 fg” |  | j j
d|gi” dS )zQ
        Test that global request messages are sent in the right format.
        s	   wantReplyr#   Tc                 S   s   d S rI   r   ©Zfailurer   r   r   Ś<lambda>t  ra   z8ConnectionTests.test_sendGlobalRequest.<locals>.<lambda>s   noReplyra   Fs   ’datarb   ŚglobalN)rL   ri   rk   rd   rK   rR   r	   ZMSG_GLOBAL_REQUESTr   rc   Ś	deferreds©r   rn   r   r   r   Śtest_sendGlobalRequestn  s    žžz&ConnectionTests.test_sendGlobalRequestc                 C   sX   t  }| j |d” |  | jjtjt 	d”d 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   rL   rQ   rd   rK   rR   r	   ZMSG_CHANNEL_OPENr   rc   r   ZlocalChannelIDrV   r   r   r   Śtest_openChannel  s    ’ž’ž
z ConnectionTests.test_openChannelc              	   C   s°   t  }|  |” | j |ddd”}| dd ” | j |ddd” d|_| j |ddd” |  | jjt	j
d	t d” d
 ft	j
d	t d” d fg” |  | jjd |g” dS )zR
        Test that channel request messages are sent in the right format.
        r   Tc                 S   s   d S rI   r   r£   r   r   r   r¤     ra   z2ConnectionTests.test_sendRequest.<locals>.<lambda>ó   test2ra   Fs   test3r   s   testrb   r   N)r   rW   rL   r    rk   ŚlocalClosedrd   rK   rR   r	   ZMSG_CHANNEL_REQUESTr   rc   r¦   ©r   r   rn   r   r   r   Śtest_sendRequest  s$    
žžūžz ConnectionTests.test_sendRequestc                 C   st   t d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   rW   r   rL   ZadjustWindowrd   r«   rK   rR   r	   r   rV   r   r   r   Śtest_adjustWindow­  s    

ž’žz!ConnectionTests.test_adjustWindowc                 C   sX   t  }|  |” | j |d” d|_| j |d” |  | jjtj	dt
 d” fg” dS )zO
        Test that channel data messages are sent in the right format.
        r   Tó   br   N)r   rW   rL   ZsendDatar«   rd   rK   rR   r	   ZMSG_CHANNEL_DATAr   rc   rV   r   r   r   Śtest_sendDataÄ  s    
žzConnectionTests.test_sendDatac                 C   s\   t  }|  |” | j |dd” d|_| j |dd” |  | jjtj	dt
 d” fg” dS )zX
        Test that channel extended data messages are sent in the right format.
        r"   r   Tr®   rŖ   rÆ   N)r   rW   rL   ZsendExtendedDatar«   rd   rK   rR   r	   ZMSG_CHANNEL_EXTENDED_DATAr   rc   rV   r   r   r   Śtest_sendExtendedDataŅ  s    
ž’žz%ConnectionTests.test_sendExtendedDatac                 C   sb   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   rW   rL   ZsendEOFrd   rK   rR   r	   ZMSG_CHANNEL_EOFr«   rV   r   r   r   Śtest_sendEOFå  s    
 
’ 
’zConnectionTests.test_sendEOFc                 C   s®   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   rW   rL   r   r\   r«   rd   rK   rR   r	   r   r   r]   r   ZremoteClosed)r   r   r^   r   r   r   Śtest_sendCloseõ  s(    

ž
ž
zConnectionTests.test_sendClosec                 C   sZ   | 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#   ru   N)	rL   Z
getChannelrd   r%   rw   r3   ŚassertRaisesr   r7   rV   r   r   r   Śtest_getChannelWithAvatar  s         ’z)ConnectionTests.test_getChannelWithAvatarc                 C   sH   | j `|  | j dd”” |  | j dd”d” |  | j dd”” dS )zW
        Test that gotGlobalRequests dispatches to global_* without an avatar.
        r<   r#   s	   Test-Data)Tr#   s	   BadGlobalN)rK   r4   r\   rL   r>   rd   r]   r   r   r   r   Ś"test_gotGlobalRequestWithoutAvatar  s     ’z2ConnectionTests.test_gotGlobalRequestWithoutAvatarc                 C   sB   t  }|  |” | jj|d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"   ©Z	wantReply)r   rW   rL   r    ŚassertFailurer   r7   ZchannelClosedr¬   r   r   r   Ś9test_channelClosedCausesLeftoverChannelDeferredsToErrback(  s    
zIConnectionTests.test_channelClosedCausesLeftoverChannelDeferredsToErrbackN)&r
   r   r   r   rG   rN   rW   rY   rZ   r_   re   ro   rr   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   rH   Ķ   sF   
4%+	rH   c                   @   s(   e Zd ZdZesdZdd Zdd ZdS )ŚCleanConnectionShutdownTestszL
    Check whether correct cleanup is performed on connection shutdown.
    r@   c                 C   s,   t  d ”| _t | j_t | _| j| j_d S rI   )r   rJ   rK   r0   r4   r?   rL   r   r   r   r   rN   >  s    
z"CleanConnectionShutdownTests.setUpc                 C   s8   | j  ”  | j jd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½   )rL   rM   ri   r¾   r   r7   rX   r§   r   r   r   Ś9test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackD  s
    

zVCleanConnectionShutdownTests.test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackN)r
   r   r   r.   r   rG   rN   rĮ   r   r   r   r   rĄ   6  s
   rĄ   )r.   rT   Ztwisted.conch.sshr   Ztwisted.conch.testr   Ztwisted.python.reflectr   Ztwisted.trialr   r   Ztwisted.conchr   r   r	   Z
SSHChannelr   r0   r   r?   ZTestCaserH   rĄ   r   r   r   r   Ś<module>   s&   \),    m