+
    DfjȢ                     R   R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
Ht ^ RIHtHt ^ RIHt  ! R R]4      tR	 t ! R
 R]P(                  4      t ! R R]P(                  4      t ! R R4      t ! R R4      t ! R R4      t ! R R4      tR t ! R R]P8                  4      tR# )z)
Test cases for L{twisted.names.server}.
)verifyClass)defer)IProtocolFactory)dnserrorresolveserver)failurelog)unittestc                   *   a  ] tR t^t o RtR tRtV tR# )RaisedArgumentsz<
An exception containing the arguments raised by L{raiser}.
c                    Wn         W n        R # Nargskwargsselfr   r   s   &&&@/usr/lib/python3/dist-packages/twisted/names/test/test_server.py__init__RaisedArguments.__init__   s    	    r   N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classdictcell____classdict__s   @r   r   r      s      r   r   c                     \        W4      h)z
Raise a L{RaisedArguments} exception containing the supplied arguments.

Used as a fake when testing the call signatures of  methods and functions.
)r   r   s   *,r   raiserr#      s     $
''r   c                   0   a  ] tR t^$t o RtR tR tRtV tR# )NoResponseDNSServerFactoryz
A L{server.DNSServerFactory} subclass which does not attempt to reply to any
received messages.

Used for testing logged messages in C{messageReceived} without having to
fake or patch the preceding code which attempts to deliver a response
message.
c                    R# )z
Deny all queries.

@param message: See L{server.DNSServerFactory.allowQuery}
@param protocol: See L{server.DNSServerFactory.allowQuery}
@param address: See L{server.DNSServerFactory.allowQuery}

@return: L{False}
@rtype: L{bool}
F )r   messageprotocoladdresss   &&&&r   
allowQuery%NoResponseDNSServerFactory.allowQuery.   s     r   c                    R# )z
A noop send reply.

@param protocol: See L{server.DNSServerFactory.sendReply}
@param message: See L{server.DNSServerFactory.sendReply}
@param address: See L{server.DNSServerFactory.sendReply}
Nr'   )r   r)   r(   r*   s   &&&&r   	sendReply$NoResponseDNSServerFactory.sendReply;       r   r'   N)	r   r   r   r   r   r+   r.   r   r   r    s   @r   r%   r%   $   s      r   r%   c                   @   a  ] tR t^Et o Rt ! R R]4      tR tRtV t	R# )RaisingDNSServerFactoryz
A L{server.DNSServerFactory} subclass whose methods raise an exception
containing the supplied arguments.

Used for stopping L{messageReceived} and testing the arguments supplied to
L{allowQuery}.
c                       ] tR t^NtRtRtR# )+RaisingDNSServerFactory.AllowQueryArguments7
Contains positional and keyword arguments in C{args}.
r'   Nr   r   r   r   r   r   r'   r   r   AllowQueryArgumentsr4   N       	r   r7   c                $    V P                  W4      h)a  
Raise the arguments supplied to L{allowQuery}.

@param args: Positional arguments which will be recorded in the raised
    exception.
@type args: L{tuple}

@param kwargs: Keyword args which will be recorded in the raised
    exception.
@type kwargs: L{dict}
)r7   r   s   &*,r   r+   "RaisingDNSServerFactory.allowQueryS   s     &&t44r   r'   N)
r   r   r   r   r   	Exceptionr7   r+   r   r   r    s   @r   r2   r2   E   s      i 
5 5r   r2   c                   @   a  ] tR t^bt o Rt ! R R]4      tR tRtV t	R# )RaisingProtocolza
A partial fake L{IProtocol} whose methods raise an exception containing the
supplied arguments.
c                       ] tR t^htRtRtR# )%RaisingProtocol.WriteMessageArgumentsr5   r'   Nr6   r'   r   r   WriteMessageArgumentsr?   h   r8   r   r@   c                $    V P                  W4      hz
Raises the supplied arguments.

@param args: Positional arguments
@type args: L{tuple}

@param kwargs: Keyword args
@type kwargs: L{dict}
)r@   r   s   &*,r   writeMessageRaisingProtocol.writeMessagem   s     ((66r   r'   N)
r   r   r   r   r   r;   r@   rC   r   r   r    s   @r   r=   r=   b   s      
	 

7 
7r   r=   c                   *   a  ] tR t^zt o RtR tRtV tR# )NoopProtocolzL
A partial fake L{dns.DNSProtocolMixin} with a noop L{writeMessage} method.
c                    R# )z
A noop version of L{dns.DNSProtocolMixin.writeMessage}.

@param args: Positional arguments
@type args: L{tuple}

@param kwargs: Keyword args
@type kwargs: L{dict}
Nr'   r   s   &*,r   rC   NoopProtocol.writeMessage   r0   r   r'   N)r   r   r   r   r   rC   r   r   r    s   @r   rF   rF   z   s     	 	r   rF   c                   @   a  ] tR t^t o Rt ! R R]4      tR tRtV t	R# )RaisingResolverza
A partial fake L{IResolver} whose methods raise an exception containing the
supplied arguments.
c                       ] tR t^tRtRtR# )RaisingResolver.QueryArgumentsr5   r'   Nr6   r'   r   r   QueryArgumentsrL      r8   r   rM   c                $    V P                  W4      hrB   )rM   r   s   &*,r   queryRaisingResolver.query   s     !!$//r   r'   N)
r   r   r   r   r   r;   rM   rO   r   r   r    s   @r   rJ   rJ      s      
 

0 
0r   rJ   c                   @   a  ] tR t^t o Rt ! R R]4      tR tRtV t	R# )RaisingCachezq
A partial fake L{twisted.names.cache.Cache} whose methods raise an exception
containing the supplied arguments.
c                       ] tR t^tRtRtR# )!RaisingCache.CacheResultArgumentsr5   r'   Nr6   r'   r   r   CacheResultArgumentsrT      r8   r   rU   c                $    V P                  W4      hrB   )rU   r   s   &*,r   cacheResultRaisingCache.cacheResult   s     ''55r   r'   N)
r   r   r   r   r   r;   rU   rW   r   r   r    s   @r   rR   rR      s      
y 

