ó
    Ö›‘h2  ã                  ó  • S r SSKJr  SSKJr  SSKJr   SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SrSSKJr   " S S\5      r  S       SS jjr\" \\5       " S S\5      5       rg! \ a    Sr\r NEf = f)z
Test ssh/channel.py.
é    )Úannotations)ÚskipIf)ÚverifyObject)Úchannel)ÚSSHTransportAddress)Ú
SSHService)ÚSSHServerTransport)Ú
interfaces)ÚIPv4Address)ÚStringTransportÚ zConch SSH not supported.)ÚTestCasec                  óZ   • \ rS rSrSrS
S jrSS jrSS jr        SS jrSS jr	Sr
g	)ÚMockConnectioné   a¹  
A mock for twisted.conch.ssh.connection.SSHConnection.  Record the data
that channels send, and when they try to close the connection.

@ivar data: a L{dict} mapping channel id #s to lists of data sent by that
    channel.
@ivar extData: a L{dict} mapping channel id #s to lists of 2-tuples
    (extended data type, data) sent by that channel.
@ivar closes: a L{dict} mapping channel id #s to True if that channel sent
    a close message.
c                ó.   • 0 U l         0 U l        0 U l        g )N)ÚdataÚextDataÚcloses©Úselfs    ÚcC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/conch/test/test_channel.pyÚ__init__ÚMockConnection.__init__*   s   € Ø;=ˆŒ	ØJLˆŒØ68ˆ�ó    c                ó   • g)z
Return our logging prefix.
r   © r   s    r   Ú	logPrefixÚMockConnection.logPrefix/   s   € ð  r   c                óZ   • U R                   R                  U/ 5      R                  U5        g)z
Record the sent data.
N)r   Ú
setdefaultÚappend)r   r   r   s      r   ÚsendDataÚMockConnection.sendData5   s#   € ð 	�	‰	×Ñ˜W bÓ)×0Ñ0°Õ6r   c                ó\   • U R                   R                  U/ 5      R                  X#45        g)z 
Record the sent extended data.
N)r   r!   r"   )r   r   Útyper   s       r   ÚsendExtendedDataÚMockConnection.sendExtendedData;   s%   € ð 	�‰×Ñ ¨Ó,×3Ñ3°T°LÕAr   c                ó"   • SU R                   U'   g)z/
Record that the channel sent a close message.
TN)r   )r   r   s     r   Ú	sendCloseÚMockConnection.sendCloseC   s   € ð  $ˆ�‰�GÒr   )r   r   r   N©ÚreturnÚNone)r-   Ústr)r   úchannel.SSHChannelr   Úbytesr-   r.   )r   r0   r&   Úintr   r1   r-   r.   )r   r0   r-   r.   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r#   r'   r*   Ú__static_attributes__r   r   r   r   r      sE   † ñ
ô9ô
 ô7ðBØ)ðBØ14ðBØ<AðBà	ôB÷$r   r   Nc                ój   • [        5       nUR                  [        XS95        UR                  U 5        g)a‹  
Connect a SSHTransport which is already connected to a remote peer to
the channel under test.

@param service: Service used over the connected transport.
@type service: L{SSHService}

@param hostAddress: Local address of the connected transport.
@type hostAddress: L{interfaces.IAddress}

@param peerAddress: Remote address of the connected transport.
@type peerAddress: L{interfaces.IAddress}
)ÚhostAddressÚpeerAddressN)r	   ÚmakeConnectionr   Ú
setService)Úservicer:   r;   Ú	transports       r   ÚconnectSSHTransportr@   J   s2   € ô$ #Ó$€IØ×ÑÜ KÑIôð ×Ñ˜Õ!r   c                  ó®   • \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSrg)ÚChannelTestséc   z
Tests for L{SSHChannel}.
c                óŒ   • [        5       U l        [        R                  " U R                  SS9U l        SU R                  l        g)z–
Initialize the channel.  remoteMaxPacket is 10 so that data is able
to be sent (the default of 0 means no data is sent because no packets
are made).
é
   )ÚconnÚremoteMaxPackets   channelN)r   rF   r   Ú
SSHChannelÚnamer   s    r   ÚsetUpÚChannelTests.setUpi   s2   € ô #Ó$ˆŒ	Ü×)Ò)¨t¯y©yÈ"ÑMˆŒØ&ˆ�‰Õr   c                ój   • U R                  [        [        R                  U R                  5      5        g)z;
L{SSHChannel} instances provide L{interfaces.ITransport}.
N)Ú
assertTruer   r
   Ú
