ó
    Ö›‘hHr  ã                   óL  • S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  \" S5      r
SSKJr  \
(       a	  SS	KJrJr  O
 " S
 S5      r " S S\R                  5      r " S S5      r " S S\R$                  5      r " S S\	R(                  5      r " S S\	R(                  5      rg)z1
This module tests twisted.conch.ssh.connection.
é    N©Úchannel)Útest_userauth)ÚrequireModule)ÚunittestÚcryptography)Úerror)ÚcommonÚ
connectionc                   ó(   • \ rS rSr " S S5      rSrg)r   é   c                   ó   • \ rS rSrSrg)Úconnection.SSHConnectioné   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    ÚfC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/conch/test/test_connection.pyÚSSHConnectionr      s   † Úr   r   r   N)r   r   r   r   r   r   r   r   r   r   r      s   † ÷	ô 	r   r   c                   óZ   • \ rS rSrSrSrSrSrS rS r	S r
S rS	 rS
 rS rS rS rSrg)ÚTestChannelé   az  
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                 ó    • SU R                   -  $ )NzTestChannel %i)Úid©Úselfs    r   Ú	logPrefixÚTestChannel.logPrefix:   s   € Ø $§'¡'Ñ)Ð)r   c                 ór   • SU l         Xl        / U l        / U l        SU l        SU l        SU l        SU l        g)z6
The channel is open.  Set up the instance variables.
Tr   FN)ÚgotOpenÚspecificDataÚinBufferÚ	extBufferÚnumberRequestsÚgotEOFÚgotOneCloseÚ	gotClosed)r!   r&   s     r   ÚchannelOpenÚTestChannel.channelOpen=   s=   € ð ˆŒØ(ÔØˆŒØˆŒØˆÔØˆŒØ ˆÔØˆ�r   c                 ó   • Xl         g)z4
Opening the channel failed.  Store the reason why.
N)ÚopenFailureReason)r!   Úreasons     r   Ú
openFailedÚTestChannel.openFailedJ   s
   € ð "(Õr   c                 ó6   • U =R                   S-  sl         US:H  $ )zG
A test request.  Return True if data is 'data'.

@type data: L{bytes}
é   ó   data)r)   ©r!   Údatas     r   Úrequest_testÚTestChannel.request_testP   s   € ð 	×Ò˜qÑ ÕØ�w‰Ðr   c                 ó:   • U R                   R                  U5        g)z-
Data was received.  Store it in the buffer.
N)r'   Úappendr7   s     r   ÚdataReceivedÚTestChannel.dataReceivedY   s   € ð 	�‰×Ñ˜TÕ"r   c                 ó<   • U R                   R                  X45        g)z6
Extended data was received.  Store it in the buffer.
N)r(   r<   )r!   Úcoder8   s      r   ÚextReceivedÚTestChannel.extReceived_   s   € ð 	�‰×Ñ˜t˜lÕ+r   c                 ó   • SU l         g)z!
EOF was received.  Remember it.
TN)r*   r    s    r   ÚeofReceivedÚTestChannel.eofReceivede   s   € ð ˆ�r   c                 ó   • SU l         g)z#
Close was received.  Remember it.
TN)r+   r    s    r   ÚcloseReceivedÚTestChannel.closeReceivedk   s   € ð  ˆÕr   c                 ó   • SU l         g)z'
The channel is closed.  Rembember it.
TN)r,   r    s    r   ÚclosedÚTestChannel.closedq   s   € ð ˆ�r   )	r(   r,   r*   r+   r%   r'   r)   r0   r&   N)r   r   r   r   Ú__doc__Únamer%   r,   r"   r-   r2   r9   r=   rA   rD   rG   rJ   r   r   r   r   r   r      sE   † ñð2 €DØ€GØ€Iò*òò(òò#ò,òò õr   r   c                   ó(   • \ rS rSrSrSrS rS rSrg)Ú
TestAvataréx   z7
A mocked-up version of twisted.conch.avatar.ConchUser
é{   c                 ó’   • U[         R                  :X  a  [        UUUU S9$ US:X  a!  [        R                  " U R                  S5      eg)zz
The server wants us to return a channel.  If the requested channel is
our TestChannel, return it, otherwise return None.
)ÚremoteWindowÚremoteMaxPacketr8   Úavataró   conch-error-argsúerror args in wrong orderN)r   rM   r	   Ú
ConchErrorÚ_ARGS_ERROR_CODE)r!   ÚchannelTypeÚ
windowSizeÚ	maxPacketr8   s        r   ÚlookupChannelÚTestAvatar.lookupChannel   sW   € ð
 œ+×*Ñ*Ó*ÜØ'Ø )ØØñ	ð ð Ð/Ó/ô
 ×"Ò" 4×#8Ñ#8Ð:UÓVÐVð 0r   c                 ó&   • US:X  a  gUS:X  a  SU4$ g)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!   ÚrequestTyper8   s      r   ÚgotGlobalRequestÚTestAvatar.gotGlobalRequest’   s$   € ð ˜-Ó'ØØ˜KÓ'Ø˜�:Ðàr   r   N)	r   r   r   r   rL   rY   r]   rc   r   r   r   r   rO   rO   x   s   † ñð ÐòWõ&r   rO   c                   óH   • \ rS rSrSr\(       d  SrS rS rS r	S r
S rS	rg
)ÚTestConnectioné¡   zm
A subclass of SSHConnection for testing.

@ivar channel: the current channel.
@type channel. C{TestChannel}
úCannot run without cryptographyc                 ó   • g)Nrf   r   r    s    r   r"   ÚTestConnection.logPrefix¬   s   € Ør   c                 ó   • g)zD
The other side made the 'TestGlobal' global request.  Return True.
Tr   r7   s     r   Úglobal_TestGlobalÚ TestConnection.global_TestGlobal¯   s   € ð r   c                 ó
   • SU4$ )z\
