+
    DfjHr                     P   R t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ]! R4      t
^ RIHt ]
'       d
   ^ RIHtHt M
 ! R	 R
4      t ! R R]P                  4      t ! R R4      t ! R R]P$                  4      t ! R R]	P(                  4      t ! R R]	P(                  4      tR# )z1
This module tests twisted.conch.ssh.connection.
Nchannel)test_userauth)requireModule)unittestcryptography)error)common
connectionc                   *    ] tR t^t ! R R4      tRtR# )r
   c                       ] tR t^tRtR# )connection.SSHConnection N)__name__
__module____qualname____firstlineno____static_attributes__r       D/usr/lib/python3/dist-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                   f   a  ] tR t^t o RtRtRtRtR tR t	R t
R tR tR	 tR
 tR tR tRtV tR# )TestChannelaz  
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                (    R V P                   ,          # )zTestChannel %i)idselfs   &r   	logPrefixTestChannel.logPrefix:   s    $''))r   c                t    RV n         Wn        . V n        . V n        ^ V n        RV n        RV n        RV n        R# )z6
The channel is open.  Set up the instance variables.
TFN)gotOpenspecificDatainBuffer	extBuffernumberRequestsgotEOFgotOneClose	gotClosed)r   r"   s   &&r   channelOpenTestChannel.channelOpen=   s=     ( r   c                    Wn         R# )z4
Opening the channel failed.  Store the reason why.
N)openFailureReason)r   reasons   &&r   
openFailedTestChannel.openFailedJ   s
     "(r   c                >    V ;P                   ^,          un         VR8H  # )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                <    V P                   P                  V4       R# )z-
Data was received.  Store it in the buffer.
N)r#   appendr2   s   &&r   dataReceivedTestChannel.dataReceivedY   s     	T"r   c                >    V P                   P                  W34       R# )z6
Extended data was received.  Store it in the buffer.
N)r$   r7   )r   coder3   s   &&&r   extReceivedTestChannel.extReceived_   s     	tl+r   c                    RV n         R# )z!
EOF was received.  Remember it.
TN)r&   r   s   &r   eofReceivedTestChannel.eofReceivede   s     r   c                    RV n         R# )z#
Close was received.  Remember it.
TN)r'   r   s   &r   closeReceivedTestChannel.closeReceivedk   s      r   c                    RV n         R# )z'
The channel is closed.  Rembember it.
TN)r(   r   s   &r   closedTestChannel.closedq   s     r   )	r$   r(   r&   r'   r!   r#   r%   r,   r"   N)r   r   r   r   __doc__namer!   r(   r   r)   r.   r4   r8   r<   r?   rB   rE   r   __classdictcell____classdict__s   @r   r   r      sM     2 DGI*(#,  r   r   c                   4   a  ] tR t^xt o Rt^{tR tR tRtV t	R# )
TestAvatarz7
A mocked-up version of twisted.conch.avatar.ConchUser
c                    V\         P                  8X  d   \        VVVV R7      # VR8X  d"   \        P                  ! V P                  R4      hR# )zz
The server wants us to return a channel.  If the requested channel is
our TestChannel, return it, otherwise return None.
)remoteWindowremoteMaxPacketr3   avatar   conch-error-argserror args in wrong orderN)r   rH   r   
ConchError_ARGS_ERROR_CODE)r   channelType
windowSize	maxPacketr3   s   &&&&&r   lookupChannelTestAvatar.lookupChannel   sW    
 +***' )	  //
 ""4#8#8:UVV 0r   c                .    VR8X  d   R# VR8X  d   RV3# R# )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   requestTyper3   s   &&&r   gotGlobalRequestTestAvatar.gotGlobalRequest   s$     -'K':r   r   N)
r   r   r   r   rG   rU   rY   r_   r   rI   rJ   s   @r   rM   rM   x   s"      W& r   rM   c                   V   a  ] tR t^t o Rt]'       g   RtR tR tR t	R t
R tRtV tR	# )
TestConnectionzm
A subclass of SSHConnection for testing.