ITransportr   r   s    r   Útest_interfaceÚChannelTests.test_interfaces   s!   € ð 	�‰œ¤Z×%:Ñ%:¸D¿L¹LÓIÕJr   c           	     ó  • [         R                  " U R                  S9nU R                  U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                  S5        U R                  UR                  U R                  5        U R                  UR                  5        U R                  UR                  5        [         R                  " SSS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                  U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                  S5        g)aS  
Test that SSHChannel initializes correctly.  localWindowSize defaults
to 131072 (2**17) and localMaxPacket to 32768 (2**15) as reasonable
defaults (what OpenSSH uses for those variables).

The values in the second set of assertions are meaningless; they serve
only to verify that the instance variables are assigned in the correct
order.
)rF   i   i €  r   é   é   é   é   é   é   é   N)r   rH   rF   ÚassertEqualÚlocalWindowSizeÚlocalWindowLeftÚlocalMaxPacketÚremoteWindowLeftrG   ÚassertIsNoner   Úavatar)r   ÚcÚc2s      r   Ú	test_initÚChannelTests.test_inity   sˆ  € ô ×Ò D§I¡IÑ.ˆØ×Ñ˜×*Ñ*¨FÔ3Ø×Ñ˜×*Ñ*¨FÔ3Ø×Ñ˜×)Ñ)¨5Ô1Ø×Ñ˜×+Ñ+¨QÔ/Ø×Ñ˜×*Ñ*¨AÔ.Ø×Ñ˜Ÿ™ §¡Ô+Ø×Ñ˜!Ÿ&™&Ô!Ø×Ñ˜!Ÿ(™(Ô#ä×Ò  1 a¨¨A¨q°!Ó4ˆØ×Ñ˜×+Ñ+¨QÔ/Ø×Ñ˜×+Ñ+¨QÔ/Ø×Ñ˜×*Ñ*¨AÔ.Ø×Ñ˜×,Ñ,¨aÔ0Ø×Ñ˜×+Ñ+¨QÔ/Ø×Ñ˜Ÿ™ !Ô$Ø×Ñ˜Ÿ™ !Ô$Ø×Ñ˜Ÿ™ AÕ&r   c                ó¨   • U R                  [        U R                  5      S5        U R                  [        [        R                  " SS95      S5        g)zc
Test that str(SSHChannel) works gives the channel name and local and
remote windows at a glance..
z%<SSHChannel channel (lw 131072 rw 0)>rR   ©ÚlocalWindowz<SSHChannel None (lw 1 rw 0)>N)rY   r/   r   rH   r   s    r   Útest_strÚChannelTests.test_str—   sB   € ð
 	×Ñœ˜TŸ\™\Ó*Ð,SÔTØ×ÑÜ”×"Ò"¨qÑ1Ó2Ð4Sõ	
r   c                ó¼   • U R                  U R                  R                  5       S5        U R                  [        R                  " SS9R                  5       S5        g)zg
Test that bytes(SSHChannel) works, gives the channel name and
local and remote windows at a glance..

s%   <SSHChannel channel (lw 131072 rw 0)>rR   re   s   <SSHChannel None (lw 1 rw 0)>N)rY   r   Ú	__bytes__rH   r   s    r   Ú
test_bytesÚChannelTests.test_bytes¡   sO   € ð 	×ÑØ�L‰L×"Ñ"Ó$Ð&Nô	
ð 	×ÑÜ×Ò¨1Ñ-×7Ñ7Ó9Ø,õ	
r   c                óX   • U R                  U R                  R                  5       S5        g)zs
Test that SSHChannel.logPrefix gives the name of the channel, the
local channel ID and the underlying connection.
z.SSHChannel channel (unknown) on MockConnectionN)rY   r   r   r   s    r   Útest_logPrefixÚChannelTests.test_logPrefix¯   s%   € ð
 	×ÑØ�L‰L×"Ñ"Ó$Ð&Võ	