The other side made the 'Test-Data' global request.  Return True and
the data we received.
Tr   r7   s     r   Úglobal_Test_DataÚTestConnection.global_Test_Dataµ   s   € ð
 �TˆzÐr   c                 ó8   • [        XUS9U l        U R                  $ )zk
The other side is requesting the TestChannel.  Create a C{TestChannel}
instance, store it, and return it.
)rS   rT   r8   )r   r   ©r!   r[   r\   r8   s       r   Úchannel_TestChannelÚ"TestConnection.channel_TestChannel¼   s!   € ô
 #Ø#ÀTñ
ˆŒð �|‰|Ðr   c                 ó   • [        S5      e)zE
The other side is requesting the ErrorChannel.  Raise an exception.
zno such thing)ÚAssertionErrorrr   s       r   Úchannel_ErrorChannelÚ#TestConnection.channel_ErrorChannelÆ   s   € ô ˜_Ó-Ð-r   r   N)r   r   r   r   rL   r   Úskipr"   rl   ro   rs   rw   r   r   r   r   rf   rf   ¡   s*   † ñö Ø0ˆò òòòõ.r   rf   c                   óì   • \ rS rSr\(       d  SrS rS rS rS r	S r
S rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S  r#S! r$S" r%S# r&S$r'g%)&ÚConnectionTestséÍ   rh   c                 óô   • [         R                  " S 5      U l        [        5       U R                  l        [        5       U l        U R                  U R                  l        U R                  R                  5         g ©N)r   ÚFakeTransportÚ	transportrO   rU   rf   ÚconnÚserviceStartedr    s    r   ÚsetUpÚConnectionTests.setUpÑ   sL   € Ü&×4Ò4°TÓ:ˆŒÜ *£ˆ�‰ÔÜ"Ó$ˆŒ	Ø"Ÿn™nˆ�	‰	ÔØ�	‰	× Ñ Õ"r   c                 ó  • U R                   R                  U5        U R                  R                  SS U R                  l        U R                   R	                  [
        R                  " SUR                  S5      S-   5        g)z/