6 
6r   rR   c                   . p\         P                  ! VP                  4       V P                  \         P                  VP                  4       V! V/ VB  T P                  V Uu. uF  qfR,          ^ ,          NK  	  upV4       R# u upi )a  
Assert that the callable logs the expected messages when called.

XXX: Put this somewhere where it can be re-used elsewhere. See #6677.

@param testCase: The test case controlling the test which triggers the
    logged messages and on which assertions will be called.
@type testCase: L{unittest.SynchronousTestCase}

@param expectedMessages: A L{list} of the expected log messages
@type expectedMessages: L{list}

@param callable: The function which is expected to produce the
    C{expectedMessages} when called.
@type callable: L{callable}

@param args: Positional arguments to be passed to C{callable}.
@type args: L{list}

@param kwargs: Keyword arguments to be passed to C{callable}.
@type kwargs: L{dict}
r(   N)r
   addObserverappend
addCleanupremoveObserverassertEqual)testCaseexpectedMessagescallabler   r   loggedMessagesms   &&&*,  r   assertLogMessagerd      so    . NOON))***N,A,ABdf>B>aI,q//>BDTUBs   $Bc                     a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t R t!R t"R  t#R! t$R" t%R# t&R$ t'R% t(R& t)R' t*R( t+R) t,R* t-R+ t.R, t/R- t0R. t1R/ t2R0 t3R1 t4R2 t5R3 t6R4 t7R5 t8R6 t9R7 t:R8 t;R9 t<R: t=R; t>R< t?R= t@R> tAR? tBR@ tCRA tDRBtEV tFRC# )DDNSServerFactoryTestsz'
Tests for L{server.DNSServerFactory}.
c                    V P                  \        P                  ! 4       P                  \        P
                  4       R# )zL
L{server.DNSServerFactory.resolver} is a L{resolve.ResolverChain}
instance
N)assertIsInstancer   DNSServerFactoryresolverr   ResolverChainr   s   &r   test_resolverType'DNSServerFactoryTests.test_resolverType   s)    
 	f557@@'BWBWXr   c                x    V P                  \        P                  ! 4       P                  P                  . 4       R# )zV
L{server.DNSServerFactory.resolver} is an empty L{resolve.ResolverChain}
by default.
Nr^   r   ri   rj   	resolversrl   s   &r   test_resolverDefaultEmpty/DNSServerFactoryTests.test_resolverDefaultEmpty   s)    
 	002;;EErJr   c                    \        4       pV P                  \        P                  ! V.R7      P                  P
                  V.4       R# )z
L{server.DNSServerFactory.__init__} accepts an C{authorities}
argument. The value of this argument is a list and is used to extend the
C{resolver} L{resolve.ResolverChain}.
)authoritiesNobjectr^   r   ri   rj   rq   r   dummyResolvers   & r   test_authorities&DNSServerFactoryTests.test_authorities   s:     ##@IISSO	
r   c                    \        4       pV P                  \        P                  ! V.R7      P                  P
                  V.4       R# )z
L{server.DNSServerFactory.__init__} accepts a C{caches} argument. The
value of this argument is a list and is used to extend the C{resolver}
L{resolve.ResolverChain}.
cachesNrv   rx   s   & r   test_caches!DNSServerFactoryTests.test_caches   s:     ##M?;DDNNO	
r   c                    \        4       pV P                  \        P                  ! V.R7      P                  P
                  V.4       R# )z
L{server.DNSServerFactory.__init__} accepts a C{clients} argument. The
value of this argument is a list and is used to extend the C{resolver}
L{resolve.ResolverChain}.
clientsNrv   rx   s   & r   test_clients"DNSServerFactoryTests.test_clients  s:     ##]O<EEOOO	
r   c                     ! R R4      p ! R R4      p ! R R4      pV P                  \        P                  ! V.V.V.R7      P                  P                  WV.4       R# )	zb
L{server.DNSServerFactory.resolver} contains an ordered list of
authorities, caches and clients.
c                       ] tR tRtRtR# )@DNSServerFactoryTests.test_resolverOrder.<locals>.DummyAuthorityi  r'   Nr   r   r   r   r   r'   r   r   DummyAuthorityr         r   r   c                       ] tR tRtRtR# )<DNSServerFactoryTests.test_resolverOrder.<locals>.DummyCachei  r'   Nr   r'   r   r   
DummyCacher     r   r   r   c                       ] tR tRtRtR# )=DNSServerFactoryTests.test_resolverOrder.<locals>.DummyClienti  r'   Nr   r'   r   r   DummyClientr     r   r   r   )ru   r~   r   Nrp   )r   r   r   r   s   &   r   test_resolverOrder(DNSServerFactoryTests.test_resolverOrder  s]    	 		 		 	 	##+,j\K=hyy5		
r   c                b    V P                  \        P                  ! 4       P                  4       R# )z9
L{server.DNSServerFactory.cache} is L{None} by default.
N)assertIsNoner   ri   cacherl   s   &r   test_cacheDefault'DNSServerFactoryTests.test_cacheDefault)  s!     	&11399:r   c                    \        4       pV P                  \        P                  ! \        4       V.R7      P                  V4       R# )zx
L{server.DNSServerFactory.__init__} assigns the last object in the
C{caches} list to L{server.DNSServerFactory.cache}.
r}   N)rw   r^   r   ri   r   rx   s   & r   test_cacheOverride(DNSServerFactoryTests.test_cacheOverride/  s7    
 ##FHm+DEKK	
r   c                b    V P                  \        P                  ! 4       P                  4       R# )z
L{server.DNSServerFactory.canRecurse} is a flag indicating that this
server is capable of performing recursive DNS lookups. It defaults to
L{False}.
N)assertFalser   ri   
canRecurserl   s   &r   test_canRecurseDefault,DNSServerFactoryTests.test_canRecurseDefault:  s!     	002==>r   c                j    V P                  \        P                  ! R.R7      P                  R4       R# )zf
L{server.DNSServerFactory.__init__} sets C{canRecurse} to L{True} if it
is supplied with C{clients}.
Nr   T)r^   r   ri   r   rl   s   &r   test_canRecurseOverride-DNSServerFactoryTests.test_canRecurseOverrideB  s'    
 	00$@KKTRr   c                b    V P                  \        P                  ! 4       P                  4       R# )z:
L{server.DNSServerFactory.verbose} defaults to L{False}.
N)r   r   ri   verboserl   s   &r   test_verboseDefault)DNSServerFactoryTests.test_verboseDefaultI  s!     	002::;r   c                f    V P                  \        P                  ! RR7      P                  4       R# )zw
L{server.DNSServerFactory.__init__} accepts a C{verbose} argument which
overrides L{server.DNSServerFactory.verbose}.
Tr   N)
assertTruer   ri   r   rl   s   &r   test_verboseOverride*DNSServerFactoryTests.test_verboseOverrideO  s!    
 	//=EEFr   c                `    V P                  \        \        \        P                  4      4       R# )z<
L{server.DNSServerFactory} implements L{IProtocolFactory}.
N)r   r   r   r   ri   rl   s   &r   test_interface$DNSServerFactoryTests.test_interfaceV  s     	$4f6M6MNOr   c                v    V P                  \        P                  P                  \        P
                  4       R# )zE
L{server.DNSServerFactory.protocol} defaults to L{dns.DNSProtocol}.
N)assertIsr   ri   r)   r   DNSProtocolrl   s   &r   test_defaultProtocol*DNSServerFactoryTests.test_defaultProtocol\  s"     	f--66Hr   c                   a  ! R R4      pV! 4       oV3R lp\         P                  ! 4       pW#n        VP                  RR7      pV P	                  SV3/ 3WDP
                  VP                  34       R# )z
L{server.DNSServerFactory.buildProtocol} builds a protocol by calling
L{server.DNSServerFactory.protocol} with its self as a positional
argument.
c                   "    ] tR tRtRtRtRtRtR# )NDNSServerFactoryTests.test_buildProtocolProtocolOverride.<locals>.FakeProtocolii  Nr'   )r   r   r   r   factoryr   r   r   r'   r   r   FakeProtocolr   i  s    GDFr   r   c                  $   < V Sn         VSn        S# r   r   )r   r   stubProtocols   *,r   fakeProtocolFactoryUDNSServerFactoryTests.test_buildProtocolProtocolOverride.<locals>.fakeProtocolFactoryp  s     $L"(Lr   N)addr)r   ri   r)   buildProtocolr^   r   r   )r   r   r   fpr   s   &    @r   "test_buildProtocolProtocolOverride8DNSServerFactoryTests.test_buildProtocolProtocolOverrideb  sf    	 	
 $~	 
 ##%(