r   c                ó6  ^• S/mSU4S jjnXR                   l        U R                   R                  S5        U R                   R                  SS5        U R                   R	                  S5        U R                  U R                   R                  S5        U R                  U R                   R                  5        U R                  TS   5        U R                  U R                   R                  S5        U R                  U R                  R                  U R                      S/5        U R                  U R                   R                  / 5        U R                  U R                  R                  U R                      S	/5        STS'   U R                   R	                  S
5        U R                  TS   5        U R                   R                  S5        U R                   R                  5         U R                   R	                  S
5        U R                  TS   5        g)zY
Test that addWindowBytes adds bytes to the window and resumes writing
if it was paused.
Fc                 ó   >• ST S'   g ©NTr   r   ©Úcbs   €r   ÚstubStartWritingÚ:ChannelTests.test_addWindowBytes.<locals>.stubStartWriting¿   ó   ø€ ØˆBˆqŠEr   ó   testrR   é2   é*   r   r   )rR   rx   é   sP   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaNr,   )r   ÚstartWritingÚwriteÚwriteExtendedÚaddWindowBytesrY   r]   rM   Ú
areWritingÚbufrF   r   ÚextBufr   ÚassertFalseÚloseConnection)r   ru   rt   s     @r   Útest_addWindowBytesÚ ChannelTests.test_addWindowBytes¸   s„  ø€ ð
 ˆWˆ÷	ð %5�‰Ô!Ø�‰×Ñ˜7Ô#Ø�‰×"Ñ" 1 gÔ.Ø�‰×#Ñ# BÔ'Ø×Ñ˜Ÿ™×6Ñ6¸
ÔCØ�‰˜Ÿ™×/Ñ/Ô0Ø�‰˜˜1™ÔØ×Ñ˜Ÿ™×)Ñ)¨3Ô/Ø×Ñ˜Ÿ™Ÿ™¨¯©Ñ5¸°yÔAØ×Ñ˜Ÿ™×,Ñ,¨bÔ1Ø×Ñ˜Ÿ™×*Ñ*¨4¯<©<Ñ8¸<¸.ÔIàˆˆ1‰Ø�‰×#Ñ# BÔ'Ø×Ñ˜˜A™Ôà�‰×Ñ˜9Ô%Ø�‰×#Ñ#Ô%Ø�‰×#Ñ# BÔ'Ø×Ñ˜˜A™Õr   c                ó*  • S U R                   l        U R                  U R                   R                  SS5      5        U R	                  U R                   R                  SS5      5        U R	                  U R                   R                  SS5      5        g)zV
Test that requestReceived handles requests by dispatching them to
request_* methods.
c                ó   • U S:H  $ )Nr   r   )r   s    r   Ú<lambda>Ú3ChannelTests.test_requestReceived.<locals>.<lambda>Ü   s   € ¸Àºr   s   test-methodr   ó   as
   bad-methodN)r   Úrequest_test_methodrM   ÚrequestReceivedrƒ   r   s    r   Útest_requestReceivedÚ!ChannelTests.test_requestReceived×   sl   € ñ
 ,Dˆ�‰Ô(Ø�‰˜Ÿ™×4Ñ4°^ÀSÓIÔJØ×Ñ˜Ÿ™×5Ñ5°nÀdÓKÔLØ×Ñ˜Ÿ™×5Ñ5°mÀSÓIÕJr   c                óÌ   • U R                  U R                  R                  5        U R                  R                  5         U R	                  U R                  R                  5        g)z=
Test that the default closeReceieved closes the connection.
N)rƒ   r   ÚclosingÚcloseReceivedrM   r   s    r   Útest_closeReceievedÚ ChannelTests.test_closeReceievedá   sB   € ð 	×Ñ˜Ÿ™×-Ñ-Ô.Ø�‰×"Ñ"Ô$Ø�‰˜Ÿ™×,Ñ,Õ-r   c                ó\  ^• S/mSU4S jjnXR                   l        U R                   R                  S5        U R                   R                  S5        U R                  U R                   R                  5        U R                  TS   5        U R                   R                  S5        U R                   R                  S5        U R                  R                  U R                      nU R                  USS/5        U R                  U R                   R                  S	5        U R                   R                  S
5        U R                  U/ SQ5        U R                  U R                   R                  S5        STS'   U R                   R                  S5        U R                  U R                   R                  5        U R                  TS   5        U R                  U/ SQ5        U R                  U R                   R                  S5        U R                  U R                   R                  S5        g)z”
Test that write handles data correctly.  Send data up to the size
of the remote window, splitting the data into packets of length
remoteMaxPacket.
Fc                 ó   >• ST S'   g rr   r   rs   s   €r   ÚstubStopWritingÚ0ChannelTests.test_write.<locals>.stubStopWritingñ   rw   r   ó   dr‹   r   r{   ó   taó   daé   ó   12345678901)r›   rš   ó
   1234567890ó   1rV   ó   123456)r›   rš   rž   rŸ   ó   12345ó   6Nr,   )r   ÚstopWritingr}   rƒ   r€   rM   r   rF   r   rY   r]   r�   ©r   r—   r   rt   s      @r   Ú
