+
    Dfj2                    
   R t ^ RIHt ^ RIHt ^ RIHt  ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt Rt^ RIHt  ! R R]4      tRR R llt]! ]]4       ! R R]4      4       tR#   ] d    Rt]t L?i ; i)z
Test ssh/channel.py.
)annotations)skipIf)verifyObject)channel)SSHTransportAddress)
SSHService)SSHServerTransport)
interfaces)IPv4Address)StringTransport zConch SSH not supported.)TestCasec                  V    ] tR t^tRtR R ltR R ltR R ltR R	 ltR
 R lt	Rt
R# )MockConnectiona  
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                   V ^8  d   QhRR/#    returnNone )formats   "A/usr/lib/python3/dist-packages/twisted/conch/test/test_channel.py__annotate__MockConnection.__annotate__*   s     9 9$ 9    c                	0    / V n         / V n        / V n        R # )N)dataextDataclosesselfs   &r   __init__MockConnection.__init__*   s    ;=	JL68r   c                   V ^8  d   QhRR/# )r   r   strr   )r   s   "r   r   r   /   s        3  r   c                    R# )z
Return our logging prefix.
r   r   r   s   &r   	logPrefixMockConnection.logPrefix/   s      r   c               $    V ^8  d   QhRRRRRR/# )r   r   channel.SSHChannelr   bytesr   r   r   )r   s   "r   r   r   5   s"     7 7 2 7% 7D 7r   c                \    V P                   P                  V. 4      P                  V4       R# )z
Record the sent data.
N)r   
setdefaultappend)r    r   r   s   &&&r   sendDataMockConnection.sendData5   s#     			Wb)006r   c               (    V ^8  d   QhRRRRRRRR/# )	r   r   r)   typeintr   r*   r   r   r   )r   s   "r   r   r   ;   s2     B B)B14B<AB	Br   c                ^    V P                   P                  V. 4      P                  W#34       R# )z 
Record the sent extended data.
N)r   r,   r-   )r    r   r1   r   s   &&&&r   sendExtendedDataMockConnection.sendExtendedData;   s%     	,33TLAr   c                    V ^8  d   QhRRRR/# )r   r   r)   r   r   r   )r   s   "r   r   r   C   s     $ $!3 $ $r   c                $    RV P                   V&   R# )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)__name__
__module____qualname____firstlineno____doc__r!   r&   r.   r4   r8   __static_attributes__r   r   r   r   r      s&    
9
 7B$ $r   r   Nc               (    V ^8  d   QhRRRRRRRR/# )r   servicer   hostAddresszinterfaces.IAddress | NonepeerAddressr   r   r   )r   s   "r   r   r   J   s0     " ""+" ," 
	"r   c                r    \        4       pVP                  \        WR7      4       VP                  V 4       R# )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}
)rB   rC   N)r   makeConnectionr   
setService)rA   rB   rC   	transports   &&& r   connectSSHTransportrH   J   s2    $ #$IKI !r   c                      ] tR t^ctRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR tR!# )"ChannelTestsz
Tests for L{SSHChannel}.
c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   ChannelTests.__annotate__i   s     ' 't 'r   c                    \        4       V n        \        P                  ! V P                  ^
R7      V n        RV P                  n        R# )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   rN   r   
SSHChannelnamer   s   &r   setUpChannelTests.setUpi   s2     #$	))tyy"M&r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL   s   s     K K Kr   c                l    V P                  \        \        P                  V P                  4      4       R# )z;
L{SSHChannel} instances provide L{interfaces.ITransport}.
N)
assertTruer   r	   
ITransportr   r   s   &r   test_interfaceChannelTests.test_interfaces   s!     	Z%:%:DLLIJr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL   y   s     ' '4 'r   c           	        \         P                  ! V P                  R7      pV P                  VP                  R4       V P                  VP
                  R4       V P                  VP                  R4       V P                  VP                  ^ 4       V P                  VP                  ^ 4       V P                  VP                  V P                  4       V P                  VP                  4       V P                  VP                  4       \         P                  ! ^^^^^^^4      pV P                  VP                  ^4       V P                  VP
                  ^4       V P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                  ^4       R# )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.
)rN   i   i   N)r   rP   rN   assertEquallocalWindowSizelocalWindowLeftlocalMaxPacketremoteWindowLeftrO   assertIsNoner   avatar)r    cc2s   &  r   	test_initChannelTests.test_inity   s    DII.**F3**F3))51++Q/**A.+!&&!!((#1aAq!4++Q/++Q/**A.,,a0++Q/!$!$A&r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL      s     
 
$ 
r   c                    V P                  \        V P                  4      R4       V P                  \        \        P                  ! ^R7      4      R4       R# )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)>localWindowz<SSHChannel None (lw 1 rw 0)>N)r\   r$   r   rP   r   s   &r   test_strChannelTests.test_str   sB    
 	T\\*,ST""q124S	
r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL      s     
 
D 
r   c                    V P                  V P                  P                  4       R4       V P                  \        P                  ! ^R7      P                  4       R4       R# )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)>ri   s   <SSHChannel None (lw 1 rw 0)>N)r\   r   	__bytes__rP   r   s   &r   
test_bytesChannelTests.test_bytes   sO     	LL""$&N	
 	1-779,	
r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL      s     
 
 
r   c                Z    V P                  V P                  P                  4       R4       R# )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)r\   r   r&   r   s   &r   test_logPrefixChannelTests.test_logPrefix   s%    
 	LL""$&V	
r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL      s        T  r   c                b  a R.oR V3R llpWP                   n        V P                   P                  R4       V P                   P                  ^R4       V P                   P	                  ^24       V P                  V P                   P                  ^*4       V P                  V P                   P                  4       V P                  S^ ,          4       V P                  V P                   P                  R4       V P                  V P                  P                  V P                   ,          R.4       V P                  V P                   P                  . 4       V P                  V P                  P                  V P                   ,          R.4       RS^ &   V P                   P	                  ^4       V P                  S^ ,          4       V P                   P                  R4       V P                   P                  4        V P                   P	                  ^4       V P                  S^ ,          4       R# )	zY
Test that addWindowBytes adds bytes to the window and resumes writing
if it was paused.
Fc                   V ^8  d   QhRR/# r   r   )r   s   "r   r   6ChannelTests.test_addWindowBytes.<locals>.__annotate__   s     	 	$ 	r   c                    < R S ^ &   R# TNr   cbs   r   stubStartWriting:ChannelTests.test_addWindowBytes.<locals>.stubStartWriting       BqEr      testr   N)   r   sP   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)r   startWritingwritewriteExtendedaddWindowBytesr\   r`   rV   
areWritingbufrN   r   extBufr   assertFalseloseConnection)r    r~   r}   s   & @r   test_addWindowBytes ChannelTests.test_addWindowBytes   s   
 W	 	 %5!7#""1g.##B'66
C//01))3/5yA,,b1**4<<8<.I1##B'A9%##%##B'Ar   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL      s     K Kd Kr   c                ,   R V P                   n        V P                  V P                   P                  RR4      4       V P	                  V P                   P                  RR4      4       V P	                  V P                   P                  RR4      4       R# )zV
Test that requestReceived handles requests by dispatching them to
request_* methods.
c                    V R 8H  # )r   r   )r   s   &r   <lambda>3ChannelTests.test_requestReceived.<locals>.<lambda>   s    r   s   test-methodr      as
   bad-methodN)r   request_test_methodrV   requestReceivedr   r   s   &r   test_requestReceived!ChannelTests.test_requestReceived   sl    
 ,D(44^SIJ55ndKL55mSIJr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL      s     . .T .r   c                    V P                  V P                  P                  4       V P                  P                  4        V P	                  V P                  P                  4       R# )z=
Test that the default closeReceieved closes the connection.
N)r   r   closingcloseReceivedrV   r   s   &r   test_closeReceieved ChannelTests.test_closeReceieved   sB     	--.""$,,-r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL      s     "; ";D ";r   c                x  a R.oR V3R llpWP                   n        V P                   P                  R4       V P                   P                  R4       V P                  V P                   P                  4       V P                  S^ ,          4       V P                   P                  ^4       V P                   P                  R4       V P                  P                  V P                   ,          pV P                  VRR.4       V P                  V P                   P                  ^4       V P                   P                  R4       V P                  V. RO4       V P                  V P                   P                  ^4       RS^ &   V P                   P                  R	4       V P                  V P                   P                  4       V P                  S^ ,          4       V P                  V. RO4       V P                  V P                   P                  R
4       V P                  V P                   P                  ^ 4       R# )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                   V ^8  d   QhRR/# r   r   )r   s   "r   r   -ChannelTests.test_write.<locals>.__annotate__        	 	 	r   c                    < R S ^ &   R# r{   r   r|   s   r   stubStopWriting0ChannelTests.test_write.<locals>.stubStopWriting   r   r      dr      ta   da   12345678901   123456   6N)r   r   
   1234567890   1)r   r   r   r      12345)r   stopWritingr   r   r   rV   r   rN   r   r\   r`   r   r    r   r   r}   s   &  @r   
test_writeChannelTests.test_write   s    W	 	 $3 4 4 0011##B'5!yy~~dll+u~.66;>*BC66:19%0011LM))4066:r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL     s     /; /;D /;r   c                  a R.oR V3R llpWP                   n        V P                   P                  ^R4       V P                   P                  ^R4       V P                   P                  ^R4       V P                  V P                   P                  4       V P                  S^ ,          4       V P                   P                  ^4       V P                   P                  ^R4       V P                  P                  V P                   ,          pV P                  V. RO4       V P                  V P                   P                  ^4       V P                   P                  ^R4       V P                  V. RO4       V P                  V P                   P                  ^4       RS^ &   V P                   P                  ^R4       V P                  V P                   P                  4       V P                  S^ ,          4       V P                  V. RO4       V P                  V P                   P                  ^R	..4       V P                  V P                   P                  ^ 4       R
# )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                   V ^8  d   QhRR/# r   r   )r   s   "r   r   5ChannelTests.test_writeExtended.<locals>.__annotate__  r   r   c                    < R S ^ &   R# r{   r   r|   s   r   r   8ChannelTests.test_writeExtended.<locals>.stubStopWriting  r   r   r   r      tr   r   r   N)r   r   r   r   r   r   )r   r   r      r   r   r   )r   r   r   r   r   )   r   )r   r   r   r   r   rV   r   rN   r   r\   r`   r   r   s   &  @r   test_writeExtendedChannelTests.test_writeExtended  s    W	 	 $3 ""1d+""1d+""1d+0011##B'""1d+yy  .AB66;""1n5S	
 	66:1""1i00011
	
 	,,4yk:66:r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL   >  s     H HD Hr   c                   V P                   P                  ^4       V P                   P                  R \        ^
4       4       4       V P	                  V P
                  P                  V P                   ,          R.4       R# )zC
Test that writeSequence is equivalent to write(''.join(sequece)).
c              3  6   "   T F  pR V3,          x  K  	  R# 5i)s   %dNr   ).0is   & r   	<genexpr>2ChannelTests.test_writeSequence.<locals>.<genexpr>C  s     "CA5A4<<s   s
   0123456789N)r   r   writeSequenceranger\   rN   r   r   s   &r   test_writeSequenceChannelTests.test_writeSequence>  sU     	##B'"""Cr"CC5Gr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL   F  s     < <T <r   c                   V P                   P                  R4       V P                   P                  ^R4       V P                   P                  4        V P	                  V P
                  P                  P                  V P                   4      4       V P                   P                  ^4       V P	                  V P
                  P                  P                  V P                   4      4       V P                   P                  ^4       V P                  V P
                  P                  P                  V P                   4      4       R# )zS
Tesyt that loseConnection() doesn't close the channel until all
the data is sent.
s   datas   datadataN)
r   r   r   r   ra   rN   r   getr   rV   r   s   &r   test_loseConnection ChannelTests.test_loseConnectionF  s    
 	7#""1k2##%$))**..t||<=##A&$))**..t||<=##A&		((,,T\\:;r   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL   T       L Ld Lr   c                    \        RRR4      p\        V P                  P                  VR7       V P	                  \        V4      V P                  P                  4       4       R# )zh
L{SSHChannel.getPeer} returns the same object as the underlying
transport's C{getPeer} method returns.
TCPz192.168.0.1i1  )rA   rC   N)r
   rH   r   rN   r\   r   getPeer)r    peers   & r   test_getPeerChannelTests.test_getPeerT  sI    
 5-7DLL$5$54H,T2DLL4H4H4JKr   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   rL   ^  r   r   c                    \        RRR4      p\        V P                  P                  VR7       V P	                  \        V4      V P                  P                  4       4       R# )zh
L{SSHChannel.getHost} returns the same object as the underlying
transport's C{getHost} method returns.
r   z	127.0.0.1i90  )rA   rB   N)r
   rH   r   rN   r\   r   getHost)r    hosts   & r   test_getHostChannelTests.test_getHost^  sI    
 5+u5DLL$5$54H,T2DLL4H4H4JKr   )r   rN   N)r:   r;   r<   r=   r>   rR   rX   re   rk   rp   rt   r   r   r   r   r   r   r   r   r   r?   r   r   r   rJ   rJ   c   s_    'K'<


 >K.";H/;bH<LL Lr   rJ   )NN)r>   
__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   rH   rJ   r   r   r   <module>r      s    #  .)=4>+48H ,*$Z *$Z"2 (BL8 BL BL[  )HJs   ,A4 4BB