OOO&,b1Avvqxx3HIr   c                `    \         P                  ! 4       p\        V . VP                  R4       R# )zU
L{server.DNSServerFactory._verboseLog} does not log messages unless
C{verbose > 0}.
Foo BarNr   ri   rd   _verboseLogr   r   s   & r   test_verboseLogQuiet*DNSServerFactoryTests.test_verboseLogQuiet{  s$    
 ##%r1==)<r   c                f    \         P                  ! ^R7      p\        V R.VP                  R4       R# )zJ
L{server.DNSServerFactory._verboseLog} logs a message if C{verbose > 0}.
r   r   Nr   r   s   & r   test_verboseLogVerbose,DNSServerFactoryTests.test_verboseLogVerbose  s(     ##A.	{AMM9Er   c           	         \         P                  ! 4       p\        ^R7      p\        V R.VP                  VRRR7       R# )z}
L{server.DNSServerFactory.messageReceived} logs about an empty query if
the message had no queries and C{verbose} is C{>0}.
r   z$Empty query from ('192.0.2.100', 53)Nr(   protor*   z192.0.2.1005   )r   Messager%   rd   messageReceivedr   rc   r   s   &  r   "test_messageReceivedLoggingNoQuery8DNSServerFactoryTests.test_messageReceivedLoggingNoQuery  s<    
 KKM&q134'	
r   c           	        \         P                  ! 4       pVP                  R\         P                  R7       VP                  R\         P                  R7       \        ^R7      p\        V R.VP                  VRRR7       R# )z}
L{server.DNSServerFactory.messageReceived} logs the query types of all
queries in the message if C{verbose} is set to C{1}.
example.comnametyper   z&MX AAAA query from ('192.0.2.100', 53)Nr   r   r   r   addQueryMXAAAAr%   rd   r   r   s   &  r   test_messageReceivedLogging12DNSServerFactoryTests.test_messageReceivedLogging1  sd    
 KKM	

CFF
3	

CHH
5&q156'	
r   c           	        \         P                  ! 4       pVP                  R\         P                  R7       VP                  R\         P                  R7       \        ^R7      p\        V R.VP                  VRRR7       R# )zv
L{server.DNSServerFactory.messageReceived} logs the repr of all queries
in the message if C{verbose} is set to C{2}.
r   r   r   zT<Query example.com MX IN> <Query example.com AAAA IN> query from ('192.0.2.100', 53)Nr   r   r   r   s   &  r   test_messageReceivedLogging22DNSServerFactoryTests.test_messageReceivedLogging2  sk    
 KKM	

CFF
3	

CHH
5&q1M '
	
r   c                  a \         P                  ! 4       p\        4       p\        4       oV P	                  \
        P                  RV3R l4       VP                  VRRR7       V P                  VP                  S4       R# )z^
L{server.DNSServerFactory.messageReceived} assigns a unix timestamp to
the received message.
timec                     < S # r   r'   )ts   r   <lambda>EDNSServerFactoryTests.test_messageReceivedTimestamp.<locals>.<lambda>  s    r   Nr   )
r   r   r%   rw   patchr   r   r   r^   timeReceived)r   rc   r   r   s   &  @r   test_messageReceivedTimestamp3DNSServerFactoryTests.test_messageReceivedTimestamp  s\    
 KKM&(H

6;;	2	!4>+r   c                .   \         P                  ! 4       p\        4       p\        4       p\        4       pV P	                  \        P
                  VP                  VVVR7      pVP                  w  rgV P                  WaW#34       V P                  V/ 4       R# )z
L{server.DNSServerFactory.messageReceived} passes all messages to
L{server.DNSServerFactory.allowQuery} along with the receiving protocol
and origin address.
r   N)	r   r   rw   r2   assertRaisesr7   r   r   r^   )r   r(   dummyProtocoldummyAddressr   er   r   s   &       r   test_messageReceivedAllowQuery4DNSServerFactoryTests.test_messageReceivedAllowQuery  s     ++-x#%#77   
 vvEF$r   c                H  a  ! R R\         4      o ! V3R lR\        P                  4      pV! 4       pV P                  SVP                  \
        P                  ! 4       RRR7      pVP                  w  w  rErgV P                  VP                  \
        P                  4       R# )z
If C{allowQuery} returns C{False},
L{server.DNSServerFactory.messageReceived} calls L{server.sendReply}
with a message whose C{rCode} is L{dns.EREFUSED}.
c                       ] tR tRtRtR# )FDNSServerFactoryTests.test_allowQueryFalse.<locals>.SendReplyExceptioni  r'   Nr   r'   r   r   SendReplyExceptionr     r   r   r   c                   4   <a  ] tR tRt o R tV3R ltRtV tR# )KDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactoryi  c                    R # )Fr'   r   s   &*,r   r+   VDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactory.allowQuery  s    r   c                   < S! W4      hr   r'   )r   r   r   r   s   &*,r   r.   UDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactory.sendReply  s    (66r   r'   N)r   r   r   r   r+   r.   r   r   )r!   r   s   @r   r2   r     s     7 7r   r2   Nr   )r;   r   ri   r   r   r   r   r   r^   rCodeEREFUSED)	r   r2   r   r   r   r(   r*   r   r   s	   &       @r   test_allowQueryFalse*DNSServerFactoryTests.test_allowQueryFalse  s    	 		7f&=&= 	7 $%KKM  
 -.FF)!5r   c                   a R.Vn         . oV3R lp\        4       p\        P                  ! R4      p\	        WQV4       VP                  W$4       V P                  SW$R3.4       R# )a\  
Assert that the named method is called with the given message when it is
passed to L{DNSServerFactory.messageReceived}.

@param methodName: The name of the method which is expected to be
    called.
@type methodName: L{str}

@param message: The message which is expected to be passed to the
    C{methodName} method.
@type message: L{dns.Message}
Nc                 .   < SP                  WV34       R # r   r[   )r(   r)   r*   receivedMessagess   &&&r   fakeHandler?DNSServerFactoryTests._messageReceivedTest.<locals>.fakeHandler  s    ##W$@Ar   )queriesrF   r   ri   setattrr   r^   )r   
methodNamer(   r	  r)   r   r  s   &&&   @r   _messageReceivedTest*DNSServerFactoryTests._messageReceivedTest  sd      &	B  >))$/[12)W,E+FGr   c                p    V P                  R\        P                  ! \        P                  R7      4       R# )zz
L{DNSServerFactory.messageReceived} passes messages with an opcode of
C{OP_QUERY} on to L{DNSServerFactory.handleQuery}.
handleQueryopCodeN)r  r   r   OP_QUERYrl   s   &r   test_queryMessageReceived/DNSServerFactoryTests.test_queryMessageReceived   s!    
 	!!-CLL1QRr   c                p    V P                  R\        P                  ! \        P                  R7      4       R# )z
L{DNSServerFactory.messageReceived} passes messages with an opcode of
C{OP_INVERSE} on to L{DNSServerFactory.handleInverseQuery}.
handleInverseQueryr  N)r  r   r   
OP_INVERSErl   s   &r    test_inverseQueryMessageReceived6DNSServerFactoryTests.test_inverseQueryMessageReceived'  s$    
 	!! #++S^^"D	
r   c                p    V P                  R\        P                  ! \        P                  R7      4       R# )z|
L{DNSServerFactory.messageReceived} passes messages with an opcode of
C{OP_STATUS} on to L{DNSServerFactory.handleStatus}.
handleStatusr  N)r  r   r   	OP_STATUSrl   s   &r   test_statusMessageReceived0DNSServerFactoryTests.test_statusMessageReceived0  !    
 	!!.#++S]]2STr   c                p    V P                  R\        P                  ! \        P                  R7      4       R# )z|
L{DNSServerFactory.messageReceived} passes messages with an opcode of
C{OP_NOTIFY} on to L{DNSServerFactory.handleNotify}.
handleNotifyr  N)r  r   r   	OP_NOTIFYrl   s   &r   test_notifyMessageReceived0DNSServerFactoryTests.test_notifyMessageReceived7  r!  r   c                p    V P                  R\        P                  ! \        P                  R7      4       R# )z
L{DNSServerFactory.messageReceived} passes messages with an opcode of
C{OP_UPDATE} on to L{DNSServerFactory.handleOther}.

This may change if the implementation ever covers update messages.
handleOtherr  N)r  r   r   	OP_UPDATErl   s   &r   test_updateMessageReceived0DNSServerFactoryTests.test_updateMessageReceived>  s!     	!!-CMM1RSr   c                   \        4       \        4       r!\        P                  ! 4       pVP                  V4       V P	                  VP
                  V.4       VP                  V4       V P	                  VP
                  W.4       VP                  V4       V P	                  VP
                  V.4       VP                  V4       V P	                  VP
                  . 4       R# )z
The C{connectionMade} and C{connectionLost} methods of
L{DNSServerFactory} cooperate to keep track of all L{DNSProtocol}
objects created by a factory which are connected.
N)rw   r   ri   connectionMader^   connectionsconnectionLost)r   protoAprotoBr   s   &   r   test_connectionTracking-DNSServerFactoryTests.test_connectionTrackingG  s      68))+v&,,vh7v&,,v.>?v&,,vh7v&,,b1r   c                   \         P                  ! 4       pVP                  R4       VP                  R4       \        P                  ! 4       p\        4       Vn        V P                  \
        P                  VP                  V\        4       RR7      pVP                  w  w  rEV P                  WAP                  ^ ,          4       R# )z
L{server.DNSServerFactory.handleQuery} takes the first query from the
supplied message and dispatches it to
L{server.DNSServerFactory.resolver.query}.
   one.example.coms   two.example.comNr(   r)   r*   )r   r   r   r   ri   rJ   rj   r   rM   r  rF   r   r^   r  )r   rc   r   r   rO   r   s   &     r   test_handleQuery&DNSServerFactoryTests.test_handleQueryX  s     KKM	

%&	

%&##%$&
**MM!^  
 66		!-r   c                  aa	 \         P                  ! 4       p\        P                  ! 4       o ! V3R lR4      pV! 4       Vn        . o	V	3R lpW1n        \        P                  ! 4       pVP                  R4       \        4       p\        4       pVP                  WEVR7       \        4       pSP                  V4       V P                  S	WuWF3/ 3.4       R# )a  
L{server.DNSServerFactory.handleQuery} adds
L{server.DNSServerFactory.resolver.gotResolverResponse} as a callback to
the deferred returned by L{server.DNSServerFactory.resolver.query}. It
is called with the query response, the original protocol, message and
origin address.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )DDNSServerFactoryTests.test_handleQueryCallback.<locals>.FakeResolveriz  c                   < S# r   r'   r   r   r   ds   &*,r   rO   JDNSServerFactoryTests.test_handleQueryCallback.<locals>.FakeResolver.query{      r   r'   Nr   r   r   r   rO   r   r   r!   r>  s   @r   FakeResolverr;  z        r   rC  c                  ,   < SP                  W34       R # r   r  )r   r   gotResolverResponseArgss   *,r   fakeGotResolverResponseODNSServerFactoryTests.test_handleQueryCallback.<locals>.fakeGotResolverResponse  s    #**D>:r   r5  r6  N)r   ri   r   Deferredrj   gotResolverResponser   r   r   rF   rw   r  callbackr^   )
r   r   rC  rG  rc   r   r   dummyResponser>  rF  s
   &       @@r   test_handleQueryCallback.DNSServerFactoryTests.test_handleQueryCallbackn  s     ##%NN	 	 "^
"$	; !8KKM	

%&#~x	aM	

=!#A<bAB	
r   c                  aa	 \         P                  ! 4       p\        P                  ! 4       o ! V3R lR4      pV! 4       Vn        . o	V	3R lpW1n        \        P                  ! 4       pVP                  R4       \        4       p\        4       pVP                  WEVR7       \        P                  ! \        4       4      pSP                  V4       V P!                  S	WuWF3/ 3.4       R# )a  
L{server.DNSServerFactory.handleQuery} adds
L{server.DNSServerFactory.resolver.gotResolverError} as an errback to
the deferred returned by L{server.DNSServerFactory.resolver.query}. It
is called with the query failure, the original protocol, message and
origin address.
c                   .   <a  ] tR tRt o V3R ltRtV tR# )CDNSServerFactoryTests.test_handleQueryErrback.<locals>.FakeResolveri  c                   < S# r   r'   r=  s   &*,r   rO   IDNSServerFactoryTests.test_handleQueryErrback.<locals>.FakeResolver.query  r@  r   r'   NrA  rB  s   @r   rC  rQ    rD  r   rC  c                  ,   < SP                  W34       R # r   r  )r   r   gotResolverErrorArgss   *,r   fakeGotResolverErrorKDNSServerFactoryTests.test_handleQueryErrback.<locals>.fakeGotResolverError  s     ''7r   r5  r6  N)r   ri   r   rI  rj   gotResolverErrorr   r   r   rF   rw   r  r	   Failurer;   errbackr^   )
r   r   rC  rV  rc   r   r   stubFailurer>  rU  s
   &       @@r   test_handleQueryErrback-DNSServerFactoryTests.test_handleQueryErrback  s     ##%NN	 	 "^
!	8 2KKM	

%&#~x	aMooik2			+ [$PRT#U"V	
r   c           	        \         P                  ! 4       p. p. p. pV P                  \        P                  VP
                  W#V3\        4       \        P                  ! 4       RR7      pVP                  w  w  rgV P                  VP                  V4       V P                  VP                  V4       V P                  VP                  V4       R# )z
L{server.DNSServerFactory.gotResolverResponse} accepts a tuple of
resource record lists and triggers a response message containing those
resource record lists.
Nr)   r(   r*   )r   ri   r   r=   r@   rJ  r   r   r   r   answers	authority
additional)r   r   r`  ra  rb  r   r(   r   s   &       r   test_gotResolverResponse.DNSServerFactoryTests.test_gotResolverResponse  s     ##%	
11!!,$&KKM  
 VV
goow/g''3g((*5r   c                D   \        4       p\        Vn        \        P                  ! 4       p^Vn        V P                  \        VP                  . . . 3RVRR7      pV P                  R\        V\        P                  . . . R7      3VP                  VP                  34       R# )z~
L{server.DNSServerFactory.gotResolverResponse} calls
L{server.DNSServerFactory._responseFromMessage} to generate a response.
Nr_  )r(   r  r`  ra  rb  r'   )r%   r#   _responseFromMessager   r   r   r   r   rJ  r^   dictOKr   r   r   r   requestr   s   &   r   0test_gotResolverResponseCallsResponseFromMessageFDNSServerFactoryTests.test_gotResolverResponseCallsResponseFromMessage  s    
 -.'-$++- ''RL  
 	#&& !	 VVQXX	
r   c                    \         P                  ! 4       p\        P                  ! RRR7      pVP	                  VR7      3pV P                  W#4       R# )zv
L{server.DNSServerFactory._responseFromMessage} generates a response
message which is a copy of the request message.
F)answerrecAvr(   N)r   ri   r   r   rf  assertIsNotr   r   rj  responses   &   r   "test_responseFromMessageNewMessage8DNSServerFactoryTests.test_responseFromMessageNewMessage  sF    
 ))+++U%8000AC+r   c                8   \         P                  ! 4       pRVn        VP                  \        P
                  ! RR7      R7      pRVn        VP                  \        P
                  ! RR7      R7      pV P                  RVP                  VP                  34       R# )z
L{server.DNSServerFactory._responseFromMessage} generates a response
message whose C{recAV} attribute is L{True} if
L{server.DNSServerFactory.canRecurse} is L{True}.
TF)ro  rp  NTF)r   ri   r   rf  r   r   r^   ro  r   r   	response1	response2s   &   r   *test_responseFromMessageRecursionAvailable@DNSServerFactoryTests.test_responseFromMessageRecursionAvailable  sw     ))+!0059Q0R	"0049P0Q	)//(JKr   c                    \         P                  ! 4       p\        P                  ! 4       pRVn        VP                  VR7      pV P                  VP                  VP                  4       R# )z
L{server.DNSServerFactory._responseFromMessage} generates a response
message whose C{timeReceived} attribute has the same value as that found
on the request.
i  rp  N)r   ri   r   r   r   rf  r^   rr  s   &   r   $test_responseFromMessageTimeReceived:DNSServerFactoryTests.test_responseFromMessageTimeReceived  sT     ))+++-#///@--x/D/DEr   c                    \         P                  ! 4       p\        P                  ! 4       p^ Vn        VP                  VR7      pV P                  VP                  VP                  4       R# )z
L{server.DNSServerFactory._responseFromMessage} generates a response
message whose C{maxSize} attribute has the same value as that found
on the request.
rp  N)r   ri   r   r   maxSizerf  r^   rr  s   &   r   test_responseFromMessageMaxSize5DNSServerFactoryTests.test_responseFromMessageMaxSize  sQ     ))+++-///@(*:*:;r   c                v    V P                  \        P                  \        P                  P
                  4       R# )zc
L{server.DNSServerFactory} has a C{_messageFactory} attribute which is
L{dns.Message} by default.
N)r   r   r   r   ri   _messageFactoryrl   s   &r   test_messageFactory)DNSServerFactoryTests.test_messageFactory(  s"    
 	ckk6#:#:#J#JKr   c                   \         P                  ! 4       pV P                  \        R\        4       \        P
                  ! 4       pV P                  \        VP                  V\        P                  R7      pV P                  R\        VP                  V\        P                  VP                  RR7      3VP                  VP                  34       R# )a  
L{server.DNSServerFactory._responseFromMessage} calls
C{dns._responseFromMessage} to generate a response
message from the request message. It supplies the request message and
other keyword arguments which should be passed to the response message
initialiser.
rf  r(   r  F)responseConstructorr(   r  ro  authNr'   )r   ri   r   r   r#   r   r   r   rf  rh  r^   rg  r  r   r   r   ri  s   &   r   +test_responseFromMessageCallsMessageFactoryADNSServerFactoryTests.test_responseFromMessageCallsMessageFactory/  s     ))+

3.7++-W997RURXRX  
 	(/(?(?#&&!,,	 VVQXX	
r   c                p   \         P                  ! 4       pVP                  \        P                  ! 4       \        P
                  ! RR7      .R7      pVP                  \        P                  ! 4       \        P
                  ! RR7      .R7      pV P                  RVP                  VP                  34       R# )z
L{server.DNSServerFactory._responseFromMessage} marks the response
message as authoritative if any of the answer records are authoritative.
T)r  )r(   r`  FNrw  )r   ri   rf  r   r   RRHeaderr^   r  rx  s   &   r   ,test_responseFromMessageAuthoritativeMessageBDNSServerFactoryTests.test_responseFromMessageAuthoritativeMessageL  s    
 ))+00KKMCLLd,C+D 1 
	 00KKMCLLe,D+E 1 
	 	^^Y^^,	