Open the channel with the default connection.
Néÿÿÿÿz>2Léÿ   s        € )r�   ÚopenChannelr€   ÚpacketsÚssh_CHANNEL_OPEN_CONFIRMATIONÚstructÚpackr   ©r!   r   s     r   Ú_openChannelÚConnectionTests._openChannelØ   s_   € ð 	�	‰	×Ñ˜gÔ&Ø!%§¡×!7Ñ!7¸¸Ð!<ˆ�‰ÔØ�	‰	×/Ñ/Ü�KŠK˜˜wŸz™z¨3Ó/Ð2UÑUõ	
r   c                 ó8   • U R                   R                  5         g r~   )r�   ÚserviceStoppedr    s    r   ÚtearDownÚConnectionTests.tearDownâ   s   € Ø�	‰	× Ñ Õ"r   c                 óx   • U R                  U R                  R                  R                  U R                  5        g)zG
Test that the connection links itself to the avatar in the
transport.
N)ÚassertIsr€   rU   r�   r    s    r   Útest_linkAvatarÚConnectionTests.test_linkAvatarå   s&   € ð
 	�‰�d—n‘n×+Ñ+×0Ñ0°$·)±)Õ<r   c                 óÀ  • [        5       n[        5       nU R                  R                  U5        U R                  R                  U5        U R                  R                  S5        U R	                  UR
                  5        U R                  UR                  5        U R                  UR
                  5        U R                  UR                  5        U R                  R                  5         U R	                  UR                  5        U R                  UR
                  5        U R                  UR                  5        SSK	J
n  U R                  UR                  U5        g)z6
Test that serviceStopped() closes any open channels.
s                   r   )ÚConnectionLostN)r   r�   rˆ   rŠ   Ú
assertTruer%   ÚassertFalser,   r‘   Útwisted.internet.errorr™   ÚassertIsInstancer0   )r!   Úchannel1Úchannel2r™   s       r   Útest_serviceStoppedÚ#ConnectionTests.test_serviceStoppedì   sú   € ô “=ˆÜ“=ˆØ�	‰	×Ñ˜hÔ'Ø�	‰	×Ñ˜hÔ'Ø�	‰	×/Ñ/Ð0GÔHØ�‰˜×(Ñ(Ô)Ø×Ñ˜×+Ñ+Ô,Ø×Ñ˜×)Ñ)Ô*Ø×Ñ˜×+Ñ+Ô,Ø�	‰	× Ñ Ô"Ø�‰˜×*Ñ*Ô+Ø×Ñ˜×)Ñ)Ô*Ø×Ñ˜×+Ñ+Ô,Ý9à×Ñ˜h×8Ñ8¸.ÕIr   c                 ó–  • U R                   R                  [        R                  " S5      S-   5        U R	                  U R
                  R                  [        R                  S4/5        / U R
                  l        U R                   R                  [        R                  " S5      S-   S-   5        U R	                  U R
                  R                  [        R                  S4/5        / U R
                  l        U R                   R                  [        R                  " S5      S-   5        U R	                  U R
                  R                  [        R                  S4/5        / U R
                  l        U R                   R                  [        R                  " S5      S-   5        U R	                  U R
                  R                  / 5        g)	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   ra   s	   test datas   TestBadó    N)
r�   Ússh_GLOBAL_REQUESTr
   ÚNSÚassertEqualr€   r‰   r   ÚMSG_REQUEST_SUCCESSÚMSG_REQUEST_FAILUREr    s    r   Útest_GLOBAL_REQUESTÚ#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                 óÜ   ^ • T R                   R                  SSS5      nT R                   R                  S5        U 4S jnUR                  U5        UR	                  T R
                  5        U$ )zP
Test that global request success packets cause the Deferred to be
called back.
ó   requestr6   Tc                 ó*   >• TR                  U S5        g ©Nr6   )r§   )r8   r!   s    €r   ÚcheckÚ3ConnectionTests.test_REQUEST_SUCCESS.<locals>.check!  s   ø€ Ø×Ñ˜T 7Õ+r   )r�   ÚsendGlobalRequestÚssh_REQUEST_SUCCESSÚaddCallbackÚ
addErrbackÚfail©r!   Údr°   s   `  r   Útest_REQUEST_SUCCESSÚ$ConnectionTests.test_REQUEST_SUCCESS  sW   ø€ ð
 �I‰I×'Ñ'¨
°G¸TÓBˆØ�	‰	×%Ñ% gÔ.õ	,ð 	
�‰�eÔØ	�‰�T—Y‘YÔØˆr   c                 óÜ   ^ • T R                   R                  SSS5      nT R                   R                  S5        U 4S jnUR                  T R                  5        UR                  U5        U$ )zO
Test that global request failure packets cause the Deferred to be
erred back.
r­   r6   Tc                 óR   >• TR                  U R                  R                  S5        g r¯   )r§   Úvaluer8   )Úfr!   s    €r   r°   Ú3ConnectionTests.test_REQUEST_FAILURE.<locals>.check0  s   ø€ Ø×Ñ˜QŸW™WŸ\™\¨7Õ3r   )r�   r²   Ússh_REQUEST_FAILUREr´   r¶   rµ   r·   s   `  r   Útest_REQUEST_FAILUREÚ$ConnectionTests.test_REQUEST_FAILURE(  sW   ø€ ð
 �I‰I×'Ñ'¨
°G¸TÓBˆØ�	‰	×%Ñ% gÔ.õ	4ð 	
�‰�d—i‘iÔ Ø	�‰�UÔØˆr   c                 ó   • U R                   ?U R                  R                  [        R
                  " S5      S-   5        U R                  U R                  R                  R                  5        U R                  U R                  R                  R                  U R                  5        U R                  U R                  R                  R                  S5        U R                  U R                  R                  R                  S5        U R                  U R                  R                  R                  S5        U R                  U R                  R                  R                  S5        U R                  U R                   R                  [        R                   S4/5        / U R                   l        U R                  R                  [        R
                  " S5      S-   5        U R#                  5         U R                  U R                   R                  [        R$                  S[        R
                  " S	5      -   [        R
                  " S
5      -   4/5        / U R                   l        U R                  R                  [        R
                  " S5      S-   5        U R#                  5         U R                  U R                   R                  [        R$                  S[        R
                  " S5      -   [        R
                  " S
5      -   4/5        g)zn
Test that open channel packets cause a channel to be created and
opened or a failure message to be returned.
r   ó               ó      r5   s               € ó
   BadChannels               s         s   unknown channelr   s   ErrorChannels         s   unknown failureN)r€   rU   r�   Ússh_CHANNEL_OPENr
   r¦   rš   r   r%   r§   r8   r&   ÚremoteWindowLeftrT   r‰   r   ÚMSG_CHANNEL_OPEN_CONFIRMATIONÚflushLoggedErrorsÚMSG_CHANNEL_OPEN_FAILUREr    s    r   Útest_CHANNEL_OPENÚ!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                 ó6  • XR                   R                  l        U R                  R	                  [
        R                  " S5      S-   5        U R                  [        R                  5      nU R                  [        U5      SSU< 35        U R                  US   R                  R                  S5        U R                  U R                   R                  [        R                   S[
        R                  " S5      -   [
        R                  " S	5      -   4/5        g
)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.
rV   rÄ   r5   zExpected one error, got: r   )rQ   rW   s         {s   error args in wrong orderr   N)r€   rU   rY   r�   rÇ   r
   r¦   rÊ   r	   rX   r§   Úlenr½   Úargsr‰   r   rË   )r!   r@   Úerrorss      r   Ú_lookupChannelErrorTestÚ'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                 ó&   • U R                  S5        g)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.