@ivar channel: the current channel.
@type channel. C{TestChannel}
Cannot run without cryptographyc                    R # )rb   r   r   s   &r   r   TestConnection.logPrefix   s    r   c                    R# )zD
The other side made the 'TestGlobal' global request.  Return True.
Tr   r2   s   &&r   global_TestGlobal TestConnection.global_TestGlobal   s     r   c                
    RV3# )z\
The other side made the 'Test-Data' global request.  Return True and
the data we received.
Tr   r2   s   &&r   global_Test_DataTestConnection.global_Test_Data   s    
 Tzr   c                >    \        WVR7      V n        V P                  # )zk
The other side is requesting the TestChannel.  Create a C{TestChannel}
instance, store it, and return it.
)rO   rP   r3   )r   r   r   rW   rX   r3   s   &&&&r   channel_TestChannel"TestConnection.channel_TestChannel   s!    
 ##T
 ||r   c                    \        R4      h)zE
The other side is requesting the ErrorChannel.  Raise an exception.
zno such thing)AssertionErrorrm   s   &&&&r   channel_ErrorChannel#TestConnection.channel_ErrorChannel   s     _--r   r   N)r   r   r   r   rG   r   skipr   rg   rj   rn   rr   r   rI   rJ   s   @r   rb   rb      s2      0 . .r   rb   c                      a  ] tR t^t o ]'       g   RtR tR tR tR t	R t
R tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t R t!R t"R t#R  t$R! t%R" t&R#t'V t(R$# )%ConnectionTestsrc   c                    \         P                  ! R 4      V n        \        4       V P                  n        \        4       V n        V P                  V P                  n        V P                  P                  4        R # N)r   FakeTransport	transportrM   rQ   rb   connserviceStartedr   s   &r   setUpConnectionTests.setUp   sL    &44T: *"$	"nn				  "r   c                   V P                   P                  V4       V P                  P                  RR V P                  n        V P                   P	                  \
        P                  ! RVP                  ^4      R,           4       R# )z/
Open the channel with the default connection.
Nz>2Ls         )r{   openChannelrz   packetsssh_CHANNEL_OPEN_CONFIRMATIONstructpackr   r   r   s   &&r   _openChannelConnectionTests._openChannel   s_     			g&!%!7!7!<		//KKwzz3/2UU	
r   c                :    V P                   P                  4        R # rx   )r{   serviceStoppedr   s   &r   tearDownConnectionTests.tearDown   s    		  "r   c                z    V P                  V P                  P                  P                  V P                  4       R# )zG
Test that the connection links itself to the avatar in the
transport.
N)assertIsrz   rQ   r{   r   s   &r   test_linkAvatarConnectionTests.test_linkAvatar   s&    
 	dnn++00$))<r   c                   \        4       p\        4       pV P                  P                  V4       V P                  P                  V4       V P                  P                  R4       V P	                  VP
                  4       V P                  VP                  4       V P                  VP
                  4       V P                  VP                  4       V P                  P                  4        V P	                  VP                  4       V P                  VP
                  4       V P                  VP                  4       ^ RI	H
