ϪfbVdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z m Z ddlmZdd lmZmZmZdd lmZdd lmZdd lmZmZed Zeej:Zej>jAejBed<GddeZ"ddlm#Z#ddlm$Z$ddl%m&Z&GddejNZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1ddl m2Z2 dd l3m4Z4m5Z5m6Z6m7Z7m8Z8dd!l9m:Z:m;Z;mZ>m?Z?d"Z@Gd#d$e:jZBGd%d&e;jZDGd'd(e?jZFGd)d*e>jZHGd+d,e7ZIGd-d.e6ZJGd/d0e8ZKejeJeKe=jGd2d3e$jZPGd4d5ZQGd6d7eQZRdd8lSmTZTGd9d:ejeTjZWGd;deQZZGd?d@eQZ[GdAdBZ\GdCdDeZee\Z]GdEdFeRee\Z^ee dGGdHdIe[ee\Z_GdJdKZ`GdLdMeZee`ZaGdNdOeRee`Zbee dPGdQdRe[ee`ZcGdSdTeZdy#eN$rd1Z@YwxYw)UzU Tests for L{twisted.conch.recvline} and fixtures for testing related functionality. N)skipIf)recvline)insults)portal)defererror)StringTransport) componentsfilepathreflect) iterbytes) requireModule)SkipTestTestCaseztwisted.conch.stdio PYTHONPATHcTeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy ) ArrowsTestsct_tj_t j _fdj_j_ jjjy)NcjSN)pselfsB/usr/lib/python3/dist-packages/twisted/conch/test/test_recvline.pyz#ArrowsTests.setUp.."s $&&) r underlyingTransportrServerProtocolptrHistoricRecvLinerprotocolFactoryfactorymakeConnectionrs`rsetUpzArrowsTests.setUps]#2#4 ((***,"0 t778rc|jjdd|jjdd|jjdd|j|jjdy)zy When L{HistoricRecvLine} receives a printable character, it adds it to the current line buffer. xNyzxyzr)rkeystrokeReceived assertEqualcurrentLineBufferrs rtest_printableCharactersz$ArrowsTests.test_printableCharacters&s]   t,   t,   t, 113]Crcfd}tdD] }|| jjjd|jj jjjd|jj jjjd|jj jjjd|jj jjjd|jj jjjd|jj jjjd|jj jjjd|jj jjjd|jj jjjdy)z When L{HistoricRecvLine} receives a LEFT_ARROW or RIGHT_ARROW keystroke it moves the cursor left or right in the current line buffer, respectively. c<jj|dSrrr+chrs rrz3ArrowsTests.test_horizontalArrows..700T:rr*r))xyr()r&syz)rr*N)r r,rr-r RIGHT_ARROW LEFT_ARROWrkRr3s` rtest_horizontalArrowsz!ArrowsTests.test_horizontalArrows1s ;F# B rF  113]C 477   113]C 477   113]C 477   113]C 477   113]C 477   113]C 477   113]C 477   113]C 477   113]C 477   113]Crc|fd}tdD] }|| jjjd|d|d|djjjd|djjjdy ) z When {HistoricRecvLine} receives a newline, it adds the current line buffer to the end of its history buffer. c<jj|dSrr1r2s rrz*ArrowsTests.test_newline..]r4r xyz abc 123 r*abc123cba ))r*r@rAscbarBN)r r,rcurrentHistoryBufferr8s` r test_newlinezArrowsTests.test_newlineXs ;./ B rF  4468VW 4 4 4 4468VW 5   FF ' ' )+Q rcfd}tdD] }|| jjjdjjj d|j j jjjdjjj d|j j jjjdjjj d|j j jjjd jjj d |j j jjjd jjj d td D]}|j j jjjdy ) a When L{HistoricRecvLine} receives UP_ARROW or DOWN_ARROW keystrokes it move the current index in the current history buffer up or down, and resets the current line buffer to the previous or next line in history, respectively for each. c<jj|dSrr1r2s rrz1ArrowsTests.test_verticalArrows..ur4rr=r>rr))r*r@)rA)rAr))r*)r@rA)r@r)rBr?r)N) r r,rrGr-rUP_ARROWrange DOWN_ARROW)rr9r3is` rtest_verticalArrowszArrowsTests.test_verticalArrowsns;./ B rF  4468VW 113Z@ 477   4468UV 113]C 477   4468UV 113]C 477   4468VW 113]C 477   4468VW 113]Cq #A tww!! " # 4468VWrc fd}tdD] }|| jjjd|jj jjjdy)z When L{HistoricRecvLine} receives a HOME keystroke it moves the cursor to the beginning of the current line buffer. c<jj|dSrr1r2s rrz'ArrowsTests.test_home..r4r hello, worldrTr)rrTN)r r,rr-rHOMEr8s` r test_homezArrowsTests.test_homesq ;O, B rF  1135KL 477<< 1135KLrcXfd}tdD] }|| jjjd|jj |jj jjjdy)z When L{HistoricRecvLine} receives an END keystroke it moves the cursor to the end of the current line buffer. c<jj|dSrr1r2s rrz&ArrowsTests.test_end..r4rrTrUN)r r,rr-rrVENDr8s` rtest_endzArrowsTests.test_ends ;O, B rF  1135KL 477<< 477;; 1135KLrcpfd}tdD] }|| jjjd|jj jjjd|jj |jj jjjd|jj jjjdy)z When L{HistoricRecvLine} receives a BACKSPACE keystroke it deletes the character immediately before the cursor. c<jj|dSrr1r2s rrz,ArrowsTests.test_backspace..r4rr*r)r5r)rr'N)r r,rr-r BACKSPACEr7r8s` rtest_backspacezArrowsTests.test_backspaces ;F# B rF  113]C 477   113\B 477   477   113[A 477   113[Arcfd}tdD] }|| jjjd|jj jjjd|jj |jj jjjd|jj |jj jjjd|jj |jj jjjd|jj jjjdy)z When L{HistoricRecvLine} receives a DELETE keystroke, it delets the character immediately after the cursor. c<jj|dSrr1r2s rrz)ArrowsTests.test_delete..r4rr*r)r^)r&rrKN)r r,rr-rDELETEr7r8s` r test_deletezArrowsTests.test_deletesY ;F# B rF  113]C 477>> 113]C 477   477>> 113\B 477   477>> 113[A 477   477>> 113Z@ 477>> 113Z@rcxfd}tdD] }|| |jj|djjj d|jj|djjj dy)z When not in INSERT mode, L{HistoricRecvLine} inserts the typed character at the cursor before the next character. c<jj|dSrr1r2s rrz)ArrowsTests.test_insert..r4rr*A)xyAr(B)xyBsAzN)r rr7r,rr-r8s` r test_insertzArrowsTests.test_inserts ;F# B rF  477   4 113^D 477   4 113_Ercfd}tdD] }|| |jj|jj|dj j j d|jj|dj j j dy)a When in INSERT mode and upon receiving a keystroke with a printable character, L{HistoricRecvLine} replaces the character at the cursor with the typed character rather than inserting before. Ah, the ironies of INSERT mode. c<jj|dSrr1r2s rrz+ArrowsTests.test_typeover..r4rr*rg)rhrri)rjrN)r rINSERTr7r,rr-r8s` r test_typeoverzArrowsTests.test_typeovers;F# B rF  477>> 477   4 113]C 477   4 113]Crcfd}j}|j|j|j|j|j |j |j|j|j|j|j|j|j|jfD]4}||jj j#d6y)z When L{HistoricRecvLine} receives a keystroke for an unprintable function key with no assigned behavior, the line buffer is unmodified. c<jj|dSrr1r2s rrz8ArrowsTests.test_unprintableCharacters.. r4rrKN)rF1F2F3F4F5F6F7F8F9F10F11F12PGUPPGDNr,rr-)rr9rr3s` rtest_unprintableCharactersz&ArrowsTests.test_unprintableCharacterss ; WW EE EE EE EE EE EE EE EE EE FF FF FF GG GG  EB rF   TVV557 D# ErN)__name__ __module__ __qualname__r$r.r:rHrQrWr[r`rdrkrorrBrrrrsJ9 D%DN ,!XF M MB*A:F$D,Err)telnet)helper) LoopbackRelayceZdZdZy) EchoServerct|jj|dz|j|jzy)NrF)terminalwritepspn)rlines r lineReceivedzEchoServer.lineReceived*s* D5L477477+;;>''- -rN)rrrrrrrBrrrrrs ! - .rrceZdZdZdZy)TestAuthcZtjj||g|i|||_yr)rSSHUserAuthClientrpassword)rusernamerrrs rrzTestAuth.__init__s)  & & / /h I Ib I$DMrc@tj|jSr)rsucceedrrs r getPasswordzTestAuth.getPasswords==/ /rN)rrrrrrBrrrrs  % 0rrc$eZdZdZdZdZdZy) TestTransportcf||_||_||_||_||_||_||_yr)r!rrrrrr) rr!rrrrrrrrs rrzTestTransport.__init__s8$3D ,D "0D $DM$DMDJ DKrc,tjdS)NT)rr)rhostKey fingerprints r verifyHostKeyzTestTransport.verifyHostKeys==& &rct|j|j|j|j|j |_|jt|j|j|j yr) rr!rrrr_TestTransport__connectionrequestServicerrrrs rconnectionSecurezTestTransport.connectionSecuresb .$$!!##  !D     t7H7HI rc8|jj|Sr)rrrs rrzTestTransport.writes$$**40 0rN)rrrrrrrrBrrrrs !( '  1rrceZdZdZy)TestSessionTransportcr|jjjjj Sr)avatarrrr"serverProtocolrs rr!z$TestSessionTransport.protocolFactorys';;##--55DDF FrN)rrrr!rBrrrrs GrrceZdZeZy) TestSessionN)rrrrtransportFactoryrBrrrrs/rrc eZdZy)TestUserNrrrrBrrrrs rrFceZdZdZdZdZy)NotifyingExpectableBufferchtj|_tj|_yr)rDeferred onConnectiononDisconnectionrs rrz"NotifyingExpectableBuffer.__init__s !NN,$~~/rcxtjj||jj |yr)rExpectableBufferconnectionMadercallbackrs rrz(NotifyingExpectableBuffer.connectionMades*..t4 ""4(rc:|jj|yr)rerrback)rreasons rrz(NotifyingExpectableBuffer.connectionLosts $$V,rN)rrrrrrrBrrrrs0)-rrc eZdZdZdZdZdZy) _BaseMixinPc|jjj}|dg|jt |z dz zz}|j ||y)Nr)recvlineClient __bytes__ splitlinesHEIGHTlenr,)rlines receivedLines expectedLiness r _assertBufferz_BaseMixin._assertBuffersR++557BBD #$++E *BQ*F!GH   6rcjjd}j|fd}|j|S)Nsdonec(jyr)r)ignoutputrs rfinishedz)_BaseMixin._trivialTest..finisheds   v &r)rexpect _testwrite addCallback)r inputLinerdoners` ` r _trivialTestz_BaseMixin._trivialTests=""))'2  " '))rN)rrrWIDTHrrrrBrrrrs E F7 *rrceZdZdZdZy) _SSHMixinc  ts tdd\}}t}t|_ fd|_t j}|j||tj|}|j|t|}tjtj |j#d}||j$d<||j&d<|j(|_|j+|j)t-j.fd |j1d}t3|} t5t-j6fd t9 fd d i|||j:|j<} t3| } | j?| |j?| |_ | |_!||_"| |_#| |_$jJS) NzMcryptography requirements missing, can't run historic recvline tests over ssh)stestuserstestpasscSrrB insultsServersrrz!_SSHMixin.setUp..s]ri)keySizesssh-rsacSrrBrecvlineServersrrz!_SSHMixin.setUp..~rcSrrBrsrrz!_SSHMixin.setUp.. rrcSrrB insultsClientsrrz!_SSHMixin.setUp.. sMrrB)&sshrrr userFactorychainedProtocolFactoryr'InMemoryUsernamePasswordDatabaseDontUseaddUserrPortalregisterCheckerrr_getPersistentRSAKeyr FilePathmktemp publicKeys privateKeysr startFactoryrr buildProtocolrrClientProtocolrr rr#r sshClient sshServerclientTransportserverTransportr)rurrlmcheckerptl sshFactorysshKeyr*r+r)r,rrrrs @@@@rr$z_SSHMixin.setUps*  (1o"%:"BBD1mmC  G$!#& **   dkkm ,d -3 j)-3 z*$($7$7 !!,,.../EF ,,T2 ' 224../EF ! !2r1aT[[ ( 2  1  1,""..***rc:|jj|yr)r)rrs rrz_SSHMixin._testwrites T"rNrrrr$rrBrrr r s 0+d#rr ) test_telnetc eZdZy)TestInsultsClientProtocolNrrBrrr7r7#rr7c eZdZy)TestInsultsServerProtocolNrrBrrr:r:'r8rr:ceZdZdZdZy) _TelnetMixinc|jtfdtjfd}t |}t t fdtjfd}t |}|j||j||j|j|_ ||_ ||_ ||_ jS)NcSrrBrsrrz$_TelnetMixin.setUp....rcSrrBrsrrz$_TelnetMixin.setUp../mrcSrrBrsrrz$_TelnetMixin.setUp..3r?rcSrrBrsrrz$_TelnetMixin.setUp..4rAr)rr:rTelnetTransportrrr7r# clearBufferr telnetClientr+r,r) r telnetServerr+rFr,rrrrs @@@@rr$z_TelnetMixin.setUp,s,,.12HI --.CD ' 52412HI --.CD ' 5##O4##O4##%##%,(..***rc:|jj|yr)rFrrs rrz_TelnetMixin._testwriteDs %rNr4rBrrr<r<+s +0&rr<ceZdZdZdZdZy) _StdioMixinc 0ttjfd}tj |}t j }tj}|jds|jdr|dd}||tj|jg}ddl m }|j|||td}x|_|_||_||_t)j*t-d|j.j1d gS) NcSrrB) testTerminalsrrz#_StdioMixin.setUp..Ss|rz.pycz.pyor)reactorT)envusePTYs>>> )rrr(stdioTerminalProcessProtocolsys executable__file__endswithr qualrtwisted.internetrO spawnProcess properEnvrrM processClientr+r gatherResultsfilterrr) rrr\exemoduleargsrOr+rMs @rr$z_StdioMixin.setUpIs 12  ../CD 55mD nn ??6 "foof&=CR[FVW\\$*=*=>?,!.. 3)D/ 3?>d/*. "" 4-44l6I6I'6RS T  rc jjdfd}j j j|S#tjtf$rYEwxYw)NKILLc|jtjj|jj j |jjdy)N )traprProcessTerminated assertIsNonevalueexitCoder,status)failurers rrfz"_StdioMixin.tearDown..trap{sG LL00 1   gmm44 5   W]]111 5r)r+ signalProcessrProcessExitedAlreadyOSErrorrMr addErrback)rrfs` rtearDownz_StdioMixin.tearDownts_   . .v 6 6   00;;DAA**G4   sAA$#A$c:|jj|yr)r+rrs rrz_StdioMixin._testwrites ""4(rN)rrrr$rqrrBrrrJrJHs) V B)rrJcFeZdZeZdZdZdZdZdZ dZ dZ dZ d Z y ) RecvlineLoopbackMixinc*|jdgdS)Nsfirst line done)>>> first line first line>>> done)rrs r testSimplez RecvlineLoopbackMixin.testSimples  !P  rcR|jtdztdzzdzgdS)NrwrL xxxx done)s>>> first xxxxs first xxxxrx)rinsertleftrs r testLeftArrowz#RecvlineLoopbackMixin.testLeftArrows.  ] "TAX - = ;  rcf|jtdztdzztdzzdzgdS)Ns right linerLsxx done)s>>> right lixxs right lixxrx)rr|r}rightrs rtestRightArrowz$RecvlineLoopbackMixin.testRightArrows7  ] "TAX - 9K G ;  rcD|jdtdzzdzgdS)N second linerLr{)s>>> second xxxxs second xxxxrx)r backspacers r testBackspacez#RecvlineLoopbackMixin.testBackspaces)  Y] *] : =  rcX|jdtdzztdzzdzgdS)Ns delete xxxxrL line done)s>>> delete lines delete linerx)rr}deleters r testDeletez RecvlineLoopbackMixin.testDeletes2  TAX % 2] B =  rcD|jdtdzzdzgdS)Ns third inel done)s>>> third lines third linerx)rr}rs r testInsertz RecvlineLoopbackMixin.testInserts)  4!8 #j 0 ;  rcR|jdtdzztzdzgdS)Ns fourth xinerLr)s>>> fourth lines fourth linerx)rr}r|rs r testTypeoverz"RecvlineLoopbackMixin.testTypeovers.  TAX % . ; =  rcL|jtdztzdzgdS)Ns blah lines home done)s >>> home lines home linerx)rr|homers rtestHomezRecvlineLoopbackMixin.testHomes*  \ !D (= 8 9  rcR|jdtdzztzdzgdS)Nsend rLr)s >>> end linesend linerx)rr}endrs rtestEndzRecvlineLoopbackMixin.testEnds.  dQh  $} 4 7  rN)rrrrrryr~rrrrrrrrBrrrtrts4N         rrtc eZdZy)RecvlineLoopbackTelnetTestsNrrBrrrrr8rrc eZdZy)RecvlineLoopbackSSHTestsNrrBrrrrr8rrzBTerminal requirements missing, can't run recvline tests over stdioc eZdZy)RecvlineLoopbackStdioTestsNrrBrrrrsrrc"eZdZeZdZdZdZy)HistoricRecvlineLoopbackMixinc>|jdtzdzgdS)Ns first line  done)rvrwrvrwrx)ruprs r testUpArrowz)HistoricRecvlineLoopbackMixin.testUpArrows'  b 9 ,   rcL|jdtztzdzgdS)aH Pressing down arrow to visit an entry that was added to the history by pressing the up arrow instead of return does not raise a L{TypeError}. @see: U{http://twistedmatrix.com/trac/ticket/9031} @return: A L{defer.Deferred} that fires when C{b"done"} is echoed back. sfirst line partial liner)rvrws>>> partial lines partial linerxrrdownrs r$test_DownArrowToPartialLineInHistoryzBHistoricRecvlineLoopbackMixin.test_DownArrowToPartialLineInHistorys.  - 2T 9I E   rcR|jdtdzztzdzgdS)Nsfirst line second line rr)rvrw>>> second linerrrrxrrs r testDownArrowz+HistoricRecvlineLoopbackMixin.testDownArrows0  (26 1D 89 D   rN)rrrrrrrrrBrrrrsN   .  rrc eZdZy)#HistoricRecvlineLoopbackTelnetTestsNrrBrrrr rrc eZdZy) HistoricRecvlineLoopbackSSHTestsNrrBrrrrrrrzKTerminal requirements missing, can't run historic recvline tests over stdioc eZdZy)"HistoricRecvlineLoopbackStdioTestsNrrBrrrr s rrceZdZdZdZy)TransportSequenceTestsz5 L{twisted.conch.recvline.TransportSequence} cL|jttjy)zh Initializing a L{recvline.TransportSequence} with no args raises an assertion. N) assertRaisesAssertionErrorrTransportSequencers rtest_invalidSequencez+TransportSequenceTests.test_invalidSequences .(*D*DErN)rrr__doc__rrBrrrrs Frr)erosrTunittestr twisted.conchrtwisted.conch.insultsr twisted.credrrYrrtwisted.internet.testingr twisted.pythonr r r twisted.python.compatr twisted.python.reflectrtwisted.trial.unittestrrrRdictenvironr[pathsepjoinpathrrrtwisted.conch.test.loopbackrr rr}rrrr|rrrrrtwisted.conch.manhole_sshrrrrrtwisted.conch.sshrrrrrrrrrrrrrSSHClientTransportrrrrregisterAdapterISession ImportErrorrrrr twisted.conch.testr5r( TestProtocolr7rr:r<rJrtrrrrrrrrrBrrrs   "))488+05+,   **//#((3 ,DE(DEN!(5=**=     !JH C 6++ 6D.11.408--0%1 44%1NG7G0o0 < J{Hg6F6FG - 7 7 -**(4# 4#n+  6 6 8P8P   6 6 8P8P &:&:;)*;)|6 6 r ,:O  y(4I E WX h8M Y 2 2 j (9   x6  IT 8  FX FY CsJJ('J(