rQ   N)rÒ   r    s    r   Útest_lookupChannelErrorÚ'ConnectionTests.test_lookupChannelError‡  s   € ð 	×$Ñ$ SÕ)r   c                 óÐ  • [        5       nU R                  R                  U5        U R                  R                  S5        U R	                  UR
                  S5        U R	                  UR                  S5        U R	                  UR                  S5        U R	                  U R                  R                  U   S5        U R	                  U R                  R                  S   S5        g)z^
Test that channel open confirmation packets cause the channel to be
notified that it's open.
s                       r   ó       N)
r   r�   rˆ   rŠ   r§   rÈ   rT   r&   ÚchannelsToRemoteChannelÚlocalToRemoteChannelr�   s     r   Útest_CHANNEL_OPEN_CONFIRMATIONÚ.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                 óf  • [        5       nU R                  R                  U5        U R                  R                  S[        R
                  " S5      -   5        U R                  UR                  R                  S5        U R                  U R                  R                  R                  U5      5        g)zb
Test that channel open failure packets cause the channel to be
notified that its opening failed.
ó          ó   failure!)rß   r5   N)r   r�   rˆ   Ússh_CHANNEL_OPEN_FAILUREr
   r¦   r§   r0   rÐ   ÚassertIsNoneÚchannelsÚgetr�   s     r   Útest_CHANNEL_OPEN_FAILUREÚ)ConnectionTests.test_CHANNEL_OPEN_FAILURE¢  s‚   € ô
 “-ˆØ�	‰	×Ñ˜gÔ&Ø�	‰	×*Ñ*Ø3´f·i²iÀÓ6LÑLô	
ð 	×Ñ˜×2Ñ2×7Ñ7Ð9IÔJØ×Ñ˜$Ÿ)™)×,Ñ,×0Ñ0°Ó9Õ:r   c                 óÆ   • [        5       nU R                  U5        UR                  nU R                  R	                  S5        U R                  UR                  US-   5        g)zK
Test that channel window adjust messages add bytes to the channel
window.
rÞ   r5   N)r   rŽ   rÈ   r�   Ússh_CHANNEL_WINDOW_ADJUSTr§   )r!   r   ÚoldWindowSizes      r   Útest_CHANNEL_WINDOW_ADJUSTÚ*ConnectionTests.test_CHANNEL_WINDOW_ADJUST¯  sR   € ô
 “-ˆØ×Ñ˜'Ô"Ø×0Ñ0ˆØ�	‰	×+Ñ+Ð,SÔTØ×Ñ˜×1Ñ1°=À1Ñ3DÕEr   c                 ó  • [        SSS9nU R                  U5        U R                  R                  S[        R
                  " S5      -   5        U R                  UR                  S/5        U R                  U R                  R                  [        R                  S4/5        / U R                  l	        SUR                  S-   -  nU R                  R                  S[        R
                  " U5      -   5        U R                  UR                  S/5        U R                  U R                  R                  [        R                  S	4/5        [        5       nU R                  U5        SUR                  S-   -  n/ U R                  l	        U R                  R                  S
