ϪfdZddlZddlmZmZddlmZddlmZm Z ddl m Z ddl m Z ddlmZdd lmZmZmZmZmZdd lmZdd lmZdd lmZdd lmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'e#jPsdZ)ndZ)GddeZ*GddZ+GddZ,Gdde'jZZ.Gdde'jZeZ/Gdde'jZZ0Gd d!e'jZZ1Gd"d#e'jZZ2Gd$d%Z3Gd&d'e'jZZ4Gd(d)e'jZZ5y)*z) Test cases for L{twisted.names.client}. N) verifyClass verifyObject)defer)CannotListenErrorConnectionRefusedError) IResolver)Clock)AlternateReactor)cacheclientdnserrorhosts) ResolverBase)DNSQueryTimeoutError) test_util)GoodTempPathMixin)failure)FilePath)platform) proto_helpers)unittestz:These tests need more work before they'll work on Windows.ceZdZdZy) FakeResolverc |dk(r>tj|tj|dtjdd}ntj|||d}|g}g}g}t j |||fS)z The getHostByNameTest does a different type of query that requires it return an A record from an ALL_RECORDS lookup, so we accommodate that here. getHostByNameTest< 127.0.0.1)addressttl)nametypeclsr payload)r!r"r#r )r RRHeaderARecord_Arsucceed) selfr!r#qtypetimeoutrrresults authority additionals @/usr/lib/python3/dist-packages/twisted/names/test/test_client.py_lookupzFakeResolver._lookup$sv ' 'UU [bA B4e"EB$  }}gy*=>>N)__name__ __module__ __qualname__r1r2r0rr#s?r2rceZdZdZdZdZy)StubPortz A partial implementation of L{IListeningPort} which only keeps track of whether it has been stopped. @ivar disconnected: A C{bool} which is C{False} until C{stopListening} is called, C{True} afterwards. Fcd|_y)NT) disconnectedr)s r0 stopListeningzStubPort.stopListeningFs  r2N)r3r4r5__doc__r:r<r6r2r0r8r8;sL!r2r8ceZdZdZdZddZy)StubDNSDatagramProtocolz L{dns.DNSDatagramProtocol}-alike. @ivar queries: A C{list} of tuples giving the arguments passed to C{query} along with the L{defer.Deferred} which was returned from the call. c0g|_t|_yNqueriesr8 transportr;s r0__init__z StubDNSDatagramProtocol.__init__S !r2Ncntj}|jj|||||f|S)zv Record the given arguments and return a Deferred which will not be called back by this code. )rDeferredrCappend)r)rrCr+idresults r0queryzStubDNSDatagramProtocol.queryWs2 ! WgwFCD r2 N)r3r4r5r=rErLr6r2r0r?r?Js$r2r?c eZdZdZeZdZdZy)GetResolverTestsz* Tests for L{client.getResolver}. ctt5tj}ddd|j t t y#1swY)xYw)zQ L{client.getResolver} returns an object providing L{IResolver}. N)r r r getResolver assertTruerrr)resolvers r0test_interfacezGetResolverTests.test_interfacehsDeg & ,))+H ,  Y9: , ,s AActt5tj}tj}ddd|j y#1swYxYw)zn Multiple calls to L{client.getResolver} return the same L{IResolver} implementation. N)r r r rRassertIs)r)abs r0test_idempotentz GetResolverTests.test_idempotentpsO eg & %""$A""$A % a % %s )AA!N)r3r4r5r= windowsSkipskiprVr[r6r2r0rPrPas D;r2rPcPeZdZdZeZdZdZdZdZ dZ dZ dZ d Z d Zd Zy ) CreateResolverTestsz- Tests for L{client.createResolver}. c|jDcgc]}t|tjs|!}}|j dt ||j |dj |ycc}w)Nr) resolvers isinstancerResolver assertEquallenfiler)rUfilenamerress r0 _hostsTestzCreateResolverTests._hostsTestsZ",,NQ 1enn0MqNN CH% Qh/O A0A0ctt5tj}ddd|j dy#1swYxYw)z L{client.createResolver} returns a L{resolve.ResolverChain} including a L{hosts.Resolver} using I{/etc/hosts} if no alternate hosts file is specified. Ns /etc/hostsr r r createResolverrlrTs r0test_defaultHostsz%CreateResolverTests.test_defaultHostss? eg & /,,.H / -0 / / AA ctt5tjd}ddd|j dy#1swYxYw)z The I{hosts} parameter to L{client.createResolver} overrides the hosts file used by the L{hosts.Resolver} in the L{resolve.ResolverChain} it returns. /foo/bar)rNrorTs r0test_overrideHostsz&CreateResolverTests.test_overrideHostssE eg & @,,;?H @ +. @ @ AAc|jDcgc]}t|tjs|!}}|j dt ||j |dj |ycc}w)z| Verify that C{resolver} has a L{client.Resolver} with a configuration filename set to C{filename}. rarN)rbrcr rdrerfresolvrhs r0_resolvConfTestz#CreateResolverTests._resolvConfTests\ #,,OQ 1foo0NqOO CH% Q1Prmcft}t|5tj}dddjDcgc]}t |tj s|!}}|jdt||j||djy#1swYxxYwcc}w)z The L{client.Resolver} included in the L{resolve.ResolverChain} returned by L{client.createResolver} uses the global reactor. Nrar) r r r rprbrcrdrerfrX_reactor)r)reactorrUrjrks r0 test_reactorz CreateResolverTests.test_reactors ' g & /,,.H /",,OQ 1foo0NqOO CH% gs1v/  / /OsB"B.!B."B+ctt5tj}ddd|j dy#1swYxYw)z L{client.createResolver} returns a L{resolve.ResolverChain} including a L{client.Resolver} using I{/etc/resolv.conf} if no alternate resolver configuration file is specified. Ns/etc/resolv.confr r r rpryrTs r0test_defaultResolvConfz*CreateResolverTests.test_defaultResolvConfsB eg & /,,.H / X':; / /rrctt5tjd}ddd|j dy#1swYxYw)z The I{resolvconf} parameter to L{client.createResolver} overrides the resolver configuration file used by the L{client.Resolver} in the L{resolve.ResolverChain} it returns. rt resolvconfNrrTs r0test_overrideResolvConfz+CreateResolverTests.test_overrideResolvConfsG eg & E,, DH E X{3 E Ervc|j}|jdtt5t j |j}dddj Dcgc]}t|tjs|!}}|jdt||jg|dj|jdg|djy#1swYxYwcc}w)z If no servers are given, addresses are taken from the file given by the I{resolvconf} parameter to L{client.createResolver}. nameserver 127.1.2.3 rNrarz 127.1.2.35 path setContentr r r rprbrcrdrerfservers dynServersr)rrUrjrks r0test_defaultServersz'CreateResolverTests.test_defaultServerss YY[ 78 eg & I,, HH I",,OQ 1foo0NqOO CH% SV^^, +,c!f.?.?@  I IOs!C-,C9 C9-C6c|j}|jdtt5t j dg|j}dddj Dcgc]}t|tjs|!}}|jdt||jdg|dj|jdg|djy#1swYxYwcc}w)z Servers passed to L{client.createResolver} are used in addition to any found in the file given by the I{resolvconf} parameter. r)z 127.3.2.1r)rrNrarrrrs r0test_overrideServersz(CreateResolverTests.test_overrideServerss YY[ 78 eg & ,,*+ H #,,OQ 1foo0NqOO CH% +,c!fnn= +,c!f.?.?@  Ps#C0.C<C<0C9c$tt5tj}dddjDcgc]}t |t js|!}}|jdt|y#1swYYxYwcc}w)zy L{client.createResolver} returns a L{resolve.ResolverChain} including a L{cache.CacheResolver}. Nra) r r r rprbrcr CacheResolverrerf)r)rUrjrks r0 test_cachezCreateResolverTests.test_cacheso eg & /,,.H /",,SQ 1e>Q>Q0RqSS CH% / /SsBB B B N)r3r4r5r=r\r]rlrqruryr}rrrrrr6r2r0r_r_{sB D0 1/2 0<4 AA &r2r_ceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZy) ResolverTestsz' Tests for L{client.Resolver}. c,ttty)z] L{client} provides L{IResolver} through a series of free functions. N)rrr r;s r0test_clientProvidesIResolverz*ResolverTests.test_clientProvidesIResolvers Y'r2c@tttjy)z; L{client.Resolver} provides L{IResolver}. N)rrr rdr;s r0$test_clientResolverProvidesIResolverz2ResolverTests.test_clientResolverProvidesIResolvers Iv/r2cL|jttjy)z L{client.Resolver} raises L{ValueError} if constructed with neither servers nor a nameserver configuration file. N) assertRaises ValueErrorr rdr;s r0test_noServerszResolverTests.test_noServerss *foo6r2ctj|jt}|j dg|j y)z A missing nameserver configuration file results in no server information being loaded from it (ie, not an exception) and a default server being provided. rxr|rrN)r rdmktempr rerrTs r0test_missingConfigurationz'ResolverTests.test_missingConfigurations6 ??$++-I +,h.A.ABr2ct|j}|jdGfddtj}|ddgdt |j jy ) z As part of its constructor, C{StubResolver} opens C{/etc/resolv.conf}; then, explicitly closes it and does not count on the GC to do so for it. zw+)modeceZdZfdZy)9ResolverTests.test_closesResolvConf..StubResolvercSrAr6)r)r! resolvConfs r0 _openFilezCResolverTests.test_closesResolvConf..StubResolver._openFiles !!r2N)r3r4r5r)rsr0 StubResolverrs "r2r example.comrz/etc/resolv.conf)rrxr|N)rropenr rdr rSclosed)r)handlerrs @r0test_closesResolvConfz#ResolverTests.test_closesResolvConfsb $++-([[d[+  "6?? " "B'0BEG   ))*r2ctjdg}|jdg|jd|jy)z L{client.Resolver.parseConfig} treats a I{domain} line without an argument as indicating a domain of C{b""}. rrsdomain r2N)r rd parseConfigredomainrTs r0test_domainEmptyArgumentz&ResolverTests.test_domainEmptyArgument!s: ??,=+>?k]+ hoo.r2ctjdg}|jdg|jg|jy)z L{client.Resolver.parseConfig} treats a I{search} line without an argument as indicating an empty search suffix. rrssearch N)r rdrresearchrTs r0test_searchEmptyArgumentz&ResolverTests.test_searchEmptyArgument*s: ??,=+>?k]+ X__-r2cvtddg}ddg}tj|}||_fd|_t }|j d}|j|j||jtjd|jjd d |d jd d jtd |jtjd |jjdd |djdd jtd|jtjd |jjd d |d jd d jtd |jtjd |jjd d |djd d j||S)a  L{client.Resolver.queryUDP} should issue queries to its L{dns.DNSDatagramProtocol} with server addresses taken from its own C{servers} and C{dynServers} lists, proceeding through them in order as L{DNSQueryTimeoutError}s occur. z::1r)z::2r)z::3r)z::4rrcSrAr6) interfaceprotocols r0z=ResolverTests.test_datagramQueryServerOrder..@sr2Nrar)r?r rdr_connectedProtocolobjectqueryUDP addCallbackrerfrCrXerrbackrcallback)r)rrrUexpectedResult queryResultrs @r0test_datagramQueryServerOrderz+ResolverTests.test_datagramQueryServerOrder3s+, ,!;/ ??73(&@#''-  0 0.A X--.2 h&&q)!,gaj9B''(.]hr2foo.example.comrarch|\}}j|gggfj|gggfyrAre) responses firstResponsesecondResponseanswerr)s r0 cbFinishedz>ResolverTests.test_singleConcurrentRequest..cbFinishedrs?,5 )M>   ]fXr2,> ?   ^vhB-? @r2)r?r rdrrCr Queryr&INrLrerfrMessageanswersrIpoprr gatherResultsr) r)rUrCrL firstResult secondResultresponsedrrrs ` @@r0test_singleConcurrentRequestz*ResolverTests.test_singleConcurrentRequestUs +,??,?+@A&6#"" ,ceeSVV<nnU+  Wq) ~~e,  Wq);;=' b""8,   l ; < A j!r2cTttjdg}fd|_j}t j dt j}|j||jt|dt j dt j}|j||jt|dt j dt j}|j||jt|dy ) zh L{client.Resolver.query} issues a request for each different concurrent query. rrcSrAr6rsr0rz?ResolverTests.test_multipleConcurrentRequests..rr2rrabar.example.comrrN) r?r rdrrCr rr&rLrerfA6)r)rUrC firstQuery secondQuery thirdQueryrs @r0test_multipleConcurrentRequestsz-ResolverTests.test_multipleConcurrentRequestszs +,??,?+@A&6#""YY13559 z" Wq)ii 2CEE: {# Wq)YY1366: z" Wq)r2cttjdg}fd|_j}t j dt j}|j||jt|d|jdjt j|j||jt|dy)z After a response is received to a query issued with L{client.Resolver.query}, another query with the same parameters results in a new network request. rrcSrAr6rsr0rz?ResolverTests.test_multipleSequentialRequests..rr2rrarN)r?r rdrrCr rr&rLrerfrrr)r)rUrCrLrs @r0test_multipleSequentialRequestsz-ResolverTests.test_multipleSequentialRequestss +,??,?+@A&6#"" ,cee4 u Wq)  b""3;;=1 u Wq)r2cttjdg}fd|_j}t j dt j}|j|}|j|}Gddt}|jdjtj|tj|j!|||j!||gS)z If the result of a request is an error response, the Deferreds for all concurrently issued requests associated with that result fire with the L{Failure}. rrcSrAr6rsr0rz>ResolverTests.test_multipleConcurrentFailure..rr2rc eZdZy)GResolverTests.test_multipleConcurrentFailure..ExpectedExceptionNr3r4r5r6r2r0ExpectedExceptionr r2rr)r?r rdrrCr rr&rL ExceptionrrrFailurerr assertFailure)r)rUrCrLrrrrs @r0test_multipleConcurrentFailurez,ResolverTests.test_multipleConcurrentFailures +,??,?+@A&6#"" ,cee4nnU+ ~~e,      b!!'//2C2E"FG"""";0AB""<1BC   r2cRtjdg}|j}|j}|j|j|j|j|j |jj j|jj jtjtj|jjtj|jjgS)z L{client.Resolver._connectedProtocol} returns a new L{DNSDatagramProtocol} connected to a new address with a cryptographically secure random port number. rr) r rdrassertIsNotNonerDassertNotEqualgetHostportrr maybeDeferredr<)r)rU firstProto secondProtos r0test_connectedProtocolz$ResolverTests.test_connectedProtocols ??,?+@A002 113  Z112 [223   ( ( * / /1F1F1N1N1P1U1U ""##J$8$8$F$FG##K$9$9$G$GH   r2ctj}tj|j |}|j }|j |j|y)z If a reactor instance is supplied to L{client.Resolver} L{client.Resolver._connectedProtocol} should pass that reactor to L{twisted.names.dns.DNSDatagramProtocol}. rN)r MemoryReactorr rdrrrXr{)r)r|rUprotos r0)test_resolverUsesOnlyParameterizedReactorz7ResolverTests.test_resolverUsesOnlyParameterizedReactorsH ))+??$++-I++- enng.r2c6tjdg}gGfdd}||_|jt j d|jt j d|j ttdy) z L{client.Resolver._connectedProtocol} is called once each time a UDP request needs to be issued and the resulting protocol instance is used for that request. rrc eZdZdZdfd Zy):ResolverTests.test_differentProtocol..FakeProtocolc"t|_yrAr8rDr;s r0rEzCResolverTests.test_differentProtocol..FakeProtocol.__init__ !)r2Nctj|tjtjSrA)rIrr(r r)r)rrLr+rJ protocolss r0rLz@ResolverTests.test_differentProtocol..FakeProtocol.querys&  &}}S[[]33r2rMr3r4r5rErL)rsr0 FakeProtocolr s  , 4r2rrrrN) r rdrrLr rrerfset)r)rUrrs @r0test_differentProtocolz$ResolverTests.test_differentProtocolsu ??,?+@A  4 4'3#syy!345syy!345 S^,a0r2c:tj}tjdg|}|j t j d|jj\\}}|jj}|jd|y)z< If the resolver is ipv6, open a ipv6 port. rrr|rz::N) rrr rdrLr rudpPortsitemsrhostre)r)fakerUrrDrs r0test_ipv6ResolverzResolverTests.test_ipv6Resolversx &&(??K=$Gsyy!345#}}224 %%%',,  y)r2cgGfdd}tjdg}||_|j|j t t dy)z If a port number is initially selected which cannot be bound, the L{CannotListenError} is handled and another port number is attempted. ceZdZfdZy)6ResolverTests.test_disallowedPort..FakeReactorc^j|tdk(r td|dy)Nra)rIrfrr)rargskwargsportss r0 listenUDPz@ResolverTests.test_disallowedPort..FakeReactor.listenUDPs. T"u:?+D$==#r2Nr3r4r5r"r!sr0 FakeReactorrs >r2r%rrrN)r rdr{rrerfrr)r%rUr!s @r0test_disallowedPortz!ResolverTests.test_disallowedPort sV  > > ??,?+@A'M##% SZ!,r2cgGfdd}tjdg}||_|jt|j |j tdy)z If port numbers that cannot be bound are repeatedly selected, L{resolver._connectedProtocol} will give up eventually. ceZdZfdZy)@ResolverTests.test_disallowedPortRepeatedly..FakeReactorc@j|td|drA)rIrrs r0r"zJResolverTests.test_disallowedPortRepeatedly..FakeReactor.listenUDP's T"'dD99r2Nr#r$sr0r%r*&s :r2r%rriN)r rdr{rrrrerfr&s @r0test_disallowedPortRepeatedlyz+ResolverTests.test_disallowedPortRepeatedlys]  : : ??,?+@A'M +X-H-HI UT*r2cFgGfdd}tjdg}||_|jt|j }|j |jjtj|j tdy)zf If the process is out of files, L{Resolver._connectedProtocol} will give up. ceZdZfdZy)5ResolverTests.test_runOutOfFiles..FakeReactorctj|ttjd}t d||)NzOut of files :()rIOSErrorerrnoEMFILEr)r)rrr errr!s r0r"z?ResolverTests.test_runOutOfFiles..FakeReactor.listenUDP:s/ T"ell,=>'dC88r2Nr#r$sr0r%r/9s 9r2r%rrraN) r rdr{rrrre socketErrorr2r3rf)r)r%rUexcr!s @r0test_runOutOfFilesz ResolverTests.test_runOutOfFiles2s  9 9 ??,?+@A'M 183N3NO .. = UQ'r2ctjdg}gtjt j t dtjtjgGfdd}||_ |jtjd|jttdy)z| When a query issued by L{client.Resolver.query} times out, the retry uses a new protocol instance. rrNc"eZdZdZdfd Zy)FResolverTests.test_differentProtocolAfterTimeout..FakeProtocolc"t|_yrAr r;s r0rEzOResolverTests.test_differentProtocolAfterTimeout..FakeProtocol.__init__Ur r2NcHj|jdSNrrIrr)rrLr+rJrr-s r0rLzLResolverTests.test_differentProtocolAfterTimeout..FakeProtocol.queryX  &{{1~%r2rMrrr-sr0rr:T  , &r2rrr)r rdrfailrrrr(r rrrLrrerfr)r)rUrrr-s @@r0"test_differentProtocolAfterTimeoutz0ResolverTests.test_differentProtocolAfterTimeoutHs ??,?+@A JJw';D'AB C MM#++- (   & &'3#syy!345 S^,a0r2ctjdg}gtjGfdd}||_|j t jd|jdjjjt j|jdjjy)z After the L{Deferred} returned by L{DNSDatagramProtocol.query} is called back, the L{DNSDatagramProtocol} is disconnected from its transport. rrc"eZdZdZdfd Zy)9ResolverTests.test_protocolShutDown..FakeProtocolc"t|_yrAr r;s r0rEzBResolverTests.test_protocolShutDown..FakeProtocol.__init__kr r2Nc*j|SrArIr)rrLr+rJrrKs r0rLz?ResolverTests.test_protocolShutDown..FakeProtocol.queryn  & r2rMrrrKsr0rrGj  , r2rrrN)r rdrrHrrLr r assertFalserDr:rrrS)r)rUrrrKs @@r0test_protocolShutDownz#ResolverTests.test_protocolShutDown`s ??,?+@A !  '3#syy!345 1//<<= &  ! ..;;.FakeProtocolc"t|_yrAr r;s r0rEzNResolverTests.test_protocolShutDownAfterTimeout..FakeProtocol.__init__r r2NcHj|jdSr=r>r?s r0rLzKResolverTests.test_protocolShutDownAfterTimeout..FakeProtocol.queryr@r2rMrrAsr0rrSrBr2rrra)r rdrrHrCrrrrrLr rrOrDr:rrrS)r)rUrKrrr-s @@r0!test_protocolShutDownAfterTimeoutz/ResolverTests.test_protocolShutDownAfterTimeoutys ??,?+@A !::goo.B4.HIJFS & &'3#syy!345 1//<<= &  ! ..;;.ExpectedExceptionNrr6r2r0rrYrr2rrrc"eZdZdZdfd Zy)EResolverTests.test_protocolShutDownAfterFailure..FakeProtocolc"t|_yrAr r;s r0rEzNResolverTests.test_protocolShutDownAfterFailure..FakeProtocol.__init__r r2Nc*j|SrArJrKs r0rLzKResolverTests.test_protocolShutDownAfterFailure..FakeProtocol.queryrLr2rMrrMsr0rr[rNr2rrr)rr rdrrHrrLr rrOrDr:rrrrSr)r)rrUrrrrKs @@r0!test_protocolShutDownAfterFailurez/ResolverTests.test_protocolShutDownAfterFailures   ??,?+@A !  '3#nnSYY/A%BC  1//<<=w'8':;<  ! ..;;<!!+/@AAr2ctjdg}|jjd}|j d|j ||j |jd|j||j y)z When a TCP DNS protocol associated with a Resolver disconnects, it is removed from the Resolver's connection list. rrN) r rdfactory buildProtocolmakeConnectionassertIn connectionsconnectionLost assertNotIn)r)rUrs r0(test_tcpDisconnectRemovesFromConnectionsz6ResolverTests.test_tcpDisconnectRemovesFromConnectionsst ??,?+@A##11$7% h 4 45 % 8#7#78r2c~tj}tjdg|}|j t j d}|jd\}}}}}Gddt} |j|jdtj| |j|| y)z The deferred returned by L{client.Resolver.queryTCP} will errback when the TCP connection attempt fails. The reason for the connection failure is passed as the argument to errback. z 192.0.2.100rrrrc eZdZy)VResolverTests.test_singleTCPQueryErrbackOnConnectionFailure..SentinelExceptionNrr6r2r0SentinelExceptionrkrr2rlN)rrr rdqueryTCPr r tcpClientsrclientConnectionFailed connectorsrrfailureResultOf) r)r|rUrrrr`r+ bindAddressrls r0-test_singleTCPQueryErrbackOnConnectionFailurez;ResolverTests.test_singleTCPQueryErrbackOnConnectionFailures  --/??,?+@'R   cii 6 74;4F4Fq4I1dGWk    &&   q !7??3D3F#G  Q 12r2ctj}tjdg|}|j t j d}|j t j d}|jd\}}}}} Gddt} |j|jdtj| |j|| } |j|| } |j| | y) z All pending L{resolver.queryTCP} C{deferred}s will C{errback} with the same C{Failure} if the connection attempt fails. rirrz example.netrc eZdZy)XResolverTests.test_multipleTCPQueryErrbackOnConnectionFailure..SentinelExceptionNrr6r2r0rlrvrr2rlN)rrr rdrmr rrnrrorprrrqrX) r)r|rUd1d2rrr`r+rrrlf1f2s r0/test_multipleTCPQueryErrbackOnConnectionFailurez=ResolverTests.test_multipleTCPQueryErrbackOnConnectionFailures  --/??,?+@'R   syy7 8   syy7 84;4F4Fq4I1dGWk    &&   q !7??3D3F#G  ! !"&7 8  ! !"&7 8 b"r2c tj}tjdg| t j d j } fd}|j||jt|jd|jt|jd|jd\}}}}}tjt} |j|jd| |jt|jd|jt|jd|j!|tjt} |j|jd| |j#|t} |j%| | y) z{ An errback on the deferred returned by L{client.Resolver.queryTCP} may trigger another TCP query. )riE'rrcP|jtjSrA)traprrm)eqrUs r0reissuezOResolverTests.test_reentrantTCPQueryErrbackOnConnectionFailure..reissues! FF) *$$Q' 'r2rarrN)rrr rdr rrm addErrbackrerfrnrprrrroassertNoResultrqrX)r)r|rrrrr`r+rrryrzfrrUs @@r00test_reentrantTCPQueryErrbackOnConnectionFailurez>ResolverTests.test_reentrantTCPQueryErrbackOnConnectionFailuresr  --/??,@+A7S IIm $   a  ( W W//0!4 W//0!44;4F4Fq4I1dGWk__35 6&&w'9'9!'.SentinelExceptionNrr6r2r0rlr'rr2rlN)rrr rdrmr rrnpendingrerfrrorprrrqrX) r)r|rUrrrr`r+rr prePendingrls r0!test_pendingEmptiedInPlaceOnErrorz/ResolverTests.test_pendingEmptiedInPlaceOnErrors  --/??,?+@'R   cii 6 74;4F4Fq4I1dGWk%%  Z!,    &&   q !7??3D3F#G  Q 12 h&& 3 Z!,r2N) r3r4r5r=rrrrrrrrrrrrrrrrr'r,r7rDrPrVr^rgrsr{rrr6r2r0rrs(0 7C+$/. D#J*6*0 6 . /1, *-&+&(,10=2=4B> 93*.)V-r2rceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZy) ClientTestscFtt_d|_d|_y)z: Replace the resolver with a FakeResolver example.comrN)rr theResolverhostnamehostnameForGetHostByNamer;s r0setUpzClientTests.setUp4s*^& (<%r2cdt_y)zp By setting the resolver to None, it will be recreated next time a name lookup is done. N)r rr;s r0tearDownzClientTests.tearDown<s "r2c|\}}}|d}|j|jj|j|j|j|y)zT Verify that the result is the same query type as what is expected. rN)rer!rr")r)r-r*rr.r/rKs r0 checkResultzClientTests.checkResultCsK*1&J ))4==9 e,r2c(|j|dy)zR Test that the getHostByName query returns the 127.0.0.1 address. rNrr)rKs r0checkGetHostByNamezClientTests.checkGetHostByNameLs -r2cztj|j}|j|j|S)zM do a getHostByName of a value that should return 127.0.0.1. )r getHostByNamerrrr)rs r0test_getHostByNamezClientTests.test_getHostByNameRs1  !>!> ? d--.r2ctj|j}|j|jt j |S)z Do a lookup and test that the resolver will issue the correct type of query type. We do this by checking that FakeResolver returns a result record with the same query type as what we issued. )r lookupAddressrrrr r&rs r0test_lookupAddresszClientTests.test_lookupAddressZs5   / d&&.r2ctj|j}|j|jt j |Sz+ See L{test_lookupAddress} )r lookupIPV6Addressrrrr AAAArs r0test_lookupIPV6Addressz"ClientTests.test_lookupIPV6Addressds5  $ $T]] 3 d&&1r2ctj|j}|j|jt j |Sr)r lookupAddress6rrrr rrs r0test_lookupAddress6zClientTests.test_lookupAddress6ls5  ! !$-- 0 d&&/r2ctj|j}|j|jt j |Sr)r lookupNameserversrrrr NSrs r0test_lookupNameserversz"ClientTests.test_lookupNameserversts5  $ $T]] 3 d&&/r2ctj|j}|j|jt j |Sr)r lookupCanonicalNamerrrr CNAMErs r0test_lookupCanonicalNamez$ClientTests.test_lookupCanonicalName|s5  & &t}} 5 d&& 2r2ctj|j}|j|jt j |Sr)r lookupAuthorityrrrr SOArs r0test_lookupAuthorityz ClientTests.test_lookupAuthoritys5  " "4== 1 d&&0r2ctj|j}|j|jt j |Sr)r lookupMailBoxrrrr MBrs r0test_lookupMailBoxzClientTests.test_lookupMailBoxs5   / d&&/r2ctj|j}|j|jt j |Sr)r lookupMailGrouprrrr MGrs r0test_lookupMailGroupz ClientTests.test_lookupMailGroups5  " "4== 1 d&&/r2ctj|j}|j|jt j |Sr)r lookupMailRenamerrrr MRrs r0test_lookupMailRenamez!ClientTests.test_lookupMailRenames5  # #DMM 2 d&&/r2ctj|j}|j|jt j |Sr)r lookupNullrrrr NULLrs r0test_lookupNullzClientTests.test_lookupNull5   dmm , d&&1r2ctj|j}|j|jt j |Sr)r lookupWellKnownServicesrrrr WKSrs r0test_lookupWellKnownServicesz(ClientTests.test_lookupWellKnownServicess5  * *4== 9 d&&0r2ctj|j}|j|jt j |Sr)r lookupPointerrrrr PTRrs r0test_lookupPointerzClientTests.test_lookupPointer5   / d&&0r2ctj|j}|j|jt j |Sr)r lookupHostInforrrr HINFOrs r0test_lookupHostInfozClientTests.test_lookupHostInfos5  ! !$-- 0 d&& 2r2ctj|j}|j|jt j |Sr)r lookupMailboxInforrrr MINFOrs r0test_lookupMailboxInfoz"ClientTests.test_lookupMailboxInfo5  $ $T]] 3 d&& 2r2ctj|j}|j|jt j |Sr)r lookupMailExchangerrrr MXrs r0test_lookupMailExchangez#ClientTests.test_lookupMailExchanges5  % %dmm 4 d&&/r2ctj|j}|j|jt j |Sr)r lookupTextrrrr TXTrs r0test_lookupTextzClientTests.test_lookupTexts5   dmm , d&&0r2ctj|j}|j|jt j |Sr)r lookupSenderPolicyrrrr SPFrs r0test_lookupSenderPolicyz#ClientTests.test_lookupSenderPolicys5  % %dmm 4 d&&0r2ctj|j}|j|jt j |Sr)r lookupResponsibilityrrrr RPrs r0test_lookupResponsibilityz%ClientTests.test_lookupResponsibilitys5  ' ' 6 d&&/r2ctj|j}|j|jt j |Sr)r lookupAFSDatabaserrrr AFSDBrs r0test_lookupAFSDatabasez"ClientTests.test_lookupAFSDatabaserr2ctj|j}|j|jt j |Sr)r lookupServicerrrr SRVrs r0test_lookupServicezClientTests.test_lookupServicerr2ctj|j}|j|jt j |Sr)r lookupZonerrrr AXFRrs r0test_lookupZonezClientTests.test_lookupZonerr2ctj|j}|j|jt j |Sr)r lookupAllRecordsrrrr ALL_RECORDSrs r0test_lookupAllRecordsz!ClientTests.test_lookupAllRecordss5  # #DMM 2 d&&8r2ctj|j}|j|jt j |Sr)r lookupNamingAuthorityPointerrrrr NAPTRrs r0!test_lookupNamingAuthorityPointerz-ClientTests.test_lookupNamingAuthorityPointer s5  / / > d&& 2r2ctj|jtj}t j |}|j |jtj|S)a L{client.query} accepts a L{dns.Query} instance and dispatches it to L{client.theResolver}.C{query}, which in turn dispatches to an appropriate C{lookup*} method of L{client.theResolver}, based on the L{dns.Query} type. )r rrr&r rLrr)r)rrs r0 test_queryzClientTests.test_querysF IIdmmSUU + LLO d&&.r2N) r3r4r5rrrrrrrrrrrrrrrrrrrrrrrrrrrrrr6r2r0rr3s="-.  r2rcFeZdZdZdZdZdZdZdZdZ dZ d Z d Z y ) FilterAnswersTestsz| Test L{twisted.names.client.Resolver.filterAnswers}'s handling of various error conditions it might encounter. c<tjdg|_y)N)z0.0.0.0rr)r rdrUr;s r0rzFilterAnswersTests.setUp's0@A r2ctjdjdfd}|j_jj }|j jdgdgdgf|S)zf Test that a truncated message results in an equivalent request made via TCP. T)truncrcj|jtj}dg|_dg|_dg|_tj|S)Nrr.r/) rerCr rrr.r/rr()rCrmr)s r0rmz:FilterAnswersTests.test_truncatedMessage..queryTCP4sO   Waii 0{{}H (zH "-H #/.H ==* *r2rr.r/)r raddQueryrUrm filterAnswersrre)r)rmrrs` @r0test_truncatedMessagez(FilterAnswersTests.test_truncatedMessage,sl KKd # >" +"*  MM ' ' * d&&(k]\N(STr2ctj|}|jj|}|j |y)N)rCode)r rrUrr~)r)rcoder6rr4s r0 _rcodeTestzFilterAnswersTests._rcodeTestAs/ KKe $mm))!,  r2c^|jtjtjS)z Test that a message with a result code of C{EFORMAT} results in a failure wrapped around L{DNSFormatError}. )r r EFORMATrDNSFormatErrorr;s r0test_formatErrorz#FilterAnswersTests.test_formatErrorFs s{{E,@,@AAr2c^|jtjtjS)zP Like L{test_formatError} but for C{ESERVER}/L{DNSServerError}. )r r ESERVERrDNSServerErrorr;s r0test_serverErrorz#FilterAnswersTests.test_serverErrorMss{{E,@,@AAr2c^|jtjtjS)zL Like L{test_formatError} but for C{ENAME}/L{DNSNameError}. )r r ENAMEr DNSNameErrorr;s r0test_nameErrorz!FilterAnswersTests.test_nameErrorSssyy%*<*<==r2c^|jtjtjS)zX Like L{test_formatError} but for C{ENOTIMP}/L{DNSNotImplementedError}. )r r ENOTIMPrDNSNotImplementedErrorr;s r0test_notImplementedErrorz+FilterAnswersTests.test_notImplementedErrorYss{{E,H,HIIr2c^|jtjtjS)zW Like L{test_formatError} but for C{EREFUSED}/L{DNSQueryRefusedError}. )r r EREFUSEDrDNSQueryRefusedErrorr;s r0test_refusedErrorz$FilterAnswersTests.test_refusedError_ss||U-G-GHHr2cd|jtjdztjS)zm Like L{test_formatError} but for an unrecognized error code and L{DNSUnknownError}. ra)r r rrDNSUnknownErrorr;s r0test_refusedErrorUnknownz+FilterAnswersTests.test_refusedErrorUnknownes$ s||a/1F1FGGr2N) r3r4r5r=rrr rrrrr r#r6r2r0rr!s: B * BB > J I Hr2rc eZdZdZddZdZy)FakeDNSDatagramProtocolc0g|_t|_yrArBr;s r0rEz FakeDNSDatagramProtocol.__init__nrFr2Nc|jj||||ftjt j |SrA)rCrIrrCrr)r)rrCr+rJs r0rLzFakeDNSDatagramProtocol.queryrs7 Wgw;<zz%44W=>>r2cyrAr6)r)rJs r0 removeResendz$FakeDNSDatagramProtocol.removeResendvs r2rM)r3r4r5rErLr)r6r2r0r%r%ms$? r2r%c*eZdZdZgdZdZdZdZy)RetryLogicTestszE Tests for query retrying implemented by L{client.Resolver}. )z1.2.3.4z4.3.2.1za.b.c.dzz.y.x.wc"|jDcgc]}|df}}tjd|}tfd|_|j dj |jj|jScc}w)a When timeouts occur waiting for responses to queries, the next configured server is issued the query. When the query has been issued to all configured servers, the timeout is increased and the process begins again at the beginning. rN)rxrcSrAr6)rsr0rz8RetryLogicTests.test_roundRobinBackoff..sur2r) testServersr rdr%rrr_cbRoundRobinBackoffr_ebRoundRobinBackoff)r)xaddrsrjrs @r0test_roundRobinBackoffz&RetryLogicTests.test_roundRobinBackoffs{#'"2"23Q!R33 OO4 7'), OO. / [22 3 Z115 9 4s B c&|jdy)Nz/Lookup address succeeded, should have timed out)rCrs r0r/z$RetryLogicTests._cbRoundRobinBackoffs CDr2c|jtjdD]}|jdt |j }|jdt |j =|j t|j }|j t||D]0\\}}}} } |j|| df|j||2|j|jy)N)rar -r) r~r TimeoutErrorrCrfr.sortlistziprerO) r)r fakeProtottriesexpectedaddrrLr+rJ expectedAddrs r0r0z$RetryLogicTests._ebRoundRobinBackoffs U''(  -A%%&=D,<,<(=>E!!"9C(8(8$9"9: JJLD,,-H MMOr_s  ;"L1'@::-4(;",+&"xKNK?<?0 ! !.x((4o&(++->o&dC -H%%C -Lk(##k\IH**IHX   -,h''-,`+H--+r2