ϪfhwdZddlZddlmZmZddlmZddlmZm Z ddl m Z ddl m Z mZddlmZmZmZmZdd lmZdd lmZmZdd lmZdd lmZdd lmZmZmZm Z m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* eddZ+GddejZZ.Gdde/Z0Gdde1Z2Gdde%Z3Gdde%Z4Gdde%Z5Gdd e3Z6Gd!d"e!jnZ8Gd#d$e!jLZ9Gd%d&e!jLZ:Gd'd(ejZZ;Gd)d*e;Z<Gd+d,ejZZ=Gd-d.Z>Gd/d0e>ejZZ?Gd1d2e>ejZZ@Gd3d4e;ZAGd5d6e;ZBGd7d8ejZZCGd9d:ejZZDGd;d.AsyncResourcecSNr&)selfresults >/usr/lib/python3/dist-packages/twisted/web/test/test_xmlrpc.py xmlrpc_asyncz:AsyncXMLRPCTests.setUp..AsyncResource.xmlrpc_async=s N)__name__ __module__ __qualname__r.r,sr- AsyncResourcer(<s r/r4) rrequestmethodrrrdumpscontentrDeferredr,rresource)r+r4r,s @r-setUpzAsyncXMLRPCTests.setUp3sp#RD) $ ' w (;< <   %~~// F & r/c|jj|j|j|jjg|j j dtjdj|jj}|j|d|j|jjdy)z If an L{XMLRPC} C{xmlrpc_*} method returns a L{defer.Deferred}, the response to the request is the result of that L{defer.Deferred}. r,r/)r3NN) r:renderr5 assertEqualwrittenr,callbackrloadsjoinfinished)r+resps r-test_deferredResponsez&AsyncXMLRPCTests.test_deferredResponseBs T\\* --r2 X&sxx (<(<=> 23 ..2r/c|jj|j|jjt j t d|jjd|j|jjg|j|jjdy)a While waiting for the L{Deferred} returned by an L{XMLRPC} C{xmlrpc_*} method to fire, the connection the request was issued over may close. If this happens, neither C{write} nor C{finish} is called on the request. Simulatedr,rN) r:r>r5processingFailedrFailurerr,rAr?r@rDr+s r- test_interruptedDeferredResponsez1AsyncXMLRPCTests.test_interruptedDeferredResponsePs T\\* %%goon[6Q&RS X& --r2 ..2r/N)r0r1r2__doc__r;rFrLr&r/r-r!r!.s ( 3 3r/r!c eZdZy)TestRuntimeErrorNr0r1r2r&r/r-rOrO^r/rOc eZdZy)TestValueErrorNrPr&r/r-rSrSbrQr/rSceZdZdZdZdZdZdZgdgdge_dZ gd ge _d Z d Z d Z d Z dZdZdZdZde_edZdZy)Test*c|Sr*r&)r+args r- xmlrpc_echozTest.xmlrpc_echons r/c ||zS)z0 This function add two numbers. r&)r+abs r- xmlrpc_addzTest.xmlrpc_addrs 1u r/intraradoublercrcc ||gS)zC This function puts the two arguments in an array. r&)r+stringnums r- xmlrpc_pairzTest.xmlrpc_pair~s}r/arrayrerac,tj|S)Help for defer.)rsucceedr+xs r- xmlrpc_deferzTest.xmlrpc_defers}}Qr/c<tjtSr*)rfailrSrKs r-xmlrpc_deferFailzTest.xmlrpc_deferFailszz.*++r/ctr*)rOrKs r- xmlrpc_failzTest.xmlrpc_failsr/c.tjddS)N hellorFaultrKs r- xmlrpc_faultzTest.xmlrpc_faults||B((r/cTtjtjddS)Nhi)rrqrryrKs r-xmlrpc_deferFaultzTest.xmlrpc_deferFaultszz&,,r4011r/c@d}||k7rtjddS|S)z8 Used to test that we can pass Unicode. ☃ zPayload not unicode snowmanrx)r+payloadsnowmans r-xmlrpc_snowmanzTest.xmlrpc_snowmans( g <<$AB Br/cdddggddS)Nr^crvfoor]Dr&rKs r-xmlrpc_complexzTest.xmlrpc_complexs3B'e44r/c ||Sr*r&)r+mapkeys r- xmlrpc_dictzTest.xmlrpc_dicts 3xr/Help for dict.c&|jdz|zS)z A method decorated with L{withRequest} which can be called by a test to verify that the request object really is passed as an argument.  )r6)r+r5others r-xmlrpc_withRequestzTest.xmlrpc_withRequests$ NN     r/c tj||S#tj$r3|j dr tj |j dwxYw)NSESSIONzSession non-existent/expired.)rlookupProcedurerNoSuchFunction startswithrySESSION_EXPIRED)r+ procedurePaths r-rzTest.lookupProcedures_ ))$ > >$$ '' 2ll((*I  s AAN)r0r1r2FAILURE NOT_FOUNDrr[r_ signaturergrorrrtrzr~rrrhelprrrr&r/r-rUrUfsGIO &J  88K ,)25(K     r/rUceZdZdZdZdZy)TestLookupProcedurez} This is a resource which customizes procedure lookup to be used by the tests of support for this customization. c|Sr*r&rms r-echozTestLookupProcedure.echosr/cl|dk(r |jStj|jd|d)zs Lookup a procedure from a fixed set of choices, either I{echo} or I{system.listeMethods}. rz procedure z not found)rrrr)r+ procedureNames r-rz#TestLookupProcedure.lookupProcedures; F "99 ## NNjzB  r/N)r0r1r2rMrrr&r/r-rrs   r/rceZdZdZdZy)TestListProceduresz This is a resource which customizes procedure enumeration to be used by the tests of support for this customization. cdgS)zW Return a list of a single method this resource will claim to support. rr&rKs r-listProceduresz!TestListProcedures.listProceduress wr/N)r0r1r2rMrr&r/r-rrs  r/rc"eZdZdZdZdZdZy)TestAuthHeaderzU This is used to get the header info so that we can test authentication. c<tj|d|_yr*)rU__init__r5rKs r-rzTestAuthHeader.__init__s d r/c<||_tj||Sr*)r5rUr>)r+r5s r-r>zTestAuthHeader.renders {{4))r/cj|jj|jjfSr*)r5getUser getPasswordrKs r-xmlrpc_authinfozTestAuthHeader.xmlrpc_authinfos'||##%t||'?'?'AAAr/N)r0r1r2rMrr>rr&r/r-rrs *Br/rc"eZdZdZdZdZdZy)TestQueryProtocolz_ QueryProtocol for tests that saves headers received and sent, inside the factory. cx|j|j_tjj |yr*) transportfactoryr QueryProtocolconnectionMaderKs r-rz TestQueryProtocol.connectionMades&!% ++D1r/cR||jj|j<yr*)rheaderslowerr+rvals r- handleHeaderzTestQueryProtocol.handleHeaders,/ SYY[)r/c||jj|j<tjj |||y)zA Keep sent headers so we can inspect them later. N)r sent_headersrrr sendHeaderrs r-rzTestQueryProtocol.sendHeaders625 !!#))+.''c37r/N)r0r1r2rMrrrr&r/r-rrs 208r/rceZdZdZeZdZy)TestQueryFactoryzE QueryFactory using L{TestQueryProtocol} for saving headers. cfi|_i|_tjj|g|i|yr*)rrrrr)r+argskwargss r-rzTestQueryFactory.__init__s/ $$T;D;F;r/N)r0r1r2rMrprotocolrr&r/r-rrs!H.check_server_headers^sR   q!))/:.check_client_headersds}   q!..}=?S    q!..?*    T^^A.;;z)XMLRPCTests.test_errors..~ 2 A A( Kr/))rVrq)rV deferFail)rvfault)rW noSuchMethod)r| deferFault)rX SESSION_TESTc<j|j|Sr*)r? faultCode)exccoder+s r-rz)XMLRPCTests.test_errors..s1A1A#--QU1Vr/TrcjD]!}j|jdd#jdt ddj }ddj }t |trj|tn,j|tj|tjtty)Nrrrr log_failurer=) rr?r assertEqualslenvalue isinstancerSassertIsInstancerOflushLoggedErrors)rrf1f2 logObserverr+s r-cbz#XMLRPCTests.test_errors..cbs>>   OOO46P    a[!1 2Q .44BQ .44B"n-%%b*:;%%b*:;%%b.9  " "#3^ Dr/)r r r r criticalr addObserver addCleanuprr assertFailurerryrrrr)r+rr methodNamerr$r r#s` @@r- test_errorszXMLRPCTests.test_errorsrs+, ' 1(BSBSTU  &&x0 KL !  D* '' 3A""1fll3A MM4V W IIaL    rD 9 E" br/cvfd|jjddd}|jjjj d|j |jjjj d|j|tj}|S)z A deferred from the Proxy can be cancelled, disconnecting the L{twisted.internet.interfaces.IConnector}. c<t|i|_jSr*)rf)rkwrs r-rz(XMLRPCTests.test_cancel..factorys.;;GI99 r/rrr disconnected) rrassertNotEqualr-rstatecancelr?r(rCancelledError)r+rrs @r- test_cancelzXMLRPCTests.test_cancels   JJw  * *5!Q 7 GII//55~F   ,,22NC   q%"6"6 7r/ctjt}|jdt dj fz}fd}|j ||S)zN A classic GET on the xml server should return a NOT_ALLOWED. sGETrcZj|jtjyr*)r?rr NOT_ALLOWED)responser+s r- checkResponsez0XMLRPCTests.test_errorGet..checkResponses   X]]D,<,< =r/)rAgentrr5rrr)r+agentrr9s` r- test_errorGetzXMLRPCTests.test_errorGetsL W% MM&-0F$))0U"V W > m$r/c 2tjt}|jt dj fzdtj td}|jtjfd}|j||S)zL Test that an invalid XML input returns an L{xmlrpc.Fault}. rsPOSTsfoo)urir6 bodyProducercdjtjtj|yr*) assertRaisesrryrrB)r,r+s r-r$z,XMLRPCTests.test_errorXMLContent..cbs   fllIOOV Dr/) rr:rr5rrFileBodyProducerrrreadBody)r+r;rr$s` r-test_errorXMLContentz XMLRPCTests.test_errorXMLContentsz W% MM4 |CD00A   foo& E br/ctj}|jjd|}|j |j ||S)z If an L{xmlrpclib.DateTime} is passed as an argument to an XML-RPC call and then returned by the server unmodified, the result should be equal to the original object. r)rDateTimerrrr?)r+whenrs r-test_datetimeRoundtripz"XMLRPCTests.test_datetimeRoundtripsC !!# JJL # #FD 1 d&&-r/cttttjgt j jfdjjdd}d}jtd|j|t}fd}|j||S)a. If it is not possible to encode a response to the request (for example, because L{xmlrpclib.dumps} raises an exception when encoding a L{Fault}) the exception which prevents the response from being generated is logged and the request object is finished anyway. rc.tjSr*r r sr-rz6XMLRPCTests.test_doubleEncodingError..rr/rr#ctd)NzCannot encode anything at all!) RuntimeError)rrs r- fakeDumpsz7XMLRPCTests.test_doubleEncodingError..fakeDumpss?@ @r/r7cjdtjddjtj tj tdy)Nr=rr)rrrrrLr?r )ignoredr#r+s r-cbFailedz6XMLRPCTests.test_doubleEncodingError..cbFailedsW   a[!1 2  ! !+a."?"E"E| T   S!7!7 !EF Jr/)r r r r r%rr&r'rrpatchrr( Exceptionr)r+rrMrPr r#s` @@r-test_doubleEncodingErrorz$XMLRPCTests.test_doubleEncodingErrors+, ' 1(BSBSTU  &&x0 KL JJL # #FB / A 9gy1   q) , K hr/cpjjdd}fd}|j|S)zV The connection to the web server is closed when the request is done. rr#cj\}j|jjj |jj yr*)r assertFalser connected assertTruer/)rOrr+s r- responseDonezBXMLRPCTests.test_closeConnectionAfterRequest..responseDones@IW   W..88 9 OOG--:: ;r/r)r+rrYs` r- test_closeConnectionAfterRequestz,XMLRPCTests.test_closeConnectionAfterRequests3 JJL # #FB / < }}\**r/ct}tjdd|}|jd|j |j dddy)z For I{HTTP} URIs, L{xmlrpc.Proxy.callRemote} passes the value it received for the C{connectTimeout} parameter as the C{timeout} argument to the underlying connectTCP call. shttp://127.0.0.1:69g@connectTimeoutr someMethodrrN)r rrrr? tcpClientsr+rrs r-test_tcpTimeoutzXMLRPCTests.test_tcpTimeout sP  / "3  & ++A.q137r/zOpenSSL not presentct}tjdd|}|jd|j |j dddy)z For I{HTTPS} URIs, L{xmlrpc.Proxy.callRemote} passes the value it received for the C{connectTimeout} parameter as the C{timeout} argument to the underlying connectSSL call. shttps://127.0.0.1:69g@r\r^rN)r rrrr? sslClientsr`s r-test_sslTimeoutzXMLRPCTests.test_sslTimeoutsP / #C  & ++A.q137r/r*)r0r1r2r;rrrrrr*r4r<rDrHrSrZrarsslSkiprer&r/r-rr%sf & ="8.`" $ !F + 8 G*+ 8, 8r/rceZdZdZddZy)XMLRPCProxyWithoutSlashTestsz3 Test with proxy that doesn't add a slash. Nctjtd|jz}||j|_|S||_|S)Nhttp://127.0.0.1:%drrs r-rz"XMLRPCProxyWithoutSlashTests.proxy.sF LL'.listedds MM% ,r/)rrrnrrr)r+r:rrzs` r-test_listMethodsz1XMLRPCPublicLookupProcedureTests.test_listMethodsYsP &'" (# JJ ! !"6 7 - fr/N)r0r1r2rMrnrqr*r{r&r/r-rlrl7s T  r/rlc"eZdZdZdZdZdZy)SerializationConfigMixinas Mixin which defines a couple tests which should pass when a particular flag is passed to L{XMLRPC}. These are not meant to be exhaustive serialization tests, since L{xmlrpclib} does all of the actual serialization work. They are just meant to exercise a few codepaths to make sure we are calling into xmlrpclib correctly. @ivar flagName: A C{str} giving the name of the flag which must be passed to L{XMLRPC} to allow the tests to pass. Subclasses should set this. @ivar value: A value which the specified flag will allow the serialization of. Subclasses should set this. c |jdi}tjdtjt di|d|_|j|j j|j jj|_ tjtd|jfzfi||_y)zO Create a new XML-RPC server with C{allowNone} set to C{True}. TrrrrNr&)flagNamerrrrrUrr'rrrrrrr)r+rs r-r;zSerializationConfigMixin.setUp~s--&"" v{{4>&>*k  ,,-FFNN$)) \\ 0DII<? @ DJ  r/c|jjd|j}|j|j|j|S)zY C{self.value} can be round-tripped over an XMLRPC method call/response. rrrrrr?rts r-test_roundtripValuez,SerializationConfigMixin.test_roundtripValues; JJ ! !'4:: 6 d&& 3r/c|jjdd|ji}|j|jd|ji|S)zz A C{dict} which contains C{self.value} can be round-tripped over an XMLRPC method call/response. rr]rrts r-test_roundtripNestedValuez2SerializationConfigMixin.test_roundtripNestedValuesE JJ ! !'C+< = d&&djj(9:r/N)r0r1r2rMr;rrr&r/r-r}r}ns   r/r}ceZdZdZdZdZy)XMLRPCAllowNoneTestszF Tests for passing L{None} when the C{allowNone} flag is set. allowNoneN)r0r1r2rMrrr&r/r-rrsH Er/rcBeZdZdZdZej ddddddZy ) XMLRPCUseDateTimeTestszd Tests for passing a C{datetime.datetime} instance when the C{useDateTime} flag is set. useDateTimeirvr-;N)r0r1r2rMrdatetimerr&r/r-rrs* H H  dBAr2 6Er/rc6eZdZdZdZdZdZdZdZdZ dZ y ) XMLRPCAuthenticatedTestsz] Test with authenticated proxy. We run this with the same input/output as above. susernamesasecretctjdtjt d|_|j j j|_g|_yr) rrrrrrrrrrKs r-r;zXMLRPCAuthenticatedTests.setUpsH"" v{{>+,  FFNN$)) r/c8dt|jt|j|jfz}t j t |}|jd}|j|j|j|jg|S)Nzhttp://%s:%s@127.0.0.1:%d/authinfo) ruserpasswordrrrrrrr?)r+urlrrs r-test_authInfoInURLz+XMLRPCAuthenticatedTests.test_authInfoInURLsy*  #  ' II.   LLs+ , LL $ d&&DMM(BCr/ctjtd|jfz|j|j }|j d}|j|j|j|j g|S)Nrr rrrrrrrrr?r+rrs r-test_explicitAuthInfoz.XMLRPCAuthenticatedTests.test_explicitAuthInfosh LL 0DII<? @ II MM  LL $ d&&DMM(BCr/c|jdz}tjtd|jfz|j |}|j d}|j|j|j |g|S)z C{QueryProtocol} uses the C{base64.b64encode} function to encode user name and password in the I{Authorization} header, so that it doesn't embed new lines when using long inputs. (rr) rrrrrrrrr?)r+ longPasswordrrs r-test_longPasswordz*XMLRPCAuthenticatedTests.test_longPasswordsp }}r) LL 0DII<? @ II   LL $ d&&L(ABr/ctjtd|jfz|j|j }|j d}|j|j|j|j g|S)Nzhttp://wrong:info@127.0.0.1:%d/rrrs r-test_explicitAuthInfoOverridez6XMLRPCAuthenticatedTests.test_explicitAuthInfoOverridesh LL ;tyylJ K II MM  LL $ d&&DMM(BCr/N) r0r1r2rMrrr;rrrrr&r/r-rrs, DH  r/rc$eZdZdZdZdZdZy)XMLRPCIntrospectionTestsct}t|tjdt j |d|_|j jj|_g|_ yr) rUrrrrrrrrr)r+rs r-r;zXMLRPCIntrospectionTests.setUpsO ""1fkk&&9[QFFNN$)) r/crfd}jjd}|j||S)NcN|jj|gdy)N)rrrrrrrrqrrrrvsystem.methodHelpsystem.methodSignaturer)sortr?)methsr+s r- cbMethodsz.cbMethodss" JJL    r/rvr)r+rrs` r-r{z)XMLRPCIntrospectionTests.test_listMethodss2 . JJL # #$8 9 i r/cgd}g}|D]R\}}|jjd|}|j|j||j |Tt j |dS)N))rrk)rqr#)rrrTrrr+ inputOutputsrrexpectedrs r-test_methodHelpz(XMLRPCIntrospectionTests.test_methodHelpsp * ND( ''(;TBA MM$**H 5 IIaL !!"t< Test the behaviour of L{QueryFactory.parseResponse}. c tddddddd|_tjd|_d|_t jt|_ y)Nr$Fr&)pathhostr6rrrr)r#z invalid xml) rrrr7 goodContents badContentsrrJrreasonrKs r-r;z$QueryFactoryParseResponseTests.setUpTsV) &OOE2(oon&67 r/c|jj}|j|jj|j|jj |j |S)z We can safely call L{QueryFactory.clientConnectionLost} as a callback of L{QueryFactory.parseResponse}. )rdeferredrclientConnectionLostr parseResponserrts r- test_parseResponseCallbackSafetyz?QueryFactoryParseResponseTests.test_parseResponseCallbackSafetyhsT    & & d''<QueryFactoryParseResponseTests.test_parseResponseErrbackSafetyusT    & & T&&;;T[[I ''(8(89r/c|jj}|j|jj|j|jj dd|S)z} We can safely call L{QueryFactory.clientConnectionLost} as an errback of L{QueryFactory.badStatus}. statusmessage)rrrrr badStatusrts r-test_badStatusErrbackSafetyz:QueryFactoryParseResponseTests.test_badStatusErrbackSafetysP    & & T&&;;T[[I ##Hi8r/cd}|jj}|jj||j|tS)z Some server can send a response without any data: L{QueryFactory.parseResponse} should catch the error and call the result errback. zM )rrrr( IndexError)r+r8rs r-test_parseResponseWithoutDataz.valids+??7??1#56D   T#8 9r/) rr6rrr7r8 notifyFinishrr: render_POST)r+r5rrs` r-test_withRequestz'XMLRPCWithRequestTests.test_withRequestsf w'"9??8]#KL :  " . .ug > !!'*r/N)r0r1r2r;rr&r/r-rrs r/r)FrMriorrrrtwisted.internetrrtwisted.internet.errorrtwisted.internet.testingr r twisted.loggerr r r rtwisted.pythonrtwisted.python.compatrrtwisted.python.reflectr twisted.trial twisted.webrrrrrtwisted.web.test.test_webrtwisted.web.xmlrpcrrrrrrrf ImportErrorTestCaser!rLrOrrSrUrrrrrrrrrhrlr}rrrrrrrr&r/r-rs   +1H #=."<<2&'G-3x((-3` |  Z \6\~ & *  BTB$8,,8* ={>=BNX%6%6N:O1X%6%6O1dX..sGs6GG"!G"