[        R
                  " U5      -   5        U R                  UR                  / 5        U R                  U R                  R                  [        R                  S	4/5        g)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Ø   r6   ó      ÿ   ó   ar5   ó      ÿrÅ   N)r   rŽ   r�   Ússh_CHANNEL_DATAr
   r¦   r§   r'   r€   r‰   r   ÚMSG_CHANNEL_WINDOW_ADJUSTÚlocalWindowLeftÚMSG_CHANNEL_CLOSErð   ©r!   r   ÚlongDataÚbigDatas       r   Útest_CHANNEL_DATAÚ!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                 ó  • [        SSS9nU R                  U5        U R                  R                  S[        R
                  " S5      -   5        U R                  UR                  S/5        U R                  U R                  R                  [        R                  S4/5        / U R                  l	        SUR                  S	-   -  nU R                  R                  S[        R
                  " U5      -   5        U R                  UR                  S/5        U R                  U R                  R                  [        R                  S
4/5        [        5       nU R                  U5        SUR                  S	-   -  n/ U R                  l	        U R                  R                  S[        R
                  " U5      -   5        U R                  UR                  / 5        U R                  U R                  R                  [        R                  S
4/5        g)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           r6   )r   r6   rñ   rò   r5   ró   s          N)r   rŽ   r�   Ússh_CHANNEL_EXTENDED_DATAr
   r¦   r§   r(   r€   r‰   r   rõ   rö   r÷   rð   rø   s       r   Útest_CHANNEL_EXTENDED_DATAÚ*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                 ó¦   • [        5       nU R                  U5        U R                  R                  S5        U R	                  UR
                  5        g)z>
Test that channel eof messages are passed up to the channel.
rØ   N)r   rŽ   r�   Ússh_CHANNEL_EOFrš   r*   r�   s     r   Útest_CHANNEL_EOFÚ ConnectionTests.test_CHANNEL_EOF
  s<   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×!Ñ!Ð"5Ô6Ø�‰˜Ÿ™Õ'r   c                 ó´  • [        5       nU R                  U5        U R                  UR                  5        U R	                  UR
                  5        U R	                  UR                  5        U R                  R                  U5        U R                  R                  S5        U R                  UR
                  5        U R                  UR                  5        g)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   rŽ   rš   r%   r›   r+   r,   r�   Ú	sendCloseÚssh_CHANNEL_CLOSEr�   s     r   Útest_CHANNEL_CLOSEÚ"ConnectionTests.test_CHANNEL_CLOSE  sš   € ô “-ˆØ×Ñ˜'Ô"Ø�‰˜Ÿ™Ô(Ø×Ñ˜×,Ñ,Ô-Ø×Ñ˜×*Ñ*Ô+Ø�	‰	×Ñ˜GÔ$Ø�	‰	×#Ñ#Ð$7Ô8Ø�‰˜×+Ñ+Ô,Ø�‰˜×)Ñ)Õ*r   c                 ó~  ^ • [        5       nT R                  U5        T R                  R                  S[        R
                  " S5      -   S-   5        T R                  UR                  S5        T R                  R                  S[        R
                  " S5      -   S-   S-   5      nU 4S jnUR                  U5        U$ )zC
Test that channel requests that succeed send MSG_CHANNEL_SUCCESS.
rØ   ó   testr¤   r5   r£   r6   c                 ót   >• TR                  TR                  R                  [        R                  S4/5        g ©Nró   )r§   r€   r‰   r   ÚMSG_CHANNEL_SUCCESS©Úresultr!   s    €r   r°   Ú;ConnectionTests.test_CHANNEL_REQUEST_success.<locals>.check1  ó0   ø€ Ø×ÑØ—‘×&Ñ&Ü×0Ñ0Ð2EÐFÐGõr   )	r   rŽ   r�   Ússh_CHANNEL_REQUESTr
   r¦   r§   r)   r´   ©r!   r   r¸   r°   s   `   r   Útest_CHANNEL_REQUEST_successÚ,ConnectionTests.test_CHANNEL_REQUEST_success#  s¡   ø€ ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×%Ñ%Ø¤&§)¢)¨GÓ"4Ñ4°wÑ>ô	
ð 	×Ñ˜×/Ñ/°Ô3Ø�I‰I×)Ñ)Ø¤&§)¢)¨GÓ"4Ñ4°wÑ>ÀÑHó
ˆõ	ð 	
�‰�eÔØˆr   c                 ó  ^ • [        5       nT R                  U5        T R                  R                  S[        R
                  " S5      -   S-   5      nU 4S jnUR                  T R                  5        UR                  U5        U$ )z@
Test that channel requests that fail send MSG_CHANNEL_FAILURE.
rØ   r  r£   c                 ót   >• TR                  TR                  R                  [        R                  S4/5        g r  )r§   r€   r‰   r   ÚMSG_CHANNEL_FAILUREr  s    €r   r°   Ú;ConnectionTests.test_CHANNEL_REQUEST_failure.<locals>.checkD  r  r   )	r   rŽ   r�   r  r
   r¦   r´   r¶   rµ   r  s   `   r   Útest_CHANNEL_REQUEST_failureÚ,ConnectionTests.test_CHANNEL_REQUEST_failure:  sl   ø€ ô “-ˆØ×Ñ˜'Ô"Ø�I‰I×)Ñ)Ø¤&§)¢)¨GÓ"4Ñ4°wÑ>ó