r   c           
        \        ^R7      p\        P                  ! 4       .p\        P                  ! 4       .p\        P                  ! 4       .p\        V R.VP                  W#V3\        4       \        P                  ! 4       RR7       R# )zt
L{server.DNSServerFactory.gotResolverResponse} logs the total number of
records in the response if C{verbose > 0}.
r   zLookup found 3 recordsNr_  )r%   r   r  rd   rJ  rF   r   )r   r   r`  ra  rb  s   &    r   test_gotResolverResponseLogging5DNSServerFactoryTests.test_gotResolverResponseLogging]  sk    
 'q1<<>"\\^$	lln%
%&!!,!^KKM	
r   c           	        \        \        4       .R7      p\        P                  ! 4       pVP	                  R4       \        P
                  ! 4       .p. p. pV P                  \        P                  VP                  W4V3\        4       VRR7      pVP                  w  w  pw  rrV P                  VP                  P                  R4       V P                  W4       V P                  W4       V P                  W4       R# )z{
L{server.DNSServerFactory.gotResolverResponse} caches the response if at
least one cache was provided in the constructor.
r}   s   example.comNr_  )r%   rR   r   r   r   r  r   rU   rJ  rF   r   r^   r   r   )r   r   rc   expectedAnswersexpectedAuthorityexpectedAdditionalr   rO   r`  ra  rb  r   s   &           r   test_gotResolverResponseCaching5DNSServerFactoryTests.test_gotResolverResponseCachingq  s    
 '|~.>?KKM	