p V P                  VP                  V4       R# )z6
Test that serviceStopped() closes any open channels.
)ConnectionLostNs                   )r   r{   r   r   
assertTruer!   assertFalser(   r   twisted.internet.errorr   assertIsInstancer,   )r   channel1channel2r   s   &   r   test_serviceStopped#ConnectionTests.test_serviceStopped   s     ==		h'		h'		//0GH(()++,))*++,		  "**+))*++,9h88.Ir   c                   V P                   P                  \        P                  ! R4      R,           4       V P	                  V P
                  P                  \        P                  R3.4       . V P
                  n        V P                   P                  \        P                  ! R4      R,           R,           4       V P	                  V P
                  P                  \        P                  R3.4       . V P
                  n        V P                   P                  \        P                  ! R4      R,           4       V P	                  V P
                  P                  \        P                  R3.4       . V P
                  n        V P                   P                  \        P                  ! R4      R,           4       V P	                  V P
                  P                  . 4       R# )	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   r]   s	   test datas   TestBad    N)
r{   ssh_GLOBAL_REQUESTr	   NSassertEqualrz   r   r
   MSG_REQUEST_SUCCESSMSG_REQUEST_FAILUREr   s   &r   test_GLOBAL_REQUEST#ConnectionTests.test_GLOBAL_REQUEST  sN    			$$VYY}%=%GHNN""j&D&Dc%J$K	
 "$		$$VYY{%;g%E%TUNN""j&D&Dl%S$T	
 "$		$$VYYz%:W%DENN""j&D&Dc%J$K	
 "$		$$VYY}%=%GH//4r   c                   a  S P                   P                  RRR4      pS P                   P                  R4       V 3R lpVP                  V4       VP	                  S P
                  4       V# )zP
Test that global request success packets cause the Deferred to be
called back.
   requestr1   Tc                 ,   < SP                  V R 4       R# r1   N)r   )r3   r   s   &r   check3ConnectionTests.test_REQUEST_SUCCESS.<locals>.check!  s    T7+r   )r{   sendGlobalRequestssh_REQUEST_SUCCESSaddCallback
addErrbackfailr   dr   s   f  r   test_REQUEST_SUCCESS$ConnectionTests.test_REQUEST_SUCCESS  sW    
 II''
GTB		%%g.	, 	
e	TYYr   c                   a  S P                   P                  RRR4      pS P                   P                  R4       V 3R lpVP                  S P                  4       VP                  V4       V# )zO
Test that global request failure packets cause the Deferred to be
erred back.
r   r1   Tc                 T   < SP                  V P                  P                  R 4       R# r   )r   valuer3   )fr   s   &r   r   3ConnectionTests.test_REQUEST_FAILURE.<locals>.check0  s    QWW\\73r   )r{   r   ssh_REQUEST_FAILUREr   r   r   r   s   f  r   test_REQUEST_FAILURE$ConnectionTests.test_REQUEST_FAILURE(  sW    
 II''
GTB		%%g.	4 	
dii 	Ur   c                Z   V P                   =V P                  P                  \        P
                  ! R4      R,           4       V P                  V P                  P                  P                  4       V P                  V P                  P                  P                  V P                  4       V P                  V P                  P                  P                  R4       V P                  V P                  P                  P                  R4       V P                  V P                  P                  P                  ^4       V P                  V P                  P                  P                  ^4       V P                  V P                   P                  \        P                   R3.4       . V P                   n        V P                  P                  \        P
                  ! R4      R,           4       V P#                  4        V P                  V P                   P                  \        P$                  R\        P
                  ! R4      ,           \        P
                  ! R4      ,           3.4       . V P                   n        V P                  P                  \        P
                  ! R4      R,           4       V P#                  4        V P                  V P                   P                  \        P$                  R	\        P
                  ! R
4      ,           \        P
                  ! R4      ,           3.4       R# )zn
Test that open channel packets cause a channel to be created and
opened or a failure message to be returned.
r         s                
   BadChannels         s   unknown channelr   s   ErrorChannels         s   unknown failureN               s               )rz   rQ   r{   ssh_CHANNEL_OPENr	   r   r   r   r!   r   r3   r"   remoteWindowLeftrP   r   r
   MSG_CHANNEL_OPEN_CONFIRMATIONflushLoggedErrorsMSG_CHANNEL_OPEN_FAILUREr   s   &r   test_CHANNEL_OPEN!ConnectionTests.test_CHANNEL_OPEN7  sF   
 NN!		""699^#<?V#VW		))112**//;**//1DE**779LM**;;Q?**::A>NN"" <<(		
 "$		""699]#;>U#UV NN"" 777ii 234iin%
	
 "$		""699_#=@W#WX NN"" 777ii 234iin%
	
r   c                X   WP                   P                  n        V P                  P	                  \
        P                  ! R4      R,           4       V P                  \        P                  4      pV P                  \        V4      ^RV: 24       V P                  V^ ,          P                  P                  R4       V P                  V P                   P                  \        P                   R\
        P                  ! R4      ,           \
        P                  ! R4      ,           3.4       R# )	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.
rR   zExpected one error, got: s         {s   error args in wrong orderr   Nr   ){   rS   )rz   rQ   rU   r{   r   r	   r   r   r   rT   r   lenr   argsr   r
   r   )r   r;   errorss   && r   _lookupChannelErrorTest'ConnectionTests._lookupChannelErrorTestk  s     26.		""II)*-DD	
 ''(8(89Va+DVJ)OP--/QRNN"" 77 8ii <=>iin%
	
r   c                (    V P                  ^{4       R# )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.
N)r   r   s   &r   test_lookupChannelError'ConnectionTests.test_lookupChannelError  s     	$$S)r   c                   \        4       pV P                  P                  V4       V P                  P                  R4       V P	                  VP
                  ^ 4       V P	                  VP                  ^ 4       V P	                  VP                  R4       V P	                  V P                  P                  V,          ^ 4       V P	                  V P                  P                  ^ ,          ^ 4       R# )z^
Test that channel open confirmation packets cause the channel to be
notified that it's open.
       Ns                       )
r   r{   r   r   r   r   rP   r"   channelsToRemoteChannellocalToRemoteChannelr   s   & r   test_CHANNEL_OPEN_CONFIRMATION.ConnectionTests.test_CHANNEL_OPEN_CONFIRMATION  s    
 -		g&		//0GH111500!4--/BC::7CQG77:A>r   c                p   \        4       pV P                  P                  V4       V P                  P                  R\        P
                  ! R4      ,           4       V P                  VP                  P                  R4       V P                  V P                  P                  P                  V4      4       R# )zb
Test that channel open failure packets cause the channel to be
notified that its opening failed.
             failure!N)r      )r   r{   r   ssh_CHANNEL_OPEN_FAILUREr	   r   r   r,   r   assertIsNonechannelsgetr   s   & r   test_CHANNEL_OPEN_FAILURE)ConnectionTests.test_CHANNEL_OPEN_FAILURE  s    
 -		g&		**3fii6LL	
 	22779IJ$)),,009:r   c                    \        4       pV P                  V4       VP                  pV P                  P	                  R4       V P                  VP                  V^,           4       R# )zK