ˆõ	ð 	
�‰�d—i‘iÔ Ø	�‰�UÔØˆr   c                 ó¼   ^ • [        5       nT R                  U5        T R                  R                  USSS5      nT R                  R	                  S5        U 4S jnU$ )zR
Test that channel request success messages cause the Deferred to be
called back.
r  r6   TrØ   c                 ó(   >• TR                  U 5        g r~   )rš   r  s    €r   r°   Ú;ConnectionTests.test_CHANNEL_REQUEST_SUCCESS.<locals>.checkX  s   ø€ Ø�O‰O˜FÕ#r   )r   rŽ   r�   ÚsendRequestÚssh_CHANNEL_SUCCESSr  s   `   r   Útest_CHANNEL_REQUEST_SUCCESSÚ,ConnectionTests.test_CHANNEL_REQUEST_SUCCESSN  sS   ø€ ô
 “-ˆØ×Ñ˜'Ô"Ø�I‰I×!Ñ! '¨7°G¸TÓBˆØ�	‰	×%Ñ%Ð&9Ô:õ	$ð ˆr   c                 ó  ^ • [        5       nT R                  U5        T R                  R                  USSS5      nT R                  R	                  S5        U 4S jnUR                  T R                  5        UR                  U5        U$ )zQ
Test that channel request failure messages cause the Deferred to be
erred back.
r  r   TrØ   c                 óR   >• TR                  U R                  R                  S5        g )Nzchannel request failed)r§   r½   r  s    €r   r°   Ú;ConnectionTests.test_CHANNEL_REQUEST_FAILURE.<locals>.checkg  s   ø€ Ø×Ñ˜VŸ\™\×/Ñ/Ð1IÕJr   )r   rŽ   r�   r   Ússh_CHANNEL_FAILUREr´   r¶   rµ   r  s   `   r   Útest_CHANNEL_REQUEST_FAILUREÚ,ConnectionTests.test_CHANNEL_REQUEST_FAILURE]  sp   ø€ ô
 “-ˆØ×Ñ˜'Ô"Ø�I‰I×!Ñ! '¨7°C¸Ó>ˆØ�	‰	×%Ñ%Ð&9Ô:õ	Kð 	
�‰�d—i‘iÔ Ø	�‰�UÔØˆr   c                 óÚ  • U R                   R                  SSS5      nUR                  S 5        U R                   R                  SSS5        U R                  U R                  R
                  [        R                  [        R                  " S5      S-   4[        R                  [        R                  " S5      S	-   4/5        U R                  U R                   R                  S
U/05        g)zA
Test that global request messages are sent in the right format.
s	   wantReplyr6   Tc                 ó   • g r~   r   ©Úfailures    r   Ú<lambda>Ú8ConnectionTests.test_sendGlobalRequest.<locals>.<lambda>t  ó   €  Tr   s   noReplyr   Fs   ÿdatar¤   ÚglobalN)r�   r²   rµ   r§   r€   r‰   r   ÚMSG_GLOBAL_REQUESTr
   r¦   Ú	deferreds©r!   r¸   s     r   Útest_sendGlobalRequestÚ&ConnectionTests.test_sendGlobalRequestn  s¹   € ð �I‰I×'Ñ'¨°g¸tÓDˆà	�‰Ñ)Ô*Ø�	‰	×#Ñ# J°°UÔ;Ø×ÑØ�N‰N×"Ñ"ä×.Ñ.´·	²	¸,Ó0GÈ+Ñ0UÐVÜ×.Ñ.´·	²	¸*Ó0EÈÑ0OÐPðô	
ð 	×Ñ˜Ÿ™×,Ñ,¨x¸!¸¨oÕ>r   c                 óp  • [        5       nU R                  R                  US5        U R                  U R                  R
                  [        R                  [        R                  " S5      S-   4/5        U R                  UR                  S5        U R                  U R                  R                  S5        g)z?
Test that open channel messages are sent in the right format.
s   aaaar   s            € aaaar   r5   N)r   r�   rˆ   r§   r€   r‰   r   ÚMSG_CHANNEL_OPENr
   r¦   r   ÚlocalChannelIDr�   s     r   Útest_openChannelÚ ConnectionTests.test_openChannel  s”   € ô “-ˆØ�	‰	×Ñ˜g wÔ/Ø×ÑØ�N‰N×"Ñ"ô ×/Ñ/Ü—I’I˜nÓ-ØMñNððô		
ð 	×Ñ˜Ÿ™ QÔ'Ø×Ñ˜Ÿ™×1Ñ1°1Õ5r   c           	      ól  • [        5       nU R                  U5        U R                  R                  USSS5      nUR	                  S 5        U R                  R                  USSS5        SUl        U R                  R                  USSS5        U R                  U R                  R                  [        R                  S[        R                  " S5      -   S	-   4[        R                  S[        R                  " S5      -   S
-   4/5        U R                  U R                  R                  S   U/5        g)zB
Test that channel request messages are sent in the right format.
r  Tc                 ó   • g r~   r   r,  s    r   r.  Ú2ConnectionTests.test_sendRequest.<locals>.<lambda>š  r0  r   ó   test2r   Fs   test3ró   s   testr¤   r   N)r   rŽ   r�   r   rµ   ÚlocalClosedr§   r€   r‰   r   ÚMSG_CHANNEL_REQUESTr
   r¦   r3  ©r!   r   r¸   s      r   Útest_sendRequestÚ 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                 ó¢  • [        SS9nU R                  U5        SUl        U R                  R	                  US5        U R                  UR                  S5        SUl        U R                  R	                  US5        U R                  UR                  S5        U R                  U R                  R                  [        R                  S4/5        g)	zQ
Test that channel window adjust messages cause bytes to be added
to the window.
rí   )rï   r   r5   Té   ó      ÿ   N)r   rŽ   rö   r�   ÚadjustWindowr§   r@  r€   r‰   r   rõ   r�   s     r   Útest_adjustWindowÚ!ConnectionTests.test_adjustWindow­  s³   € ô
 ¨!Ñ,ˆØ×Ñ˜'Ô"Ø"#ˆÔØ�	‰	×Ñ˜w¨Ô*Ø×Ñ˜×0Ñ0°!Ô4Ø"ˆÔØ�	‰	×Ñ˜w¨Ô*Ø×Ñ˜×0Ñ0°!Ô4Ø×ÑØ�N‰N×"Ñ"ô ×8Ñ8Ø;ððõ	
r   c                 óT  • [        5       nU R                  U5        U R                  R                  US5        SUl        U R                  R                  US5        U R                  U R                  R                  [        R                  S[        R                  " S5      -   4/5        g)z?
Test that channel data messages are sent in the right format.
rò   Tó   bró   N)r   rŽ   r�   ÚsendDatar@  r§   r€   r‰   r   ÚMSG_CHANNEL_DATAr
   r¦   r�   s     r   Útest_sendDataÚConnectionTests.test_sendDataÄ  sƒ   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×Ñ˜7 DÔ)Ø"ˆÔØ�	‰	×Ñ˜7 DÔ)Ø×ÑØ�N‰N×"Ñ"Ü×)Ñ)Ð+>ÄÇÂÈ4ÃÑ+PÐQÐRõ	
r   c                 óX  • [        5       nU R                  U5        U R                  R                  USS5        SUl        U R                  R                  USS5        U R                  U R                  R                  [        R                  S[        R                  " S5      -   4/5        g)zH
Test that channel extended data messages are sent in the right format.
r5   r  TrF  r?  rG  N)r   rŽ   r�   ÚsendExtendedDatar@  r§   r€   r‰   r   ÚMSG_CHANNEL_EXTENDED_DATAr
   r¦   r�   s     r   Útest_sendExtendedDataÚ%ConnectionTests.test_sendExtendedDataÒ  sŽ   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×"Ñ" 7¨A¨wÔ7Ø"ˆÔØ�	‰	×"Ñ" 7¨A¨xÔ8Ø×ÑØ�N‰N×"Ñ"ô ×8Ñ8Ø=ÄÇ	Â	È'Ó@RÑRððõ	
r   c                 ó�  • [        5       nU R                  U5        U R                  R                  U5        U R	                  U R
                  R                  [        R                  S4/5        SUl	        U R                  R                  U5        U R	                  U R
                  R                  [        R                  S4/5        g)z>
Test that channel EOF messages are sent in the right format.
ró   TN)
r   rŽ   r�   ÚsendEOFr§   r€   r‰   r   ÚMSG_CHANNEL_EOFr@  r�   s     r   Útest_sendEOFÚConnectionTests.test_sendEOFå  sŸ   € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×Ñ˜'Ô"Ø×ÑØ�N‰N×"Ñ"¤j×&@Ñ&@ÐBUÐ%VÐ$Wô	
ð #ˆÔØ�	‰	×Ñ˜'Ô"Ø×ÑØ�N‰N×"Ñ"¤j×&@Ñ&@ÐBUÐ%VÐ$Wõ	
r   c                 óÔ  • [        5       nU R                  U5        U R                  R                  U5        U R	                  UR
                  5        U R                  U R                  R                  [        R                  S4/5        U R                  R                  U5        U R                  U R                  R                  [        R                  S4/5        [        5       nU R                  U5        U R	                  UR                  5        U R                  UR                  5        SUl        U R                  R                  U5        U R	                  UR                  5        g)z@
Test that channel close messages are sent in the right format.
ró   TN)r   rŽ   r�   r  rš   r@  r§   r€   r‰   r   r÷   r%   r›   r,   ÚremoteClosed)r!   r   rŸ   s      r   Útest_sendCloseÚConnectionTests.test_sendCloseõ  s  € ô “-ˆØ×Ñ˜'Ô"Ø�	‰	×Ñ˜GÔ$Ø�‰˜×+Ñ+Ô,Ø×ÑØ�N‰N×"Ñ"Ü×*Ñ*Ð,?Ð@ÐAô	
ð 	�	‰	×Ñ˜GÔ$Ø×ÑØ�N‰N×"Ñ"Ü×*Ñ*Ð,?Ð@ÐAô	
ô
 “=ˆØ×Ñ˜(Ô#Ø�‰˜×(Ñ(Ô)Ø×Ñ˜×+Ñ+Ô,Ø $ˆÔØ�	‰	×Ñ˜HÔ%Ø�‰˜×*Ñ*Õ+r   c                 óX  • U R                   R                  SSSS5      nU R                  UR                  S5        U R                  UR                  S5        U R                  UR
                  S5        U R                  [        R                  U R                   R                  SSSS5        g)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   é   r6   rÆ   N)	r�   Ú
getChannelr§   r8   rÈ   rT   ÚassertRaisesr	   rX   r�   s     r   Útest_getChannelWithAvatarÚ)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                 ó   • U R                   ?U R                  U R                  R	                  SS5      5        U R                  U R                  R	                  SS5      S5        U R                  U R                  R	                  SS5      5        g)zG
Test that gotGlobalRequests dispatches to global_* without an avatar.
r`   r6   s	   Test-Data)Tr6   s	   BadGlobalN)r€   rU   rš   r�   rc   r§   r›   r    s    r   Ú"test_gotGlobalRequestWithoutAvatarÚ2ConnectionTests.test_gotGlobalRequestWithoutAvatar  sp   € ð �N‰NÐ!Ø�‰˜Ÿ	™	×2Ñ2°=À'ÓJÔKØ×ÑØ�I‰I×&Ñ& |°WÓ=¸ô	
ð 	×Ñ˜Ÿ™×3Ñ3°LÀ'ÓJÕKr   c                 óê   • [        5       nU R                  U5        U R                  R                  USSSS9nU R	                  U[
        R                  5      nU R                  R                  U5        U$ )zƒ
