Ϫf2dZddlmZddlmZddlmZ ddlmZddl m Z ddl m Z ddl mZdd lmZdd lmZdd lmZd ZddlmZGdde Z d ddZeeeGddeZy#e$rd ZeZ YBwxYw)z Test ssh/channel.py. ) annotations)skipIf) verifyObject)channel)SSHTransportAddress) SSHService)SSHServerTransport) interfaces) IPv4Address)StringTransportzConch SSH not supported.)TestCasecHeZdZdZddZd dZd dZ d dZd dZy) 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.i|_i|_i|_y)N)dataextDataclosesselfs A/usr/lib/python3/dist-packages/twisted/conch/test/test_channel.py__init__zMockConnection.__init__*s;= JL 68 cy)z, Return our logging prefix. rrs r logPrefixzMockConnection.logPrefix/s rcZ|jj|gj|y)z' Record the sent data. N)r setdefaultappend)rrrs rsendDatazMockConnection.sendData5s# Wb)006rc^|jj|gj||fy)z0 Record the sent extended data. N)rrr)rrtypers rsendExtendedDatazMockConnection.sendExtendedData;s' ,33T4LArc"d|j|<y)z? Record that the channel sent a close message. TN)r)rrs r sendClosezMockConnection.sendCloseCs $ GrNreturnNone)r'str)rchannel.SSHChannelrbytesr'r()rr*r"intrr+r'r()rr*r'r() __name__ __module__ __qualname____doc__rrr r#r%rrrrrsE 9  7 B)B14B assertIsNoneravatar)rcc2s r test_initzChannelTests.test_initys   DII . **F3 **F3 ))51 ++Q/ **A. + !&&! !((#   1aAq! 4 ++Q/ ++Q/ **A. ,,a0 ++Q/ !$ !$ A&rc|jt|jd|jttjddy)z{ Test that str(SSHChannel) works gives the channel name and local and remote windows at a glance.. z%rG localWindowzN)rNr)rr?rs rtest_strzChannelTests.test_strsB T\\*,ST  ""q1 24S rc|j|jjd|jtjdjdy)z Test that bytes(SSHChannel) works, gives the channel name and local and remote windows at a glance.. s%rGrYsN)rNr __bytes__r?rs r test_byteszChannelTests.test_bytessO  LL " " $&N     1 - 7 7 9 , rcX|j|jjdy)z Test that SSHChannel.logPrefix gives the name of the channel, the local channel ID and the underlying connection. z.SSHChannel channel (unknown) on MockConnectionN)rNrrrs rtest_logPrefixzChannelTests.test_logPrefixs%  LL " " $&V rc4dgd fd }||j_|jjd|jjdd|jj d|j |jj d|j|jj|jd|j |jjd|j |jj|jdg|j |jjg|j |jj|jd gdd<|jj d |jd|jjd |jj|jj d |jdy )zq Test that addWindowBytes adds bytes to the window and resumes writing if it was paused. Fcdd<yNTrrcbsrstubStartWritingz:ChannelTests.test_addWindowBytes..stubStartWriting BqErtestrG2*rr)rGrhsPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaNr&)r startWritingwrite writeExtendedaddWindowBytesrNrRrC areWritingbufr=rextBufr assertFalseloseConnection)rrfres @rtest_addWindowBytesz ChannelTests.test_addWindowBytess W %5 ! 7# ""1g. ##B' 66 C  //0 1 ))3/  5yA ,,b1 **4<<8<.I1 ##B' A 9% ##% ##B' Arc*d|j_|j|jjdd|j |jjdd|j |jjddy)zn Test that requestReceived handles requests by dispatching them to request_* methods. c |dk(S)Nrr)rs rz3ChannelTests.test_requestReceived..s  rs test-methodras bad-methodN)rrequest_test_methodrCrequestReceivedrsrs rtest_requestReceivedz!ChannelTests.test_requestReceivedsl ,D (  44^SIJ 55ndKL 55mSIJrc|j|jj|jj|j |jjy)zM Test that the default closeReceieved closes the connection. N)rsrclosing closeReceivedrCrs rtest_closeReceievedz ChannelTests.test_closeReceievedsB --. ""$  ,,-rcZdgdfd }||j_|jjd|jjd|j|jj|j d|jj d|jjd|jj|j}|j|ddg|j|jjd |jjd |j|gd |j|jjd dd<|jjd |j|jj|j d|j|gd|j|jjd|j|jjdy)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. Fcdd<yrcrrdsrstubStopWritingz0ChannelTests.test_write..stubStopWritingrgrdryrrktada 12345678901)rr 12345678901rK123456)rrrr123456Nr&) r stopWritingrmrsrprCror=rrNrRrqrrrres @r test_writezChannelTests.test_writes W $3   4  4  001 1 ##B' 5!yy~~dll+ u~. 66; >* BC 66:1 9% 001 1 LM ))40 66:rcdgdfd }||j_|jjdd|jjdd|jjdd|j|jj|j d|jj d |jjdd|jj|j}|j|gd |j|jjd |jjd d |j|gd|j|jjddd<|jjdd|j|jj|j d|j|gd|j|jjddgg|j|jjdy)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. Fcdd<yrcrrdsrrz8ChannelTests.test_writeExtended..stubStopWritingrgrrGrryrHtrrk)rGrrHrrHryrrIr)rrrrIrrIrrKrJr)rrrrr)rJrrNr&) rrrnrsrprCror=rrNrRrrrs @rtest_writeExtendedzChannelTests.test_writeExtended s W $3   ""1d+ ""1d+ ""1d+ 001 1 ##B' ""1d+yy  . AB 66; ""1n5  S  66:1 ""1i0 001 1     ,,4yk: 66:rc|jjd|jjdtdD|j |j j |jdgy)zS Test that writeSequence is equivalent to write(''.join(sequece)). rkc3(K|] }d|fz yw)s%dNr).0is r z2ChannelTests.test_writeSequence..Cs"CA5A4<"Csr<s 0123456789N)rro writeSequencerangerNr=rrs rtest_writeSequencezChannelTests.test_writeSequence>sU ##B' """Cr"CC  5 Grc|jjd|jjdd|jj|j |j j j|j|jjd|j |j j j|j|jjd|j|j j j|jy)zk Tesyt that loseConnection() doesn't close the channel until all the data is sent. sdatarGsdatadatarJN) rrmrnrtrSr=rgetrorCrs rtest_loseConnectionz ChannelTests.test_loseConnectionFs 7# ""1k2 ##% $))**..t||<= ##A& $))**..t||<= ##A&  ((,,T\\:;rctddd}t|jj||j t ||jj y)z L{SSHChannel.getPeer} returns the same object as the underlying transport's C{getPeer} method returns. TCPz 192.168.0.1i1)r6r3N)r r8rr=rNrgetPeer)rpeers r test_getPeerzChannelTests.test_getPeerTsI 5-7DLL$5$54H ,T2DLL4H4H4JKrctddd}t|jj||j t ||jj y)z L{SSHChannel.getHost} returns the same object as the underlying transport's C{getHost} method returns. rz 127.0.0.1i90)r6r2N)r r8rr=rNrgetHost)rhosts r test_getHostzChannelTests.test_getHost^sI 5+u5DLL$5$54H ,T2DLL4H4H4JKrNr&)r-r.r/r0rArErWr[r^r`rur|rrrrrrrrrrr:r:csY'K '<     >K.";H/;bH <LLrr:)NN)r6rr2interfaces.IAddress | Noner3rr'r()r0 __future__runittestrzope.interface.verifyrtwisted.conch.sshrtwisted.conch.ssh.addressrtwisted.conch.ssh.servicertwisted.conch.ssh.transportr twisted.internetr twisted.internet.addressr twisted.internet.testingr skipTest ImportErrorobjecttwisted.trial.unittestrrr8r:rrrrs#. )=4>+48H,*$Z*$^/3.2" "+"," "2(BL8BLBL[)HJs,A99 BB