Test that channel window adjust messages add bytes to the channel
window.
r   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=13DEr   c                ^   \        ^^R7      pV P                  V4       V P                  P                  R\        P
                  ! R4      ,           4       V P                  VP                  R.4       V P                  V P                  P                  \        P                  R3.4       . V P                  n	        RVP                  ^,           ,          pV P                  P                  R\        P
                  ! V4      ,           4       V P                  VP                  R.4       V P                  V P                  P                  \        P                  R3.4       \        4       pV P                  V4       RVP                  ^,           ,          p. V P                  n	        V P                  P                  R\        P
                  ! V4      ,           4       V P                  VP                  . 4       V P                  V P                  P                  \        P                  R3.4       R# )	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   r1               a      r   N)r   r   r{   ssh_CHANNEL_DATAr	   r   r   r#   rz   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79K#KL))G95NN"" 88;	
 "$722Q67		""#689L#LM))G95NN""**,?@A	
 -'"'00145!#		""#679K#KL))2.NN""**,?@A	
r   c                ^   \        ^^R7      pV P                  V4       V P                  P                  R\        P
                  ! R4      ,           4       V P                  VP                  R	.4       V P                  V P                  P                  \        P                  R3.4       . V P                  n	        RVP                  ^,           ,          pV P                  P                  R\        P
                  ! V4      ,           4       V P                  VP                  R	.4       V P                  V P                  P                  \        P                  R3.4       \        4       pV P                  V4       RVP                  ^,           ,          p. V P                  n	        V P                  P                  R\        P
                  ! V4      ,           4       V P                  VP                  . 4       V P                  V P                  P                  \        P                  R3.4       R# )
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   s           r1   r   r   r   s          N)    r1   )r   r   r{   ssh_CHANNEL_EXTENDED_DATAr	   r   r   r$   rz   r   r
   r   r   r   r   r   s   &   r   test_CHANNEL_EXTENDED_DATA*ConnectionTests.test_CHANNEL_EXTENDED_DATA  s   
 !A>'"		++3fii6HH	
 	**\N;NN"" 88;	
 "$722Q67		++3fii6II	
 	**\N;NN""**,?@A	
 -'"'00145!#		++3fii6HH	
 	**B/NN""**,?@A	
r   c                    \        4       pV P                  V4       V P                  P                  R4       V P	                  VP
                  4       R# )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                   \        4       pV P                  V4       V P                  VP                  4       V P	                  VP
                  4       V P	                  VP                  4       V P                  P                  V4       V P                  P                  R4       V P                  VP
                  4       V P                  VP                  4       R# )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                  a  \        4       pS P                  V4       S P                  P                  R\        P
                  ! R4      ,           R,           4       S P                  VP                  ^4       S P                  P                  R\        P
                  ! R4      ,           R,           R,           4      pV 3R lpVP                  V4       V# )zC
Test that channel requests that succeed send MSG_CHANNEL_SUCCESS.
r      testr   r   r1   c                 v   < SP                  SP                  P                  \        P                  R 3.4       R# r   N)r   rz   r   r
   MSG_CHANNEL_SUCCESSresultr   s   &r   r   ;ConnectionTests.test_CHANNEL_REQUEST_success.<locals>.check1  0    &&002EFGr   )	r   r   r{   ssh_CHANNEL_REQUESTr	   r   r   r%   r   r   r   r   r   s   f   r   test_CHANNEL_REQUEST_success,ConnectionTests.test_CHANNEL_REQUEST_success#  s     -'"		%%&))G"44w>	
 	//3II))&))G"44w>H
	 	
er   c                  a  \        4       pS P                  V4       S P                  P                  R\        P
                  ! R4      ,           R,           4      pV 3R lpVP                  S P                  4       VP                  V4       V# )z@
Test that channel requests that fail send MSG_CHANNEL_FAILURE.
r   r  r   c                 v   < SP                  SP                  P                  \        P                  R 3.4       R# r  )r   rz   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   f   r   test_CHANNEL_REQUEST_failure,ConnectionTests.test_CHANNEL_REQUEST_failure:  sl     -'"II))&))G"44w>
	 	
dii 	Ur   c                   a  \        4       pS P                  V4       S P                  P                  VRRR4      pS P                  P	                  R4       V 3R lpV# )zR
Test that channel request success messages cause the Deferred to be
called back.
r  r1   Tr   c                 *   < SP                  V 4       R # rx   )r   r	  s   &r   r   ;ConnectionTests.test_CHANNEL_REQUEST_SUCCESS.<locals>.checkX  s    OOF#r   )r   r   r{   sendRequestssh_CHANNEL_SUCCESSr  s   f   r   test_CHANNEL_REQUEST_SUCCESS,ConnectionTests.test_CHANNEL_REQUEST_SUCCESSN  sS    
 -'"II!!'7GTB		%%&9:	$ r   c                  a  \        4       pS P                  V4       S P                  P                  VRRR4      pS P                  P	                  R4       V 3R lpVP                  S P                  4       VP                  V4       V# )zQ
Test that channel request failure messages cause the Deferred to be
erred back.
r  r   Tr   c                 T   < SP                  V P                  P                  R 4       R# )zchannel request failedN)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   f   r   test_CHANNEL_REQUEST_FAILURE,ConnectionTests.test_CHANNEL_REQUEST_FAILURE]  sp    
 -'"II!!'7C>		%%&9:	K 	
dii 	Ur   c                   V P                   P                  RRR4      pVP                  R 4       V P                   P                  RRR4       V P                  V P                  P
                  \        P                  \        P                  ! R4      R,           3\        P                  \        P                  ! R4      R	,           3.4       V P                  V P                   P                  R
V./4       R# )zA
Test that global request messages are sent in the right format.
s	   wantReplyr1   Tc                     R # rx   r   failures   &r   <lambda>8ConnectionTests.test_sendGlobalRequest.<locals>.<lambda>t      Tr   s   noReplyr   Fs   datar   globalN)r{   r   r   r   rz   r   r
   MSG_GLOBAL_REQUESTr	   r   	deferredsr   r   s   & r   test_sendGlobalRequest&ConnectionTests.test_sendGlobalRequestn  s     II''gtD	)*		##JU;NN""..		,0G+0UV..		*0E0OP	
 	,,x!o>r   c                z   \        4       pV P                  P                  VR4       V P                  V P                  P
                  \        P                  \        P                  ! R4      R,           3.4       V P                  VP                  ^ 4       V P                  V P                  P                  ^4       R# )z?