Whenever an SSH channel gets closed any Deferred that was returned by a
sendRequest() on its parent connection must be errbacked.
ó   dummyrequestó	   dummydatar5   ©Ú	wantReply)r   rŽ   r�   r   ÚassertFailurer	   rX   ÚchannelClosedrB  s      r   Ú9test_channelClosedCausesLeftoverChannelDeferredsToErrbackÚIConnectionTests.test_channelClosedCausesLeftoverChannelDeferredsToErrback(  sf   € ô
 “-ˆØ×Ñ˜'Ô"à�I‰I×!Ñ! '¨?¸LÐTUÐ!ÐVˆØ×Ñ˜q¤%×"2Ñ"2Ó3ˆØ�	‰	×Ñ Ô(Øˆr   ©r�   r€   N)(r   r   r   r   r   ry   rƒ   rŽ   r’   r–   r    rª   r¹   rÁ   rÌ   rÒ   rÕ   rÛ   rä   ré   rû   rÿ   r  r  r  r  r"  r(  r5  r:  rC  rI  rO  rT  rY  r]  rd  rg  rp  r   r   r   r   r{   r{   Í   sµ   † ÞØ0ˆò#ò
ò#ò=òJò*5ò0òò2
òh
ò8*ò?ò;ò	Fò#
òJ)
òV(ò+ò ò.ò(òò"?ò"6ò&6ò6
ò.
ò
ò&
ò ,ò4
ò	Lõr   r{   c                   ó6   • \ rS rSrSr\(       d  SrS rS rSr	g)ÚCleanConnectionShutdownTestsi6  zD
Check whether correct cleanup is performed on connection shutdown.
rh   c                 óÀ   • [         R                  " S 5      U l        [        5       U R                  l        [        5       U l        U R                  U R                  l        g r~   )r   r   r€   rO   rU   rf   r�   r    s    r   rƒ   Ú"CleanConnectionShutdownTests.setUp>  s<   € Ü&×4Ò4°TÓ:ˆŒÜ *£ˆ�‰ÔÜ"Ó$ˆŒ	Ø"Ÿn™nˆ�	‰	Õr   c                 óä   • U R                   R                  5         U R                   R                  SSSS9nU R                  U[        R
                  5      nU R                   R                  5         U$ )zt
Once the service is stopped any leftover global deferred returned by
a sendGlobalRequest() call must be errbacked.
rj  rk  r5   rl  )r�   r‚   r²   rn  r	   rX   r‘   r4  s     r   Ú9test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackÚVCleanConnectionShutdownTests.test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackD  s]   € ð
 	�	‰	× Ñ Ô"à�I‰I×'Ñ'¨¸ÐQRÐ'ÐSˆØ×Ñ˜q¤%×"2Ñ"2Ó3ˆØ�	‰	× Ñ Ô"Øˆr   rr  N)
r   r   r   r   rL   r   ry   rƒ   rx  r   r   r   r   rt  rt  6  s   † ñö Ø0ˆò-õ
r   rt  )rL   r‹   Útwisted.conch.sshr   Útwisted.conch.testr   Útwisted.python.reflectr   Útwisted.trialr   r   Útwisted.conchr	   r
   r   Ú
SSHChannelr   rO   r   rf   ÚTestCaser{   rt  r   r   r   Ú<module>r�     s•   ðñó å %Ý ,Ý 0Ý "á˜^Ó,€å æß4Ð4÷ñ ô
Y�'×$Ñ$ô Y÷x&ñ &ôR).�Z×-Ñ-ô ).ôXf	�h×'Ñ'ô f	ôR 8×#4Ñ#4õ r   