Ϫf<dZddlZddlZddlmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZGd d ej ZGd d e j$ZGd de j$ZGddeZGddej Zej0dddddk(rdZdZndZdZGddej Zy)z0 Test cases for twisted.protocols.ident module. N)StringIO)defererror)StringTransport)ident)failure)unittestc4eZdZdZdZdZdZdZdZdZ y) ClassParserTestsz* Test parsing of ident responses. c6tj|_y)z7 Create an ident client used in tests. N)r IdentClientclientselfs 9/usr/lib/python3/dist-packages/twisted/test/test_ident.pysetUpzClassParserTests.setUps'') ctj}|jjj |ddf|jj d|j |tjS)zX 'UNKNOWN-ERROR' error should map to the L{ident.IdentError} exception. {z 123, 456 : ERROR : UNKNOWN-ERROR) rDeferredrqueriesappend lineReceived assertFailurer IdentErrorrds rtest_indentErrorz!ClassParserTests.test_indentErrorsZ NN  ""AsC=1   !CD!!!U%5%566rctj}|jjj |ddf|jj d|j |tjS)zN 'NO-USER' error should map to the L{ident.NoUser} exception. rz234, 456 : ERROR : NO-USER) rrrrrrrrNoUserrs rtest_noUSerErrorz!ClassParserTests.test_noUSerError(sX NN  ""AsC=1   !=>!!!U\\22rctj}|jjj |ddf|jj d|j |tjS)zX 'INVALID-PORT' error should map to the L{ident.InvalidPort} exception. iY7z 345, 567 : ERROR : INVALID-PORT) rrrrrrrr InvalidPortrs rtest_invalidPortErrorz&ClassParserTests.test_invalidPortError1sZ NN  ""AsC=1   !CD!!!U%6%677rctj}|jjj |ddf|jj d|j |tjS)zV 'HIDDEN-USER' error should map to the L{ident.HiddenUser} exception. r%iz567, 789 : ERROR : HIDDEN-USER) rrrrrrrr HiddenUserrs rtest_hiddenUserErrorz%ClassParserTests.test_hiddenUserError:sZ NN  ""AsC=1   !AB!!!U%5%566rc:tj}|jjj |ddf|jj t jtj|j|tjS)zy A pending query which failed because of a ConnectionLost should receive an L{ident.IdentError}. ii) rrrrrconnectionLostrFailurerConnectionLostrrrrs rtest_lostConnectionz$ClassParserTests.test_lostConnectionCsk NN  ""AsC=1 ""7??53G3G3I#JK!!!U%5%566rN) __name__ __module__ __qualname____doc__rrr#r'r*r/rrr r s%* 73877rr ceZdZdZy)TestIdentServerc|jSN) resultValuer serverAddress clientAddresss rlookupzTestIdentServer.lookupOsrNr0r1r2r=r4rrr6r6Ns rr6ceZdZdZy)TestErrorIdentServerc"|jr8) exceptionTyper:s rr=zTestErrorIdentServer.lookupTs  ""rNr>r4rrr@r@Ss#rr@c eZdZy) NewExceptionN)r0r1r2r4rrrDrDXsrrDceZdZdZdZy)ServerParserTestsct}|jtg}|j|_t j |_|jd|j|ddt j|_|jd|j|ddt j|_|jd|j|dd t j|_|jd |j|d d t|_|jd |j|dd|jt}|jt|ddD]M}|dd=|jd|fz|jd|fz|j|d|fzd|fzgOy)Nz123, 345rz 123, 345 : ERROR : UNKNOWN-ERRORz432, 210z432, 210 : ERROR : NO-USERz987, 654z987, 654 : ERROR : INVALID-PORTz756, 827z756, 827 : ERROR : HIDDEN-USERz987, 789z 987, 789 : ERROR : UNKNOWN-ERROR)riiz%d, 5z5, %dz%d, 5 : ERROR : INVALID-PORTz5, %d : ERROR : INVALID-PORT)r@makeConnectionrrsendLinerrrBr assertEqualr"r&r)rDflushLoggedErrorslen)rpLerrsports r testErrorszServerParserTests.testErrors]s " *+ XX ** z" 1AB,, z" 1;<++ z" 1@A** z" 1?@& z" 1AB%%l3 TA&' D! NN7dW, - NN7dW, -   2dW<2dW<  rct}|jtg}|j|_d|_|j d|j|ddy)N)SYSUSERz123, 456rz123, 456 : USERID : SYS : USER)r6rMrrrNr9rrO)rrRrSs r testSuccesszServerParserTests.testSuccesssS   *+ XX '  z" 1?@rN)r0r1r2rVrZr4rrrFrF\s&PArrFz=LrH0100007F040302017F00000101020304cLeZdZdededZdezZdZdZdZ dZ d Z d Z y ) ProcMixinTestsz4: z:0019 z]:02FA 0A 00000000:00000000 00:00000000 00000000 0 0 10927 1 f72a5b80 3000 0 0 2 -1zd sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode cvtj}|j|jtdy)N 127.0.0.1)rProcServerMixinrOdottedQuadFromHexString_addr1rrRs rtestDottedQuadFromHexStringz*ProcMixinTests.testDottedQuadFromHexStrings+  ! ! # 226:KHrc|tj}|j|jtdzdy)Nz:0277)rciw)rrdrO unpackAddressrfrgs rtestUnpackAddressz ProcMixinTests.testUnpackAddresss/  ! ! # ')9:z4ProcMixinTests.testExistingAddress..D$))-rc0j|dfdS)NrootrH)r)uidusernames rryz4ProcMixinTests.testExistingAddress..sX__S%96$B1$Errmror|r)rrdentries getUsernamerOr= SYSTEM_NAME)rrRr~s` @rtestExistingAddressz"ProcMixinTests.testExistingAddresssa  ! ! #- E   HH&(8 9AMM6;R  A3'rcJtj}fd|_jtj|j ddjtj|j ddjtj|j ddy)Nc0tjgSr8rwrsrryz7ProcMixinTests.testNonExistingAddress..rzrrcrorm)z1.2.3.5rq)rpi)rrdr assertRaisesr"r=rgs` rtestNonExistingAddressz%ProcMixinTests.testNonExistingAddresssr  ! ! #-  %,,2CEUV %,,2CEUV %,,2CEUVrcgfd}jtd|tj}j tj |j ddjdifgy)zS L{ident.ProcServerMixin.lookup} uses the Linux TCP process table. cTj||ftjS)z[ Mock for the open call to prevent actually opening /proc/net/tcp. )rr sampleFile)argskwargs open_callsrs r mocked_openz8ProcMixinTests.testLookupProcNetTcp..mocked_opens&   tVn -DOO, ,ropenrro)z /proc/net/tcpN)patchbuiltinsrrdrr"r=rO)rrrRrs` @rtestLookupProcNetTcpz#ProcMixinTests.testLookupProcNetTcpsf  - 8V[1  ! ! # %,,2CEUV -r23Z@rN) r0r1r2rf_addr2rsrrhrkrtrrrr4rrrarasD   D  68< = IP (WArra)r3rstructiortwisted.internetrrtwisted.internet.testingrtwisted.protocolsrtwisted.pythonr twisted.trialr TestCaser IdentServerr6r@ RuntimeErrorrDrFpackrfrrar4rrrs  )4#""77x((77t e'' #5,,#  < 1A))1Ah6;;tQ!' F F F F;AX&&;Ar