test_writeÚChannelTests.test_writeé   s–  ø€ ð ˆWˆ÷	ð $3�‰Ô Ø�‰×Ñ˜4Ô Ø�‰×Ñ˜4Ô Ø×Ñ˜Ÿ™×0Ñ0Ô1Ø�‰˜˜1™Ôà�‰×#Ñ# BÔ'Ø�‰×Ñ˜5Ô!Ø�y‰y�~‰~˜dŸl™lÑ+ˆØ×Ñ˜  u˜~Ô.Ø×Ñ˜Ÿ™×6Ñ6¸Ô;à�‰×Ñ˜>Ô*Ø×Ñ˜ÒBÔCØ×Ñ˜Ÿ™×6Ñ6¸Ô:àˆˆ1‰Ø�‰×Ñ˜9Ô%Ø×Ñ˜Ÿ™×0Ñ0Ô1Ø�‰˜˜1™ÔØ×Ñ˜ÒLÔMØ×Ñ˜Ÿ™×)Ñ)¨4Ô0Ø×Ñ˜Ÿ™×6Ñ6¸Õ:r   c                ó¤  ^• S/mSU4S jjnXR                   l        U R                   R                  SS5        U R                   R                  SS5        U R                   R                  SS5        U R                  U R                   R                  5        U R                  TS   5        U R                   R                  S	5        U R                   R                  SS5        U R                  R                  U R                      nU R                  U/ S
Q5        U R                  U R                   R                  S5        U R                   R                  SS5        U R                  U/ SQ5        U R                  U R                   R                  S5        STS'   U R                   R                  SS5        U R                  U R                   R                  5        U R                  TS   5        U R                  U/ SQ5        U R                  U R                   R                  SS//5        U R                  U R                   R                  S5        g)z§
Test that writeExtended handles data correctly.  Send extended data
up to the size of the window, splitting the extended data into packets
of length remoteMaxPacket.
Fc                 ó   >• ST S'   g rr   r   rs   s   €r   r—   Ú8ChannelTests.test_writeExtended.<locals>.stubStopWriting  rw   r   rR   r™   r‹   rS   ó   tr   r{   )©rR   r›   ©rS   rª   ©rS   r‹   rœ   rT   r�   )r«   r¬   r­   ©rT   rž   ©rT   rŸ   rV   rU   r    )r«   r¬   r­   r®   r¯   )rU   r¡   r¢   Nr,   )r   r£   r~   rƒ   r€   rM   r   rF   r   rY   r]   r‚   r¤   s      @r   Útest_writeExtendedÚChannelTests.test_writeExtended  sÅ  ø€ ð ˆWˆ÷	ð $3�‰Ô Ø�‰×"Ñ" 1 dÔ+Ø�‰×"Ñ" 1 dÔ+Ø�‰×"Ñ" 1 dÔ+Ø×Ñ˜Ÿ™×0Ñ0Ô1Ø�‰˜˜1™Ôà�‰×#Ñ# BÔ'Ø�‰×"Ñ" 1 dÔ+Ø�y‰y× Ñ  §¡Ñ.ˆØ×Ñ˜ÒAÔBØ×Ñ˜Ÿ™×6Ñ6¸Ô;à�‰×"Ñ" 1 nÔ5Ø×ÑØÒSô	
ð 	×Ñ˜Ÿ™×6Ñ6¸Ô:àˆˆ1‰Ø�‰×"Ñ" 1 iÔ0Ø×Ñ˜Ÿ™×0Ñ0Ô1Ø�‰˜˜1™ÔØ×ÑØòô
	
ð 	×Ñ˜Ÿ™×,Ñ,°°4¨y¨kÔ:Ø×Ñ˜Ÿ™×6Ñ6¸Õ:r   c                óø   • U R                   R                  S5        U R                   R                  S [        S5       5       5        U R	                  U R
                  R                  U R                      S/5        g)zC