>"<<>*--!!1CD!^  
 =>FF910Z.9g/i3j5r   c           	        \        4       p\        Vn        \        P                  ! 4       p^Vn        V P                  \        VP                  \        P                  ! \        P                  ! 4       4      RVRR7      pV P                  R\        V\        P                  R7      3VP                   VP"                  34       R# )z{
L{server.DNSServerFactory.gotResolverError} calls
L{server.DNSServerFactory._responseFromMessage} to generate a response.
Nr_  r  r'   )r%   r#   rf  r   r   r   r   r   rX  r	   rY  r   DomainErrorr^   rg  ENAMEr   r   ri  s   &   r   -test_gotResolverErrorCallsResponseFromMessageCDNSServerFactoryTests.test_gotResolverErrorCallsResponseFromMessage  s    
 -.'-$++- $$OOE--/0  
 	gSYY78166188:L	
r   c           	     D   \         P                  ! 4       pV P                  \        P                  VP
                  \        P                  ! V4      \        4       \        P                  ! 4       RR7      pVP                  w  w  rVV P                  VP                  V4       R# )a  
L{server.DNSServerFactory.gotResolver} accepts a L{failure.Failure} and
triggers a response message whose rCode corresponds to the DNS error
contained in the C{Failure}.

@param responseError: The L{Exception} instance which is expected to
    trigger C{expectedMessageCode} when it is supplied to
    C{gotResolverError}
@type responseError: L{Exception}

@param expectedMessageCode: The C{rCode} which is expected in the
    message returned by C{gotResolverError} in response to
    C{responseError}.
@type expectedMessageCode: L{int}
Nr_  )r   ri   r   r=   r@   rX  r	   rY  r   r   r   r^   r  )r   responseErrorexpectedMessageCoder   r   r(   r   s   &&&    r   _assertMessageRcodeForError1DNSServerFactoryTests._assertMessageRcodeForError  s|      ##%11OOM*$&KKM  
 VV
(;<r   c                l    V P                  \        P                  ! 4       \        P                  4       R# )z
L{server.DNSServerFactory.gotResolver} triggers a response message with
an C{rCode} of L{dns.ENAME} if supplied with a L{error.DomainError}.
N)r  r   r  r   r  rl   s   &r    test_gotResolverErrorDomainError6DNSServerFactoryTests.test_gotResolverErrorDomainError  s!    
 	(():):)<ciiHr   c                l    V P                  \        P                  ! 4       \        P                  4       R# )z
