ϪfR6dZddlmZddlmZddlmZddlmZddl m Z m Z m Z ddl mZddlmZdd lmZGd d ZGd d ej(ZGddej(ZGddej(ZGdde j0ZGddej(ZGddej(ZGddej(ZGddej(Zy)z7 Tests for L{twisted.words.protocols.jabber.component} )sha1) verifyObject)failure)unittest) componentijabber xmlstream)JID)domish)XmlPipeceZdZdZdZy)DummyTransportc||_yN)list)selfrs I/usr/lib/python3/dist-packages/twisted/words/test/test_jabbercomponent.py__init__zDummyTransport.__init__s  c:|jj|yr)rappend)rbytess rwritezDummyTransport.writes rN)__name__ __module__ __qualname__rrrrrrs  rrceZdZdZdZy)#ComponentInitiatingInitializerTestscg|_tj|_d|j_tj |j|_d|j_|jj|j_|jj|jjdd|j_ tj|j|_y)Nsecrettest:componentz12345)outputr Authenticator authenticatorpassword XmlStream namespacersendconnectionMade dataReceivedsidrComponentInitiatingInitializerinitrs rsetUpz)ComponentInitiatingInitializerTests.setUps &446&.#",,T-?-?@#3 "kk00 %%' ## ; %<r5asciis s T)rDrConnectComponentAuthenticatorr r(r transport addObserverSTREAM_AUTHD_EVENTrFr+r,rr:encoder7)routlistcaxshvs rtestAuthzComponentAuthTests.testAuthGs!  4 4VX F   $%g.  y33T__E   F & ' 1 1 3 : :7 C ^b%8?%JK ' **D1rN)rrrrFrUrrrrArACs !2rrAceZdZdZdZy) ServiceTestsz) Tests for L{component.Service}. c`tj}ttj|y)zF L{component.Service} implements L{ijabber.IService}. N)rServicerrIService)rservices rtest_interfacezServiceTests.test_interfacefs"##%W%%w/rN)rrr__doc__r\rrrrWrWas 0rrWc$eZdZdZdZdZdZy)JabberServiceHarnessc.d|_d|_d|_y)NF)componentConnectedFlagcomponentDisconnectedFlagtransportConnectedFlagr0s rrzJabberServiceHarness.__init__os&+#).&&+#rcd|_yrC)rarr s rcomponentConnectedz'JabberServiceHarness.componentConnectedt &*#rcd|_yrC)rbr0s rcomponentDisconnectedz*JabberServiceHarness.componentDisconnectedws )-&rcd|_yrC)rcres rtransportConnectedz'JabberServiceHarness.transportConnectedzrgrN)rrrrrfrirkrrrr_r_ns, +.+rr_ceZdZdZy)JabberServiceManagerTestsctjdd}t}|j|g}|j j d}||_|j|j _|j|jd|j|j|tj|jd|j|j!d|jd|j"y)Nfoor'T)rServiceManagerr_setServiceParent getFactory buildProtocolrMrrr+r7rcdispatchr rOraconnectionLostrb)rsmsvcwlistrSs rtestSMz JabberServiceManagerTests.testSMs  % %eZ 8"$ R ]]_ * *4 0 "\\   s99: B 445 s99: $ s<<=rN)rrrryrrrrmrm~s>rrmc"eZdZdZdZdZdZy) RouterTestsz( Tests for L{component.Router}. ctj}gfd|_t}|j d|j |j dt|j|j |j |jdtjd}|jj||j |gy)zJ Test route registration and routing on incoming stanzas. c&j|Srr)elementrouteds rz+RouterTests.test_addRoute..sv}}W'=rz example.orgrJ)testnstestN) rRouterrouter addRoutesinkr7lenroutesr Elementsourcer*)rrouterpiperrs @r test_addRoutezRouterTests.test_addRoutes!!#= y tyy1 C ./ FMM-$@A..!34 ! 'F+rct}t}tj}|jd|j|jd|jg|j j dfdtjd}d|d<d|d<|j j||j|gy) z, Test routing of a message. component1.example.orgzcomponent2.example.org/*c&j|Srr~routgoings rrz(RouterTests.test_route..sHOOG.sX__W5Mrrrz example.comrr)rrs2srrrs @rtest_routeDefaultzRouterTests.test_routeDefaultsY i!!#0*//Bchh' t%MN 231v$t v& &8,rN)rrrr]rrrrrrr{r{s,"-$-rr{cFeZdZdZdZdZdZdZdZdZ dZ d Z d Z y ) !ListenComponentAuthenticatorTestsz> Tests for L{component.ListenComponentAuthenticator}. cg|_tjd}tj||_|jj |j_y)Nr!)r$rListenComponentAuthenticatorr r(rr*)rr&s rr1z'ListenComponentAuthenticatorTests.setUpsA !>>xH ",,];"kk00rc:|jjdy)zA Stub loseConnection because we are a transport. z no reasonN)r rur0s rloseConnectionz0ListenComponentAuthenticatorTests.loseConnections %%k2rcgfd}|j}||_|j||jd|j|j |j |jd|jd|j|jd|j|j|j |jd|jjfdy)zK The received stream header should set several attributes. c,j||fyrr~)event observerfn observerss raddOnetimeObserverzPListenComponentAuthenticatorTests.test_streamStarted..addOnetimeObservers   eZ0 1rNzz)rrrr3)r rmakeConnectionassertIdenticalr- assertFalse _headerSentr,r7versionassertNotIdentical assertTruer& onElement)rrrSrs @rtest_streamStartedz4ListenComponentAuthenticatorTests.test_streamStarteds  2^^ 2 $ T266* (  * , bff- ' $ 0 0 : :;Yr]Krcg}|j}|j|_|j||j d|j dt ||j d|djy)zM The received stream header should have a correct namespace. zprJzinvalid-namespacer3Nr rsendStreamErrorrr,r7r conditionr streamErrorsrSs r test_streamStartedWrongNamespacezBListenComponentAuthenticatorTests.test_streamStartedWrongNamespace sr ^^)00 $  * C -. ,l2.>.H.HIrcg}|j}|j|_|j||j d|j dt ||j d|djy)zJ The received stream header should have a 'to' attribute. z_rJzimproper-addressingr3Nrrs rtest_streamStartedNoToz8ListenComponentAuthenticatorTests.test_streamStartedNoTosr ^^)00 $  ?  C -. . R0@0J0JKrcg}|j}|j|j_t j d}|j d|jj||jd|dy)z< We expect a handshake element with a hash. )jabber:component:acceptr41234r3N) r rr& onHandshaker r addContentrr7)r handshakesrSr4s rtest_onElementz0ListenComponentAuthenticatorTests.test_onElement+sk ^^'1'8'8$NN#KL V$ ""9- B0rc<g}g}|j}|j|j_|j|_t j d}|jj||j||jd|djy)z9 Reject elements that are not handshakes )rmessagenot-authorizedr3N) r rr&rrr rrrr7r)rrrrSrs rtest_onElementNotHandshakez.authenticatedO LL rr(32532c0f7dbf1253c095b18b18e36d38d94c1256rKr3rJN) r rrOr-r&rr7r$r)rrrStheHashrs @rtest_onHandshakez2ListenComponentAuthenticatorTests.test_onHandshakeIs| ^^ i::MJ< $$W- R9 CJ'rcNg}gfd}|j}|jtj||j|_d|_d}|j j||jd|dj|jdty)zH Receiving a bad handshake should yield a stream error. c(j|yrr~rs rrzRListenComponentAuthenticatorTests.test_onHandshakeWrongHash..authenticatedarrrrr3rN) r rrOrrr-r&rr7rr)rrrrSrrs @rtest_onHandshakeWrongHashz;ListenComponentAuthenticatorTests.test_onHandshakeWrongHashZs  ^^ i::MJ)00 $$W- )<+;+E+EF CJ'rN) rrrr]r1rrrrrrrrrrrrrs81 3 L4J"L 1G ("(rrc4eZdZdZdZdZdZdZdZdZ y) XMPPComponentServerFactoryTestsz< Tests for L{component.XMPPComponentServerFactory}. ctj|_tj|jd|_|jj d|_td|j _y)Nr!component.example.org) rrrXMPPComponentServerFactoryfactoryrsr r thisEntityr0s rr1z%XMPPComponentServerFactoryTests.setUptsR&&(  ;;DKKR 33D9$'(?$@!rc|jj|jtj|jd|jj|jd|j j|j d|jj|j d|jjy)zY A new connection increases the stream serial count. No logs by default. rrJN) r rtSTREAM_CONNECTED_EVENTr7serialrr rawDataInFn rawDataOutFnr0s rtest_makeConnectionz3XMPPComponentServerFactoryTests.test_makeConnectionzs  0P0PQ DNN112 DLL//0 T4>>#=#=> T4>>#>#>?rc&d|j_|jj|jtj|j d|jj |j d|jjy)zD Setting logTraffic should set up raw data loggers. TN)r logTrafficr rtrrrrr0s rtest_makeConnectionLogTrafficz=XMPPComponentServerFactoryTests.test_makeConnectionLogTrafficsb#'   0P0PQ dnn&@&@A dnn&A&ABrcf|jj|jtjGddt}t j |}|jj|tj |jdt|j|y)zQ An observer for stream errors should trigger onError to log it. c eZdZy)?XMPPComponentServerFactoryTests.test_onError..TestErrorN)rrrrrr TestErrorrs rrrJN) r rtr ExceptionrFailureSTREAM_ERROR_EVENTr7rflushLoggedErrors)rrreasons r test_onErrorz,XMPPComponentServerFactoryTests.test_onErrorsz  0P0PQ   -  (D(DE C 6 6y ABCrc|jj|jtj|jd|jj |j |j|jj dy)zG Make sure a new stream is added to the routing table. rN)r rtrOassertInrrrr0s rtest_connectionInitializedz:XMPPComponentServerFactoryTests.test_connectionInitializedsb  0L0LM -t{{/A/AB  NNDKK../FG rc |jj|jtj|jjdtj|j d|j j y)zU Make sure a stream is removed from the routing table on disconnect. Nr)r rtrOSTREAM_END_EVENT assertNotInrrr0s rtest_connectionLostz3XMPPComponentServerFactoryTests.test_connectionLostsW  0L0LM i&@&@A 0$++2D2DErN) rrrr]r1rrrrrrrrrros*A @C D FrrN)r]hashlibrzope.interface.verifyrtwisted.pythonr twisted.trialrtwisted.words.protocols.jabberrrr "twisted.words.protocols.jabber.jidr twisted.words.xishr twisted.words.xish.utilityr rTestCaserrArWrYr_rmr{rrrrrrs.""HH2%.  %(*;*;%P2**2< 08$$ 0 +9,, + > 1 1>D<-(##<-~M((9(9M(`;Fh&7&7;Fr