Test that writeSequence is equivalent to write(''.join(sequece)).
r{   c              3  ó.   #   • U  H  nS U4-  v •  M     g7f)s   %dNr   )Ú.0Úis     r   Ú	<genexpr>Ú2ChannelTests.test_writeSequence.<locals>.<genexpr>C  s   é € Ð"Cº°A 5¨A¨4¦<ºùs   ‚rE   s
   0123456789N)r   r   ÚwriteSequenceÚrangerY   rF   r   r   s    r   Útest_writeSequenceÚChannelTests.test_writeSequence>  sU   € ð 	�‰×#Ñ# BÔ'Ø�‰×"Ñ"Ñ"C¼¸r¼Ó"CÔCØ×Ñ˜Ÿ™Ÿ™¨¯©Ñ5¸°ÕGr   c                ó†  • U R                   R                  S5        U R                   R                  SS5        U R                   R                  5         U R	                  U R
                  R                  R                  U R                   5      5        U R                   R                  S5        U R	                  U R
                  R                  R                  U R                   5      5        U R                   R                  S5        U R                  U R
                  R                  R                  U R                   5      5        g)zS
Tesyt that loseConnection() doesn't close the channel until all
the data is sent.
s   datarR   s   datadatarU   é   N)
r   r}   r~   r„   r^   rF   r   Úgetr   rM   r   s    r   Útest_loseConnectionÚ ChannelTests.test_loseConnectionF  sÑ   € ð
 	�‰×Ñ˜7Ô#Ø�‰×"Ñ" 1 kÔ2Ø�‰×#Ñ#Ô%Ø×Ñ˜$Ÿ)™)×*Ñ*×.Ñ.¨t¯|©|Ó<Ô=Ø�‰×#Ñ# AÔ&Ø×Ñ˜$Ÿ)™)×*Ñ*×.Ñ.¨t¯|©|Ó<Ô=Ø�‰×#Ñ# AÔ&Ø�‰˜Ÿ	™	×(Ñ(×,Ñ,¨T¯\©\Ó:Õ;r   c                óÀ   • [        SSS5      n[        U R                  R                  US9  U R	                  [        U5      U R                  R                  5       5        g)zh
L{SSHChannel.getPeer} returns the same object as the underlying
transport's C{getPeer} method returns.
ÚTCPz192.168.0.1i1Ô  )r>   r;   N)r   r@   r   rF   rY   r   ÚgetPeer)r   Úpeers     r   Útest_getPeerÚChannelTests.test_getPeerT  sI   € ô
 ˜5 -°Ó7ˆÜ D§L¡L×$5Ñ$5À4ÒHà×ÑÔ,¨TÓ2°D·L±L×4HÑ4HÓ4JÕKr   c                óÀ   • [        SSS5      n[        U R                  R                  US9  U R	                  [        U5      U R                  R                  5       5        g)zh
L{SSHChannel.getHost} returns the same object as the underlying
transport's C{getHost} method returns.
rÂ   z	127.0.0.1i90  )r>   r:   N)r   r@   r   rF   rY   r   ÚgetHost)r   Úhosts     r   Útest_getHostÚChannelTests.test_getHost^  sI   € ô
 ˜5 +¨uÓ5ˆÜ D§L¡L×$5Ñ$5À4ÒHà×ÑÔ,¨TÓ2°D·L±L×4HÑ4HÓ4JÕKr   )r   rF   Nr,   )r3   r4   r5   r6   r7   rJ   rO   rb   rg   rk   rn   r…   rŽ   r“   r¥   r°   rº   r¿   rÅ   rÊ   r8   r   r   r   rB   rB   c   sY   † ñô'ôKô'ô<
ô
ô
ô ô>Kô.ô";ôH/;ôbHô<ôL÷Lr   rB   )NN)r>   r   r:   úinterfaces.IAddress | Noner;   rÌ   r-   r.   )r7   Ú
__future__r   Úunittestr   Úzope.interface.verifyr   Útwisted.conch.sshr   Útwisted.conch.ssh.addressr   Útwisted.conch.ssh.servicer   Útwisted.conch.ssh.transportr	   Útwisted.internetr
   Útwisted.internet.addressr   Útwisted.internet.testingr   ÚskipTestÚImportErrorÚobjectÚtwisted.trial.unittestr   r   r@   rB   r   r   r   Ú<module>rÛ      s»   ðñõ #å å .ðÝ)Ý=Ý4Ý>Ý+Ý4Ý8à€Hõ ,ô*$�Zô *$ð^ /3Ø.2ð"Øð"à+ð"ð ,ð"ð 
õ	"ñ2 ˆ�(ÓôBL�8ó BLó ñBLøð[ ó Ø)€HØ‚Jðús   –,A; Á;
BÂB