L{server.DNSServerFactory.gotResolver} triggers a response message with
an C{rCode} of L{dns.ENAME} if supplied with a
L{error.AuthoritativeDomainError}.
N)r  r   AuthoritativeDomainErrorr   r  rl   s   &r   -test_gotResolverErrorAuthoritativeDomainErrorCDNSServerFactoryTests.test_gotResolverErrorAuthoritativeDomainError  s!     	(()G)G)I399Ur   c                    V P                  \        4       \        P                  4       V P	                  \        4      pV P                  \        V4      ^4       R# )z
L{server.DNSServerFactory.gotResolver} triggers a response message with
an C{rCode} of L{dns.ESERVER} if supplied with another type of error and
logs the error.
N)r  KeyErrorr   ESERVERflushLoggedErrorsr^   len)r   r   s   & r   test_gotResolverErrorOtherError5DNSServerFactoryTests.test_gotResolverErrorOtherError  s>     	((S[[A""8,Q#r   c           
         \        ^R7      p\        V R.VP                  \        P                  ! \
        P                  ! 4       4      \        4       \        P                  ! 4       RR7       R# )zJ
L{server.DNSServerFactory.gotResolver} logs a message if C{verbose > 0}.
r   zLookup failedNr_  )
r%   rd   rX  r	   rY  r   r  rF   r   r   r   s   & r   test_gotResolverErrorLogging2DNSServerFactoryTests.test_gotResolverErrorLogging  sN     'q1OOE--/0!^KKM	
r   c                  a \         P                  ! 4       p. oV3R lVn        \        P                  ! RRR7      p\        4       \        4       .Vn        \        4       \        4       .Vn        \        4       \        4       .Vn        VP                  \        P                  ! \        P                  ! 4       4      RVRR7       V P                  \        P                  ! ^RR7      .S4       R# )z
L{server.DNSServerFactory.gotResolverError} does not allow request
attributes to leak into the response ie it sends a response with AD, CD
set to 0 and empty response record sections.
c                 &   < SP                  V4      # r   r  r)   rs  r*   	responsess   &&&r   r   UDNSServerFactoryTests.test_gotResolverErrorResetsResponseAttributes.<locals>.<lambda>      	@P@PA
r   TauthenticDatacheckingDisabledNr_  r  rn  )r   ri   r.   r   r   rw   r`  ra  rb  rX  r	   rY  r   r  r^   r   r   rj  r  s   &  @r   -test_gotResolverErrorResetsResponseAttributesCDNSServerFactoryTests.test_gotResolverErrorResetsResponseAttributes  s     ))+	
 ++D4H!8VX.#Xvx0$h1  OOE--/0	 	! 	
 	#++Ad;<iHr   c                  a \         P                  ! 4       p. oV3R lVn        \        P                  ! RRR7      p\        4       \        4       .Vn        \        4       \        4       .Vn        \        4       \        4       .Vn        VP                  . . . 3RVRR7       V P                  \        P                  ! ^ RR7      .S4       R# )z
L{server.DNSServerFactory.gotResolverResponse} does not allow request
attributes to leak into the response ie it sends a response with AD, CD
set to 0 and none of the records in the request answer sections are
copied to the response.
c                 &   < SP                  V4      # r   r  r  s   &&&r   r   XDNSServerFactoryTests.test_gotResolverResponseResetsResponseAttributes.<locals>.<lambda>
  r  r   Tr  Nr_  r  )r   ri   r.   r   r   rw   r`  ra  rb  rJ  r^   r  s   &  @r   0test_gotResolverResponseResetsResponseAttributesFDNSServerFactoryTests.test_gotResolverResponseResetsResponseAttributes  s     ))+	
 ++D4H!8VX.#Xvx0$h1##RL4$ 	$ 	
 	#++Ad;<iHr   c                @   \         P                  ! 4       p\        4       p\        P                  ! 4       pV P                  \        P                  VP                  \        4       VVR7      pVP                  w  rVV P                  WQV34       V P                  V/ 4       R# )z
If L{server.DNSServerFactory.sendReply} is supplied with a protocol
*and* an address tuple it will supply that address to
C{protocol.writeMessage}.
r_  N)r   r   rw   r   ri   r   r=   r@   r.   r   r^   )r   rc   r   r   r   r   r   s   &      r   test_sendReplyWithAddress/DNSServerFactoryTests.test_sendReplyWithAddress  s     KKMx##%11KK$&   
 vv<01$r   c                *   \         P                  ! 4       p\        P                  ! 4       pV P	                  \
        P                  VP                  \        4       VRR7      pVP                  w  rEV P                  WA34       V P                  V/ 4       R# )z