Test that open channel messages are sent in the right format.
s   aaaar   s             aaaaN)r   r{   r   r   rz   r   r
   MSG_CHANNEL_OPENr	   r   r   localChannelIDr   s   & r   test_openChannel ConnectionTests.test_openChannel  s     -		gw/NN"" //IIn-MN		
 	Q'1115r   c           	        \        4       pV P                  V4       V P                  P                  VRRR4      pVP	                  R 4       V P                  P                  VRRR4       RVn        V P                  P                  VRRR4       V P                  V P                  P                  \        P                  R\        P                  ! R4      ,           R	,           3\        P                  R\        P                  ! R4      ,           R
,           3.4       V P                  V P                  P                  ^ ,          V.4       R# )zB
Test that channel request messages are sent in the right format.
r  Tc                     R # rx   r   r&  s   &r   r(  2ConnectionTests.test_sendRequest.<locals>.<lambda>  r*  r      test2r   Fs   test3r   s   testr   N)r   r   r{   r  r   localClosedr   rz   r   r
   MSG_CHANNEL_REQUESTr	   r   r-  r   r   r   s   &  r   test_sendRequest ConnectionTests.test_sendRequest  s    -'"II!!'7GTB	)*		gxe<"		gxd;NN"" 22'&))G*<<{J
 22'&))H*==G		
 	,,Q/!5r   c                   \        ^R7      pV P                  V4       ^ Vn        V P                  P	                  V^4       V P                  VP                  ^4       RVn        V P                  P	                  V^4       V P                  VP                  ^4       V P                  V P                  P                  \        P                  R3.4       R# )zQ
