Ϫf'dZddlmZddlmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZmZmZmZdd lmZdd lmZ dd lmZeZdZddlmZddlm Z dZ"GddejFZ$GddejFZ%GddejFZ&Gdde'Z(GddejFZ)GddejFZ*Gd d!ejFZ+Gd"d#ejFZ,Gd$d%ejZZ.Gd&d'ejFZ/Gd(d)ejFZ0Gd*d+Z1Gd,d-ejdZ3Gd.d/ejdZ4Gd0d1ejFZ5Gd2d3ejFZ6Gd4d5ejFZ7Gd6d7eZ8y#e!$rdZdZYjwxYw)8z8 Tests for L{twisted.words.protocols.jabber.xmlstream}. )skipIf) verifyObject)defertask)ConnectionLost)IProtocolFactory)failure) proto_helpers)unittest)errorijabberjid xmlstream)!GenericXmlStreamFactoryTestsMixin)domish)ssl)F)ClientTLSOptions)CertificateOptionsN)TzSSL not availableurn:ietf:params:xml:ns:xmpp-tlsc(eZdZdZdZdZdZdZy)HashPasswordTestsz. Tests for L{xmlstream.hashPassword}. cTtjdd}|jd|y)zS The sid and secret are concatenated to calculate sha1 hex digest. 12345secret(99567ee91b2c7cabf607f10cb9f4a3634fa820e0Nr hashPassword assertEqualselfhashs I/usr/lib/python3/dist-packages/twisted/words/test/test_jabberxmlstream.py test_basiczHashPasswordTests.test_basic)s'%%gx8 CTJcP|jttjddy)zB The session identifier must be a unicode object. s¹2345rN assertRaises TypeErrorrrr!s r#test_sidNotUnicodez$HashPasswordTests.test_sidNotUnicode0s )Y%;%;_hWr%cP|jttjddy)z8 The password must be a unicode object. rssecrétNr'r*s r#test_passwordNotUnicodez)HashPasswordTests.test_passwordNotUnicode6s )Y%;%;WFVWr%cTtjdd}|jd|y)z\ The concatenated sid and password must be encoded to UTF-8 before hashing. rusecrét(659bf88d8f8e179081f7f3b4a8e7d224652d2853Nrr s r#test_unicodeSecretz$HashPasswordTests.test_unicodeSecret<s'%%g}= CTJr%N)__name__ __module__ __qualname____doc__r$r+r-r0r%r#rr$sKX X Kr%rcXeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zy)IQTestszG Tests both IQ and the associated IIQResponseTracker callback. ctjd}d|_tj||_t j |_|j j|j_|jjtj|jjdtj|jd|_y)N otherhosttestnszmget)rConnectAuthenticator namespace XmlStreamrClockclock callLater _callLatermakeConnectionr StringTransport dataReceivedIQiq)r! authenticators r#setUpz IQTests.setUpIs!66{C "* ",,];ZZ\ $(JJ$8$8! %%m&C&C&EF ## = ,,t~~u5r%c~|j|jdd|j|jdy)Ntyper;id)rrG assertTruer*s r# testBasiczIQTests.testBasicVs. %0  &r%c@|jjj|jj |jdj d}|j |jjjd|zdzd|zdzgy)NrLzutf-8ss)r transportclearrGsendencodeassertInvalue)r!idBytess r#testSendzIQTests.testSendZs   &&(  ''$-&&w/ NN $ $ * * ,&069g%(99  r%cfd}jj}|j|j}|j djdz|S)Nc0j|ddy)NrKresult)r)rZr!s r#cbz&IQTests.testResultResponse..cbgs   VF^X 6r%rL)rGrR addCallbackrrE)r!r[dxss` r#testResultResponsezIQTests.testResultResponsefsM 7 GGLLN b ^^ 5 EFr%c|jj}|j|tj|j }|j d|jdz|S)NzrL)rGrR assertFailurer StanzaErrorrrEr!r^r_s r#testErrorResponsezIQTests.testErrorResponseqsO GGLLN 1e//0 ^^ 4twwt}DEr%cj}tj|j|jfd}|j d|d|j dy)z Test that untracked iq responses don't trigger any action. Untracked means that the id of the incoming response iq is not in the stream's C{iqDeferreds} dictionary. c>jt|ddy)NhandledF) assertFalsegetattr)rGr!s r#r[z*IQTests.testNonTrackedResponse..cbs   WRE: ;r%z/iqzN)rupgradeWithIQResponseTrackerri iqDeferreds addObserverrE)r!r_r[s` r#testNonTrackedResponsezIQTests.testNonTrackedResponseysV^^..r2 (  < ub"% 78r%c|jj}|j}|jd|jdz|j |jd|j |S)z Test if the deferred associated with an iq request is removed from the list kept in the L{XmlStream} object after it has been fired. r\rL)rGrRrrE assertNotInrmrds r# testCleanupzIQTests.testCleanupsW GGLLN ^^ 5 EF 7r%c|jj}|j}|jd|j |t |S)z Test if deferreds for iq's that haven't yet received a response have their errback called on stream disconnect. Closed by peer)rGrRrconnectionLostrbrrds r#testDisconnectCleanupzIQTests.testDisconnectCleanups@ GGLLN ^^ *+ 1n-r%cfdjj}|jjj d|S)z~ Test to make sure the errbacks cannot cause the iteration of the iqDeferreds to blow up in our face. ctjjj}|jyN)rrFrR addErrback)r r^ebr!s r#r{z'IQTests.testNoModifyingDict..ebs* T^^,113A LL r%rt)rGrRrzrru)r!r^r{s` @r#testNoModifyingDictzIQTests.testNoModifyingDicts=   GGLLN R %%&67r%cjd|j_|jj}|j|tj |j jddg|j|j j|j|jj|S)zK Test that an iq request with a defined timeout times out. <) rGtimeoutrRrbr TimeoutErrorr@pumpricallsrmr!r^s r#testRequestTimingOutzIQTests.testRequestTimingOuts} GGLLN 1i445 B  ))* 334r%cbd|j_|jj}|jj d|j j d|jdz|jjddg|j|jj|S)z Test that an iq request with a defined timeout does not time out when a response was received before the timeout period elapsed. r~rr\rL) rGrrRr@rArrErrirrs r#testRequestNotTimingOutzIQTests.testRequestNotTimingOuts  GGLLN  NN ' ' )DGGDM 9 A ))*r%c d|j_|jj}|j}|j d|j |t |j|jj|S)z| Test if timeouts for iq's that haven't yet received a response are cancelled on stream disconnect. r~rt) rGrrRrrurbrrir@rrds r#!testDisconnectTimeoutCancellationz)IQTests.testDisconnectTimeoutCancellationsc  GGLLN ^^ *+ 1n- ))*r%N)r1r2r3r4rIrNrWr`rerorrrvr|rrrr5r%r#r7r7DsC 6'   90     r%r7cleZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZy)XmlStreamTestscd|_yNT)gotStreamStartr!objs r# onStreamStartzXmlStreamTests.onStreamStart "r%cd|_yr) gotStreamEndrs r# onStreamEndzXmlStreamTests.onStreamEnds  r%cd|_yr)gotStreamErrorrs r# onStreamErrorzXmlStreamTests.onStreamErrorrr%cd|_d|_d|_tjtj }|j d|j|j d|j|j d|j|jtj||j_d|_d|_||_y)z9 Set up XmlStream and several observers. Fz//event/stream/start//event/stream/endz//event/stream/errorr:rrN)rrrrr> AuthenticatorrnrrrrCr StringTransportWithDisconnectionrPprotocolr=versionr!r_s r#rIzXmlStreamTests.setUps$!#  !8!8!: ; -t/A/AB +T-=-=> -t/A/AB -HHJK "   r%cn|j}|j|jjjddj d}|j d||j d||j d||j d||j |jy) z> Basic test on the header sent by sendHeader. rrk  Test events when a stream error is received. zN)rrErMrrrs r#test_receiveStreamErrorz&XmlStreamTests.test_receiveStreamError9sQ^^  ; )* ++, ))*r%cP|j}d|_|j|jj |j t jd|jd|jj|j|jy)z Test sendStreamError on an initiating xmlstream with a header sent. An error should be sent out and the connection lost. Tversion-unsupportedr%N rrrrPrQsendStreamErrorr StreamErrorassertNotEqualrUrMrrs r#test_sendStreamErrorInitiatingz-XmlStreamTests.test_sendStreamErrorInitiatingGsv ^^    5,,-BCD C!3!3!56 ))*r%cf|j}d|_|jj|j t j d|j|j|jd|jj|j|jy)z Test sendStreamError on an initiating xmlstream without having sent a header. In this case, no header should be generated. Also, the error should not be sent out on the stream. Just closing the connection. Trr%N) rrrPrQrr r assertNotrrrUrMrrs r#&test_sendStreamErrorInitiatingNoHeaderz5XmlStreamTests.test_sendStreamErrorInitiatingNoHeaderUs}^^   5,,-BCD r~~& bll0023 ))*r%cP|j}d|_|j|jj |j t jd|jd|jj|j|jy)z Test sendStreamError on a receiving xmlstream with a header sent. An error should be sent out and the connection lost. Frr%Nrrs r#test_sendStreamErrorReceivingz,XmlStreamTests.test_sendStreamErrorReceivingesv ^^    5,,-BCD C!3!3!56 ))*r%cf|j}d|_|jj|j t j d|j|j|jd|jj|j|jy)z Test sendStreamError on a receiving xmlstream without having sent a header. In this case, a header should be generated. Then, the error should be sent out on the stream followed by closing the connection. Frr%N) rrrPrQrr rrMrrrUrrs r#%test_sendStreamErrorReceivingNoHeaderz4XmlStreamTests.test_sendStreamErrorReceivingNoHeaderss}^^   5,,-BCD ' C!3!3!56 ))*r%c|j}|j|j}|j|j ||j|j |j y)zE Test resetting the XML stream to start a new layer. N)rrstreamresetrrr)r!r_rs r# test_resetzXmlStreamTests.test_resetsL^^    FBII. r~~&r%c:|j}|jd|j|jj d|jj t jd}|j||j|jj d|jj t jd}|j||j|jj dy)z: Test send with various types of objects. )r:presence)z http://etherx.jabber.org/streamsfeaturessN)rrRrrPrUrQrElement)r!r_els r# test_sendzXmlStreamTests.test_sends^^   ++-~>  ^^2 3   ++-~>  ^^L M   ++-/DEr%ctgggGfdd}|}tj|}|j|g|j|jdg|j d|jdt |j |jdgy)zM Test that the associated authenticator is correctly called. c,eZdZfdZfdZfdZy).TestAuthenticatorc(jdyryappend)r!connectionMadeCallss r#connectionMadezKXmlStreamTests.test_authenticator..TestAuthenticator.connectionMades#**40r%c(j|yryr)r! rootElementstreamStartedCallss r# streamStartedzJXmlStreamTests.test_authenticator..TestAuthenticator.streamStarteds"))+6r%c(j|yryr)r!r_associateWithStreamCallss r#associateWithStreamzPXmlStreamTests.test_authenticator..TestAuthenticator.associateWithStreams(//3r%N)r1r2r3rrr)rrrsr#TestAuthenticatorrs 1 7 4r%rNsr)rr>rrrElenr)r!rar_rrrs @@@r#test_authenticatorz!XmlStreamTests.test_authenticators!#%  4 4     # "78  $!45  - C 234   $!45r%N)r1r2r3rrrrIrrrrrrrrrrrrr5r%r#rrsS#!#" ( ( 7 6 + ++ ++ 'F$6r%rc eZdZy) TestErrorN)r1r2r3r5r%r#rrsr%rc*eZdZdZdZdZdZdZy)AuthenticatorTestsc~tj|_tj|j|_yry)rrrHr>r*s r#rIzAuthenticatorTests.setUps+&446",,T-?-?@r%c|j}|jtj|j d|j d|j |jd|j|j d|j|jd|j|j d|jy)e Test streamStart to fill the appropriate attributes from the stream header. rNinvalid) rrCr rDrErrassertIdenticalrr=rrrs r#test_streamStartz#AuthenticatorTests.test_streamStarts ^^ -779:   , T266* BLL1 T2>>2 r}}-r%c|j}|jtj|j d|j d|j y)z Test streamStart to fill the appropriate attributes from the stream header for a pre-XMPP-1.0 header. rrrNrrCr rDrErrrs r#test_streamStartLegacyz)AuthenticatorTests.test_streamStartLegacysK ^^ -779:  - ,r%c|j}|jtj|j d|j d|j y)z Test streamStart to fill the appropriate attributes from the stream header for a version with only one digit. zrNrrs r#test_streamBadVersionOneDigitz0AuthenticatorTests.test_streamBadVersionOneDigitsK ^^ -779:  9 ,r%c|j}|jtj|j d|j d|j y)z} Test streamStart to fill the appropriate attributes from the stream header for a malformed version. zrNrrs r#test_streamBadVersionNoNumberz0AuthenticatorTests.test_streamBadVersionNoNumbersK ^^ -779:  < ,r%N)r1r2r3rIrrrrr5r%r#rrsA.& - - -r%rc0eZdZdZdZdZdZdZdZy)ConnectAuthenticatorTestsc4d|_d|_tjd|_tj |j|_|jj d|j|jj d|jy)NFr//event/stream/authd//event/xmpp/initfailed) gotAuthenticated initFailurerr<rHr>rnonAuthenticated onInitFailedr*s r#rIzConnectAuthenticatorTests.setUp ss %&;;KH",,T-?-?@ ""#94;O;OP ""#O>OPr%cd|_yr)rrs r#r z)ConnectAuthenticatorTests.onAuthenticateds $r%c||_yry)r )r!r s r#r z&ConnectAuthenticatorTests.onInitFaileds "r%cGdd}|}|g|j_|jj|j g|jj|j |j y)zG Test successful completion of an initialization step. ceZdZdZy)9ConnectAuthenticatorTests.testSucces..Initializercyryr5r*s r# initializezDConnectAuthenticatorTests.testSucces..Initializer.initializesr%Nr1r2r3rr5r%r# Initializerrs r%rN)r initializersrHinitializeStreamrrMrr!rinits r# testSuccesz$ConnectAuthenticatorTests.testSuccessa   }'+f# ++- T^^889 --.r%cGdd}|}|g|j_|jj|j |g|jj|j |j |jd|j|j|jjty)z9 Test failure of an initialization step. ceZdZdZy):ConnectAuthenticatorTests.testFailure..Initializerctry)rr*s r#rzEConnectAuthenticatorTests.testFailure..Initializer.initialize-sr%Nrr5r%r#rr,s r%rN) rrrHrrrirassertNotIdenticalr rMcheckrrs r# testFailurez%ConnectAuthenticatorTests.testFailure's   }'+f# ++- $!rr example.comNz9r:test)rHr=rrCr rDrErrrrhostrrrrrTrrMrs r#rz*ConnectAuthenticatorTests.test_streamStart9s (0$ ^^ -779:   , "&&) 2<<0 (;(;< T2==1 t,,-  M  ("++6 --.r%N) r1r2r3rIr r rr rr5r%r#rrs!Q%#/ ;$/r%rc"eZdZdZdZdZdZy)ListenAuthenticatorTestsz4 Tests for L{xmlstream.ListenAuthenticator} c~tj|_tj|j|_yry)rListenAuthenticatorrHr>r*s r#rIzListenAuthenticatorTests.setUpYs+&::<",,T-?-?@r%c |j}|jtj|j d|j |j d|jd|j|jd|j |jd|j |jd|j|j d|j|jd|jjy)rNrrr jabber:clientr")rrCr rDrrrErrrrr=rrr%rs r#rz)ListenAuthenticatorTests.test_streamStart]s ^^ -779: T266*   , bff- GRVV, ",,7 T2>>2  (:(:;r%c|j}|jtj|j d|j |j ty)zD The generated session id must be a unicode object. rN)rrCr rDrEassertIsInstancerstrrs r# test_streamStartUnicodeSessionIDz9ListenAuthenticatorTests.test_streamStartUnicodeSessionIDrsK^^ -779:   bffc*r%N)r1r2r3r4rIrr/r5r%r#r'r'TsA<* +r%r'c~eZdZdZdZdZeedZeedZ eedZ dZ dZ d Z d Zd Zy ) TLSInitiatingInitializerTestscg|_g|_tj|_tj d|_tj|j |_|jj|j_ |jj|jjdtj|j|_ y)Nr"r)outputdonerrsavedSSLr<rHr>rrRrrETLSInitiatingInitializerrr*s r#rIz#TLSInitiatingInitializerTests.setUps  !  &;;MJ",,T-?-?@"kk00 %%' ## ; 66t~~F r%c.|jt_yry)r5rrr*s r#tearDownz&TLSInitiatingInitializerTests.tearDowns  r%ctj|jd|_|j|jjy)z> Passing required sets the instance variable. T)requiredN)rr6rrMr:r*s r#test_initRequiredz/TLSInitiatingInitializerTests.test_initRequireds366t~~PTU   **+r%ctjj_fdjj_fdj_fdj_jj}|jjtjjdtjjd}jd|jjt|j jj#dtzjgdj$|S) zN When TLS is wanted and SSL available, StartTLS is initiated. c:jjdSNTLSr4r)ctxr!s r#zDTLSInitiatingInitializerTests.test_wantedSupported..s 8H8H8Or%c:jjdSNrr@r*sr#rBzDTLSInitiatingInitializerTests.test_wantedSupported..tyy'7'7'@r%c:jjdSNheaderr@r*sr#rBzDTLSInitiatingInitializerTests.test_wantedSupported..DII,<,r?rrH)r rDrrPstartTLSrrrstartr]rResetrr3name NS_XMPP_TLSurirEr4)r!r^rKs` r#test_wantedSupportedz2TLSInitiatingInitializerTests.test_wantedSupporteds $1#@#@#B ,O  )@$F! IIOO  d&& 8 C ,-;;q> X]]3 hll3 ##$;k$IJ 3TYY?r%cfd}tjj_|jj_fdj_fdj_jj}jjdtzjgdj|S)z: The server certificate will be verified. cj|tj|jdjj dy)Nr"r?)r-rr _hostnamer4r)contextFactoryr!s r# fakeStartTLSzJTLSInitiatingInitializerTests.test_certificateVerify..fakeStartTLSs<  ! !.2B C   ^55} E II  U #r%c:jjdSrDr@r*sr#rBzFTLSInitiatingInitializerTests.test_certificateVerify..rEr%c:jjdSrGr@r*sr#rBzFTLSInitiatingInitializerTests.test_certificateVerify..rIr%rLrM) r rDrrPrNrrrrOrErRrr4)r!rYr^s` r#test_certificateVerifyz4TLSInitiatingInitializerTests.test_certificateVerifys  $ $1#@#@#B ,8  )@$F! IIOO  ##$;k$IJ 3TYY?r%cttjj_j_fd}t j j_|jj_fdj_ fdj_ jj}jjdtzjgdj|S)zH A custom contextFactory is passed through to startTLS. )configurationForTLSc`j|jjdyr>)assertIsr4r)rXrAr!s r#rYzQTLSInitiatingInitializerTests.test_certificateVerifyContext..fakeStartTLSs# MM#~ . II  U #r%c:jjdSrDr@r*sr#rBzMTLSInitiatingInitializerTests.test_certificateVerifyContext..rEr%c:jjdSrGr@r*sr#rBzMTLSInitiatingInitializerTests.test_certificateVerifyContext..rIr%rLrM)rrr6rrXr rDrPrNrrrOrErRrr4)r!rYr^rAs` @r#test_certificateVerifyContextz;TLSInitiatingInitializerTests.test_certificateVerifyContexts !"66 NN  $'   $$1#@#@#B ,8  )@$F! IIOO  ##$;k$IJ 3TYY?r%cdt_d|j_|jj }|j |j d|j dt|j|S)zX No StartTLS is initiated when wanted, not required, SSL not available. NFr) rrrr:rOr]rrr3rs r#"test_wantedNotSupportedNotRequiredz@TLSInitiatingInitializerTests.test_wantedNotSupportedNotRequiredsY "  IIOO  d&&- C ,-r%cdt_d|j_|jj }|j |tj |jdt|j|S)zS TLSNotSupported is raised when TLS is required but not available. NTr) rrrr:rOrbTLSNotSupportedrrr3rs r#test_wantedNotSupportedRequiredz=TLSInitiatingInitializerTests.test_wantedNotSupportedRequireds[ !  IIOO  1i778 C ,-r%ctjd}|jd|j|jf|i|j _d|j_|jj}|jdt|j|j|t j|S)zW TLSRequired is raised when TLS is not wanted, but required by server. rrKr:Fr)rr addElementrSrQrrrwantedrOrrr3rb TLSRequiredr!tlsr^s r#test_notWantedRequiredz4TLSInitiatingInitializerTests.test_notWantedRequiredsnnLM z"$'GGSXX#6"<   IIOO  C ,- 1i334r%c|tjd}|j|jf|i|j_d|j _d|j _|j j}|j|jd|jdt|j|S)zL No StartTLS is initiated when not wanted and not required. rjFNr)rrrSrQrrrrlr:rOr]rrr3rns r#test_notWantedNotRequiredz7TLSInitiatingInitializerTests.test_notWantedNotRequired snnLM$'GGSXX#6"<  "  IIOO  d&&- C ,-r%cdt_|jj}|j |tj |jj dtz|S)zN TLSFailed is raised when the server responds with a failure. rz)rrrrOrb TLSFailedrErRrs r# test_failedz)TLSInitiatingInitializerTests.test_failedsN IIOO  1i112 ##$;k$IJr%N)r1r2r3rIr8r;r skipWhenNoSSLrTr\rcrerhrprrrur5r%r#r1r1svG"&, ]( ]( ]2     r%r1ceZdZdZdZy)TestFeatureInitializerr#c,tjdSry)rsucceedr*s r#rOzTestFeatureInitializer.start*s}}T""r%N)r1r2r3featurerOr5r%r#rxrx's  G#r%rxc$eZdZdZdZdZdZy)%BaseFeatureInitiatingInitializerTestsctjtj|_t|j|_yry)rr>rrxrr*s r#rIz+BaseFeatureInitiatingInitializerTests.setUp/s-",,Y-D-D-FG*4>>: r%c|jjtj|jji|j_|jj S)zW Test that an advertized feature results in successful initialization. )rr{rrrrrr*s r#testAdvertizedz4BaseFeatureInitiatingInitializerTests.testAdvertized3sE$(99#4#4fnnTYYEVEV6W"Xyy##%%r%cd|j_|jtj|jj y)z Test that when the feature is not advertized, but required by the initializer, an exception is raised. TN)rr:r(rFeatureNotAdvertizedrr*s r#testNotAdvertizedRequiredz?BaseFeatureInitiatingInitializerTests.testNotAdvertizedRequired:s0 "  )88$)):N:NOr%czd|j_|jd|jjy)z Test that when the feature is not advertized, and not required by the initializer, the initializer silently succeeds. FN)rr:rrr*s r#testNotAdvertizedNotRequiredzBBaseFeatureInitiatingInitializerTests.testNotAdvertizedNotRequiredBs- #  T499#7#7#9:r%N)r1r2r3rIrrrr5r%r#r}r}.s;&P;r%r}c0eZdZdZdZdZdZdZdZy)ToResponseTestscNtjd}d|d<d|d<d|d<d|d <tj|d }|j |||j |dd|j |dd|j |dd |j |d dy ) zS Test that a response stanza is generated with addressing swapped. r+rGr;rKuser1@example.comtouser2@example.com/resourcefromstanza1rLrZN)rrr toResponserrr!stanzaresponses r#test_toResponsezToResponseTests.test_toResponseLs 78v*t 5v t ''9 1 &)+>? $)EF &)84 $3r%ctjd}d|d<d|d<tj|}|j |dd|j |j dy)zY Test that a response is generated from a stanza without a from address. rr;rKrrrN)rrrrrri hasAttributers r#test_toResponseNoFromz%ToResponseTests.test_toResponseNoFrom\sd 78v*t ''/ &)+>? ..t45r%ctjd}d|d<d|d<tj|}|j |j d|j |ddy)zW Test that a response is generated from a stanza without a to address. rr;rKrrrN)rrrrrirrrs r#test_toResponseNoToz#ToResponseTests.test_toResponseNoTogsc 78v5v''/ ..v67 $)EFr%ctjd}d|d<tj|}|j |j d|j |j dy)zY Test that a response is generated from a stanza without any addressing. r+messagechatrKrrNrrrrrirrs r#test_toResponseNoAddressingz+ToResponseTests.test_toResponseNoAddressingrs^ <=v''/ ..t45 ..v67r%ctjd}tj|}|j |j dy)zP Test that a proper response is generated without id attribute. rrLNrrs r# test_noIDzToResponseTests.test_noID|s< <=''/ ..t45r%ctjd}tj|}|j |j dy)zR Test that a proper response is generated without type attribute. rrKNrrs r# test_noTypezToResponseTests.test_noTypes< <=''/ ..v67r%N) r1r2r3rrrrrrr5r%r#rrKs!4 6 G868r%rceZdZdZdZdZy) DummyFactoryzJ Dummy XmlStream factory that only registers bootstrap observers. ci|_yry callbacksr*s r#__init__zDummyFactory.__init__s r%c"||j|<yryr)r!eventcallbacks r# addBootstrapzDummyFactory.addBootstraps (ur%N)r1r2r3r4rrr5r%r#rrs)r%rc.eZdZdZdZdZdZdZdZy)DummyXMPPHandlerzO Dummy XMPP subprotocol handler to count the methods are called on it. c.d|_d|_d|_y)Nr)doneMadedoneInitializeddoneLostr*s r#rzDummyXMPPHandler.__init__s   r%c$|jyry)rrs r#rCzDummyXMPPHandler.makeConnections r%c.|xjdz c_yNrrr*s r#rzDummyXMPPHandler.connectionMade  r%c.|xjdz c_yr)rr*s r#connectionInitializedz&DummyXMPPHandler.connectionInitializeds !r%c.|xjdz c_yr)rr!reasons r#ruzDummyXMPPHandler.connectionLostrr%N) r1r2r3r4rrCrrrur5r%r#rrs  "r%rceZdZdZdZdZy)FailureReasonXMPPHandlerz> Dummy handler specifically for failure Reason tests. cd|_y)NF)gotFailureReasonr*s r#rz!FailureReasonXMPPHandler.__init__s %r%cHt|tjrd|_yyr) isinstancer Failurerrs r#ruz'FailureReasonXMPPHandler.connectionLosts fgoo .$(D ! /r%N)r1r2r3r4rrur5r%r#rrs&)r%rc(eZdZdZdZdZdZdZy)XMPPHandlerTestsz- Tests for L{xmlstream.XMPPHandler}. c\ttjtjy)zN L{xmlstream.XMPPHandler} implements L{ijabber.IXMPPHandler}. N)rr IXMPPHandlerr XMPPHandlerr*s r#test_interfacezXMPPHandlerTests.test_interfaces W))9+@+@+BCr%cGdd}tj}||_|jd|j dg|jj y)zP Test that data is passed on for sending by the stream manager. ceZdZdZdZy)6XMPPHandlerTests.test_send..DummyStreamManagercg|_yry)outlistr*s r#rz?XMPPHandlerTests.test_send..DummyStreamManager.__init__s ! r%c:|jj|yry)rr)r!datas r#rRz;XMPPHandlerTests.test_send..DummyStreamManager.sends ##D)r%N)r1r2r3rrRr5r%r#DummyStreamManagerrs  " *r%rrN)rrparentrRrr)r!rhandlers r#rzXMPPHandlerTests.test_sendsN  * *'')+- ]# -'..*@*@Ar%c"Gddtj}|}tjtj}|j ||j |j |j||jy)zY Test that makeConnection saves the XML stream and calls connectionMade. ceZdZdZy)=XMPPHandlerTests.test_makeConnection..TestXMPPHandlercd|_yrrr*s r#rzLXMPPHandlerTests.test_makeConnection..TestXMPPHandler.connectionMades $ r%N)r1r2r3rr5r%r#TestXMPPHandlerrs %r%rN)rrr>rrCrMrr)r!rrr_s r#test_makeConnectionz$XMPPHandlerTests.test_makeConnectionsm  %i33 %"#  !8!8!: ;r" (() R!2!23r%ctj}tjtj}|j ||j t |jd|jy)zB Test that connectionLost forgets the XML stream. N)rrr>rrCru Exceptionr)r!rr_s r#test_connectionLostz$XMPPHandlerTests.test_connectionLosts_'')  !8!8!: ;r"y{+ T7#4#45r%N)r1r2r3r4rrrrr5r%r#rrsD B" 46r%rc(eZdZdZdZdZdZdZy)XMPPHandlerCollectionTestsz7 Tests for L{xmlstream.XMPPHandlerCollection}. c6tj|_yry)rXMPPHandlerCollection collectionr*s r#rIz XMPPHandlerCollectionTests.setUps#99;r%cLttj|jy)zZ L{xmlstream.StreamManager} implements L{ijabber.IXMPPHandlerCollection}. N)rr IXMPPHandlerCollectionrr*s r#rz)XMPPHandlerCollectionTests.test_interfaces W33T__Er%ct}|j|j|j||j|j |j|j y)z: Test the addition of a protocol handler. N)rsetHandlerParentrrTrrr!rs r#test_addHandlerz*XMPPHandlerCollectionTests.test_addHandlersH#$  1 gt/ T__gnn=r%ct}|j|j|j|j|j ||j|j d|j y)z5 Test removal of a protocol handler. N)rrrdisownHandlerParentrqrrrs r#test_removeHandlerz-XMPPHandlerCollectionTests.test_removeHandler sX#$  1##DOO4 $//2 T7>>2r%N)r1r2r3r4rIrrrr5r%r#rrs<F >3r%rcdeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZy)StreamManagerTestsz/ Tests for L{xmlstream.StreamManager}. cLt}tj||_yry)rr StreamManager streamManager)r!factorys r#rIzStreamManagerTests.setUps.&44W=r%c$|j}|jd|j|jg|j|j|j |j jd|j|j|j jd|j|j|j jd|j|j|j jdy)zM Test correct initialization and setup of factory observers. Nz//event/stream/connectedrrr) rrrrhandlers _connectedrr_authd _disconnectedinitializationFailed)r!sms r#r$zStreamManagerTests.test_basics   T2<<0 R[[)  MM2:://0JK  BJJ$8$89O$PQ ))2::+?+?@T+UV   # #RZZ%9%9:S%T r%cj|j}t}|j|tjtj }|j ||jd|j|jd|j|jd|jy)z Test that protocol handlers have their connectionMade method called when the XML stream is connected. rrN) rrrrr>rrrrrrr!rrr_s r#test_connectedz!StreamManagerTests.test_connected.s   "$  $  !8!8!: ; b G,,- G334 G,,-r%c2|j}t}|j|tjtj }|j ||jd|j|jd|jy)zP Test raw data functions unset when logTraffic is set to False. N) rrrrr>rrr rawDataInFn rawDataOutFnrs r#test_connectedLogTrafficFalsez0StreamManagerTests.test_connectedLogTrafficFalse<sr  "$  $  !8!8!: ; b T2>>2 T2??3r%c@|j}d|_t}|j|t j t j }|j||jd|j|jd|jy)zM Test raw data functions set when logTraffic is set to True. TN) r logTrafficrrrr>rrrrrrs r#test_connectedLogTrafficTruez/StreamManagerTests.test_connectedLogTrafficTrueHsy   "$  $  !8!8!: ; b bnn5 boo6r%cj|j}t}|j|tjtj }|j ||jd|j|jd|j|jd|jy)z Test that protocol handlers have their connectionInitialized method called when the XML stream is initialized. rrN) rrrrr>rrrrrrrs r# test_authdzStreamManagerTests.test_authdUs   "$  $  !8!8!: ; "  G,,- G334 G,,-r%cj|j}t}|j|tjtj }|j ||jd|j|jd|j|jd|jy)z Test that protocol handlers have their connectionLost method called when the XML stream is disconnected. rrN) rrrrr>rrrrrrrs r#test_disconnectedz$StreamManagerTests.test_disconnectedcs   "$  $  !8!8!: ;  G,,- G334 G,,-r%c|j}t}|j||jt j t d|jd|jy)z A L{STREAM_END_EVENT} results in L{StreamManager} firing the handlers L{connectionLost} methods, passing a L{failure.Failure} reason. z no reasonTN) rrrrr rrrrr!rrs r#test_disconnectedReasonz*StreamManagerTests.test_disconnectedReasonqsW   *,  $ ;)?@A w778r%c|j}t}|j||jd|j|jd|j |jd|j y)zN Test the addition of a protocol handler while not connected. rN)rrrrrrrrs r#rz"StreamManagerTests.test_addHandler|sg  "$  $ G,,- G334 G,,-r%c|j}tjtj}|j ||j |t }|j||jd|j|jd|j|jd|jy)a Test the addition of a protocol handler after the stream have been initialized. Make sure that the handler will have the connected stream passed via C{makeConnection} and have C{connectionInitialized} called. rrN) rrr>rrrrrrrrr)r!rr_rs r#test_addHandlerInitializedz-StreamManagerTests.test_addHandlerInitializeds    !8!8!: ; b " "$  $ G,,- G334 G,,-r%ctjtj}tj|}|j d}t j |_|j|jd|j|d|jd|jd|jjy)z Test send when the stream has been initialized. The data should be sent directly over the XML stream. Nrrrr)rXmlStreamFactoryrr buildProtocolr rDrPrrEdispatchrRrrUr!rrr_s r#test_sendInitializedz'StreamManagerTests.test_sendInitializeds ,,Y-D-D-FG  $ $W -  " "4 ($446    - B./   ););)=>r%c<tjtj}tj|}t }|j ||j d}tj|_ |jd|jd|jj|jd|jd|j|jd|jj|jd|jd|jd|j!|d|jd|jj|j#|jy)z Test send when there is no established XML stream. The data should be cached until an XML stream has been established and initialized. Nrr%rrrr)rr rrr addHandlerrr rDrPrRrrU _packetQueuerrErrir!rrrr_s r#test_sendNotConnectedz(StreamManagerTests.test_sendNotConnecteds6,,Y-D-D-FG  $ $W -"$ g  " "4 ($446    bll0023 (:;  bll0023 (:;  - B./ ););)=> )r%ctjtj}tj|}|j d}t j |_|j|jd|jd|jd|jj|jd|jdy)z Test send when the stream is connected but not yet initialized. The data should be cached until the XML stream has been initialized. Nrrr%r)rr rrrr rDrPrrErRrrUrrs r#test_sendNotInitializedz*StreamManagerTests.test_sendNotInitializeds ,,Y-D-D-FG  $ $W -  " "4 ($446    -   bll0023 (:;r%ctjtj}tj|}t }|j ||j d}|jtj|_ |jd|jd|jd|jj|jd|jdy)z Test send after XML stream disconnection. The data should be cached until a new XML stream has been established and initialized. Nrr%r)rr rrrrrrr rDrPrurRrrUrrs r#test_sendDisconnectedz(StreamManagerTests.test_sendDisconnecteds,,Y-D-D-FG  $ $W -"$ g  " "4 ( $446  $   bll0023 (:;r%N)r1r2r3r4rIr$rrrrrrrr rrrrr5r%r#rrsN> . 4 7 . . 9 ..(?(*@<(.TestAuthenticatorcg|_yry) xmlstreamsr*s r#rzEXmlStreamServerFactoryTests.setUp..TestAuthenticator.__init__s "$r%c:|jj|yry)r!rrs r#rzPXmlStreamServerFactoryTests.setUp..TestAuthenticator.associateWithStreams&&r*r%N)r1r2r3rrr5r%r#rrs  % +r%rcSryr5)rsr#authenticatorFactoryz?XmlStreamServerFactoryTests.setUp..authenticatorFactory s $& &r%N)rXmlStreamServerFactoryr)r!r$rs @r#rIz!XmlStreamServerFactoryTests.setUps'  + + '!778LM r%c8tt|jy)z< L{XmlStreamServerFactory} is a L{Factory}. N)rrrr*s r#rz*XmlStreamServerFactoryTests.test_interfaces %t||4r%c|jjd}|j|g|jjy)a The authenticator factory should be used to instantiate the authenticator and pass it to the protocol. The default protocol, L{XmlStream} stores the authenticator it is passed, and calls its C{associateWithStream} method. so we use that to check whether our authenticator factory is used and the protocol instance gets an authenticator. N)rrrrHr!rs r#,test_buildProtocolAuthenticatorInstantiationzHXmlStreamServerFactoryTests.test_buildProtocolAuthenticatorInstantiations6\\ ' ' - "r//::;r%cz|jjd}|j|tjy)zV The protocol factory creates Jabber XML Stream protocols by default. N)rrr-rr>rs r#test_buildProtocolXmlStreamz7XmlStreamServerFactoryTests.test_buildProtocolXmlStream#s.\\ ' ' - b)"5"56r%c|jjd}|jjd}|j|||j|j|jy)z Subsequent calls to buildProtocol should result in different instances of the protocol, as well as their authenticators. N)rrrrH)r!xs1xs2s r#test_buildProtocolTwicez3XmlStreamServerFactoryTests.test_buildProtocolTwice*sX ll((.ll((. S)  1 133D3DEr%N) r1r2r3r4rIrr(r*r.r5r%r#rrs"N"5 <7Fr%r)9r4r rzope.interface.verifyrtwisted.internetrrtwisted.internet.errorrtwisted.internet.interfacesrtwisted.pythonr twisted.testr twisted.trialtwisted.words.protocols.jabberr r rr!twisted.words.test.test_xmlstreamrtwisted.words.xishrr_sslrvtwisted.internet._sslverifyrtwisted.internet.sslr ImportErrorrRTestCaserr7rrrrrr'r1 BaseFeatureInitiatingInitializerrxr}rrrrrrrrrr5r%r#r?s.(18"&"IIO% 8, CM<7/ K))K@_h_DX6X&&X6v  @-**@-FI/ 1 1I/X*+x00*+ZcH$5$5cL#YGG#;H,=,=;:?8h''?8D ) )y,,. )y44 )36x((36l3!2!23Db<**b