If L{server.DNSServerFactory.sendReply} is supplied with a protocol but
no address tuple it will supply only a message to
C{protocol.writeMessage}.
Nr_  )
r   r   r   ri   r   r=   r@   r.   r   r^   )r   rc   r   r   r   r   s   &     r   test_sendReplyWithoutAddress2DNSServerFactoryTests.test_sendReplyWithoutAddress,  s{     KKM##%11KK$&  
 vvt$$r   c           	         V P                  \        P                  RR 4       \        P                  ! 4       pRVn        \        P                  ! ^R7      p\        V RR.VP                  \        4       VRR7       R# )	zm
If L{server.DNSServerFactory.sendReply} logs a "no answers" message if
the supplied message has no answers.
r   c                      R # iQ r'   r'   r   r   r   FDNSServerFactoryTests.test_sendReplyLoggingNoAnswers.<locals>.<lambda>D      r   Q r   zReplying with no answers Processed query in 1.000 secondsNr_  )
r   r   r   r   r   r   ri   rd   r.   rF   r   s   &  r   test_sendReplyLoggingNoAnswers4DNSServerFactoryTests.test_sendReplyLoggingNoAnswers?  s`    
 	

6;;6KKM##A.')KLKK!^	
r   c           	        V P                  \        P                  RR 4       \        P                  ! 4       pVP
                  P                  \        P                  ! \        P                  ! R4      R7      4       VP                  P                  \        P                  ! \        P                  ! R4      R7      4       VP                  P                  \        P                  ! \        P                  ! R4      R7      4       RVn        \        P                  ! ^R7      p\        V . R	OVP                  \        4       VRR7       R# )
z
If L{server.DNSServerFactory.sendReply} logs a message for answers,
authority, additional if the supplied a message has records in any of
those sections.
r   c                      R # r  r'   r'   r   r   r   HDNSServerFactoryTests.test_sendReplyLoggingWithAnswers.<locals>.<lambda>W  r  r   z	127.0.0.1)payloadr  r   Nr_  )z*Answers are <A address=127.0.0.1 ttl=None>z+Authority is <A address=127.0.0.1 ttl=None>z,Additional is <A address=127.0.0.1 ttl=None>r  )r   r   r   r   r   r`  r[   r  Record_Ara  rb  r   ri   rd   r.   rF   r   s   &  r    test_sendReplyLoggingWithAnswers6DNSServerFactoryTests.test_sendReplyLoggingWithAnswersQ  s     	

6;;6KKM			cll;.GHI	3<<[0IJK	CLLk1JKL##A. KK!^	
r   c                6   \         P                  ! 4       pV P                  \        P                  VP
                  \        P                  ! 4       \        4       RR7      pVP                  w  w  r4V P                  VP                  \        P                  4       R# )z
L{server.DNSServerFactory.handleInverseQuery} triggers the sending of a
response message with C{rCode} set to L{dns.ENOTIMP}.
Nr6  )r   ri   r   r=   r@   r  r   r   r   r^   r  ENOTIMPr   r   r   r(   r   s   &    r   test_handleInverseQuery-DNSServerFactoryTests.test_handleInverseQueryl  ss    
 ##%11  KKM$&  
 VV
4r   c           	         \        ^R7      p\        V R.VP                  \        P                  ! 4       \        4       RR7       R# )zb
L{server.DNSServerFactory.handleInverseQuery} logs the message origin
address if C{verbose > 0}.
r   zInverse query from ('::1', 53)r6  Nz::1r   )r%   rd   r  r   r   rF   r   s   & r   test_handleInverseQueryLogging4DNSServerFactoryTests.test_handleInverseQueryLogging}  s9    
 'q1-.  KKM!^	
r   c                6   \         P                  ! 4       pV P                  \        P                  VP
                  \        P                  ! 4       \        4       RR7      pVP                  w  w  r4V P                  VP                  \        P                  4       R# )zy
L{server.DNSServerFactory.handleStatus} triggers the sending of a
response message with C{rCode} set to L{dns.ENOTIMP}.
Nr6  )r   ri   r   r=   r@   r  r   r   r   r^   r  r  r  s   &    r   test_handleStatus'DNSServerFactoryTests.test_handleStatus  q    
 ##%11NNKKM$&  
 VV
4r   c           	         \        ^R7      p\        V R.VP                  \        P                  ! 4       \        4       RR7       R# )z\
L{server.DNSServerFactory.handleStatus} logs the message origin address
if C{verbose > 0}.
r   zStatus request from ('::1', 53)r6  Nr  )r%   rd   r  r   r   rF   r   s   & r   test_handleStatusLogging.DNSServerFactoryTests.test_handleStatusLogging  7    
 'q1./NNKKM!^	
r   c                6   \         P                  ! 4       pV P                  \        P                  VP
                  \        P                  ! 4       \        4       RR7      pVP                  w  w  r4V P                  VP                  \        P                  4       R# )zy
L{server.DNSServerFactory.handleNotify} triggers the sending of a
response message with C{rCode} set to L{dns.ENOTIMP}.
Nr6  )r   ri   r   r=   r@   r#  r   r   r   r^   r  r  r  s   &    r   test_handleNotify'DNSServerFactoryTests.test_handleNotify  r  r   c           	         \        ^R7      p\        V R.VP                  \        P                  ! 4       \        4       RR7       R# )z\
L{server.DNSServerFactory.handleNotify} logs the message origin address
if C{verbose > 0}.
r   zNotify message from ('::1', 53)r6  Nr  )r%   rd   r#  r   r   rF   r   s   & r   test_handleNotifyLogging.DNSServerFactoryTests.test_handleNotifyLogging  r  r   c                6   \         P                  ! 4       pV P                  \        P                  VP
                  \        P                  ! 4       \        4       RR7      pVP                  w  w  r4V P                  VP                  \        P                  4       R# )zx
L{server.DNSServerFactory.handleOther} triggers the sending of a
response message with C{rCode} set to L{dns.ENOTIMP}.
Nr6  )r   ri   r   r=   r@   r(  r   r   r   r^   r  r  r  s   &    r   test_handleOther&DNSServerFactoryTests.test_handleOther  sq    
 ##%11MMKKM$&  
 VV
4r   c           	         \        ^R7      p\        V R.VP                  \        P                  ! 4       \        4       RR7       R# )z[
L{server.DNSServerFactory.handleOther} logs the message origin address
if C{verbose > 0}.
r   z$Unknown op code (0) from ('::1', 53)r6  Nr  )r%   rd   r(  r   r   rF   r   s   & r   test_handleOtherLogging-DNSServerFactoryTests.test_handleOtherLogging  s7    
 'q134MMKKM!^	
r   r'   N)Gr   r   r   r   r   rm   rr   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r%  r*  r2  r7  rM  r\  rc  rk  rt  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r    s   @r   rf   rf      sf    YK






.;	
?S<GPIJ2=F
"
&
,,%,6:H8S
UUT2".,&
P%
N60
B	,LF<L
:
"
(68
.=:IV$
I0I.%(%&
$
65"
5"
5"
5"
 
r   rf   N)r   zope.interface.verifyr   twisted.internetr   twisted.internet.interfacesr   twisted.namesr   r   r   r   twisted.pythonr	   r
   twisted.trialr   r;   r   r#   ri   r%   r2   r=   rF   rJ   rR   rd   TestCaserf   r'   r   r   <module>r     s    . " 8 5 5 ' "i (!8!8 B5f55 5:7 70 "0 006 60V@O
H-- O
r   