Test that channel window adjust messages cause bytes to be added
to the window.
)r   T         N)r   r   r   r{   adjustWindowr   r:  rz   r   r
   r   r   s   & r   test_adjustWindow!ConnectionTests.test_adjustWindow  s    
 !,'""#		w*00!4"		w*00!4NN"" 88;	
r   c                ^   \        4       pV P                  V4       V P                  P                  VR4       RVn        V P                  P                  VR4       V P                  V P                  P                  \        P                  R\        P                  ! R4      ,           3.4       R# )z?
Test that channel data messages are sent in the right format.
r   T   br   N)r   r   r{   sendDatar:  r   rz   r   r
   MSG_CHANNEL_DATAr	   r   r   s   & r   test_sendDataConnectionTests.test_sendData  s     -'"		7D)"		7D)NN""))+>4+PQR	
r   c                b   \        4       pV P                  V4       V P                  P                  V^R4       RVn        V P                  P                  V^R4       V P                  V P                  P                  \        P                  R\        P                  ! R4      ,           3.4       R# )zH
Test that channel extended data messages are sent in the right format.
r  Tr9  Nr@  )r   r   r{   sendExtendedDatar:  r   rz   r   r
   MSG_CHANNEL_EXTENDED_DATAr	   r   r   s   & r   test_sendExtendedData%ConnectionTests.test_sendExtendedData  s     -'"		""7Aw7"		""7Ax8NN"" 88=		'@RR	
r   c                   \        4       pV P                  V4       V P                  P                  V4       V P	                  V P
                  P                  \        P                  R3.4       RVn	        V P                  P                  V4       V P	                  V P
                  P                  \        P                  R3.4       R# )z>
Test that channel EOF messages are sent in the right format.
r   TN)
r   r   r{   sendEOFr   rz   r   r
   MSG_CHANNEL_EOFr:  r   s   & r   test_sendEOFConnectionTests.test_sendEOF  s     -'"		'"NN""j&@&@BU%V$W	
 #		'"NN""j&@&@BU%V$W	
r   c                   \        4       pV P                  V4       V P                  P                  V4       V P	                  VP
                  4       V P                  V P                  P                  \        P                  R3.4       V P                  P                  V4       V P                  V P                  P                  \        P                  R3.4       \        4       pV P                  V4       V P	                  VP                  4       V P                  VP                  4       RVn        V P                  P                  V4       V P	                  VP                  4       R# )z@
Test that channel close messages are sent in the right format.
r   TN)r   r   r{   r   r   r:  r   rz   r   r
   r   r!   r   r(   remoteClosed)r   r   r   s   &  r   test_sendCloseConnectionTests.test_sendClose  s    -'"		G$++,NN""**,?@A	
 			G$NN""**,?@A	

 =(#(()++, $		H%**+r   c                Z   V P                   P                  R^2^R4      pV P                  VP                  R4       V P                  VP                  ^24       V P                  VP
                  ^4       V P                  \        P                  V P                   P                  R^2^R4       R# )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   r1   r   N)	r{   
getChannelr   r3   r   rP   assertRaisesr   rT   r   s   & r   test_getChannelWithAvatar)ConnectionTests.test_getChannelWithAvatar  s     ))&&~r2wGw/112600"5dii22M2r7	
r   c                "   V P                   =V P                  V P                  P	                  RR4      4       V P                  V P                  P	                  RR4      R4       V P                  V P                  P	                  RR4      4       R# )zG
Test that gotGlobalRequests dispatches to global_* without an avatar.
r\   r1   s	   Test-Datas	   BadGlobalN)Tr1   )rz   rQ   r   r{   r_   r   r   r   s   &r   "test_gotGlobalRequestWithoutAvatar2ConnectionTests.test_gotGlobalRequestWithoutAvatar  sp     NN!		22='JKII&&|W=	
 	33L'JKr   c                    \        4       pV P                  V4       V P                  P                  VRR^R7      pV P	                  V\
        P                  4      pV P                  P                  V4       V# )z
Whenever an SSH channel gets closed any Deferred that was returned by a
sendRequest() on its parent connection must be errbacked.
   dummyrequest	   dummydata	wantReply)r   r   r{   r  assertFailurer   rT   channelClosedr<  s   &  r   9test_channelClosedCausesLeftoverChannelDeferredsToErrbackIConnectionTests.test_channelClosedCausesLeftoverChannelDeferredsToErrback(  sf    
 -'"II!!'?LTU!Vq%"2"23		(r   r{   rz   N))r   r   r   r   r   rt   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r"  r/  r4  r=  rB  rH  rM  rR  rV  r[  r^  rg  r   rI   rJ   s   @r   rv   rv      s     0#
#=J*502
h
8*?;	F#
J)
V(+ .("?"6&66
.

&
 ,4
	L r   rv   c                   D   a  ] tR tRt o Rt]'       g   RtR tR tRt	V t
R# )CleanConnectionShutdownTestsi6  zD
Check whether correct cleanup is performed on connection shutdown.
rc   c                    \         P                  ! R 4      V n        \        4       V P                  n        \        4       V n        V P                  V P                  n        R # rx   )r   ry   rz   rM   rQ   rb   r{   r   s   &r   r}   "CleanConnectionShutdownTests.setUp>  s<    &44T: *"$	"nn		r   c                    V P                   P                  4        V P                   P                  RR^R7      pV P                  V\        P
                  4      pV P                   P                  4        V# )zt
Once the service is stopped any leftover global deferred returned by
a sendGlobalRequest() call must be errbacked.
ra  rb  rc  )r{   r|   r   re  r   rT   r   r.  s   & r   9test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackVCleanConnectionShutdownTests.test_serviceStoppedCausesLeftoverGlobalDeferredsToErrbackD  s]    
 			  "II''QR'Sq%"2"23		  "r   ri  N)r   r   r   r   rG   r   rt   r}   ro  r   rI   rJ   s   @r   rk  rk  6  s#      0-
 
r   rk  )rG   r   twisted.conch.sshr   twisted.conch.testr   twisted.python.reflectr   twisted.trialr   r   twisted.conchr   r	   r
   
SSHChannelr   rM   r   rb   TestCaserv   rk  r   r   r   <module>rx     s     % , 0 "^, 44 
Y'$$ Yx& &R).Z-- ).Xf	h'' f	R8#4#4 r   