AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/names/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/names/test/__pycache__/test_server.cpython-310.pyc
o

�bǢ�@s�dZddlmZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
mZddlmZGdd	�d	e�Zd
d�ZGdd
�d
ej�ZGdd�dej�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�Zdd�ZGdd�dej�ZdS)z)
Test cases for L{twisted.names.server}.
�)�verifyClass)�defer)�IProtocolFactory)�dns�error�resolve�server)�failure�log)�unittestc@�eZdZdZdd�ZdS)�RaisedArgumentszD
    An exception containing the arguments raised by L{raiser}.
    cCs||_||_dS�N��args�kwargs��selfrr�r�@/usr/lib/python3/dist-packages/twisted/names/test/test_server.py�__init__s
zRaisedArguments.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrr
�r
cOs
t||��)z�
    Raise a L{RaisedArguments} exception containing the supplied arguments.

    Used as a fake when testing the call signatures of  methods and functions.
    )r
rrrr�raisers
rc@s eZdZdZdd�Zdd�ZdS)�NoResponseDNSServerFactorya
    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.
    cC�dS)a
        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}
        Fr)r�message�protocol�addressrrr�
allowQuery.sz%NoResponseDNSServerFactory.allowQuerycCr)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)rr rr!rrr�	sendReply;�z$NoResponseDNSServerFactory.sendReplyN)rrrrr"r#rrrrr$s	
rc@�(eZdZdZGdd�de�Zdd�ZdS)�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@�eZdZdZdS)z+RaisingDNSServerFactory.AllowQueryArguments�G
        Contains positional and keyword arguments in C{args}.
        N�rrrrrrrr�AllowQueryArgumentsN�r*cO�|�||��)aC
        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}
        )r*rrrrr"Ssz"RaisingDNSServerFactory.allowQueryN)rrrr�	Exceptionr*r"rrrrr&Esr&c@r%)�RaisingProtocolzm
    A partial fake L{IProtocol} whose methods raise an exception containing the
    supplied arguments.
    c@r')z%RaisingProtocol.WriteMessageArgumentsr(Nr)rrrr�WriteMessageArgumentshr+r/cOr,�z�
        Raises the supplied arguments.

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

        @param kwargs: Keyword args
        @type kwargs: L{dict}
        )r/rrrr�writeMessagem�
zRaisingProtocol.writeMessageN)rrrrr-r/r1rrrrr.b�r.c@r)�NoopProtocolzT
    A partial fake L{dns.DNSProtocolMixin} with a noop L{writeMessage} method.
    cOr)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}
        Nrrrrrr1r$zNoopProtocol.writeMessageN)rrrrr1rrrrr4zrr4c@r%)�RaisingResolverzm
    A partial fake L{IResolver} whose methods raise an exception containing the
    supplied arguments.
    c@r')zRaisingResolver.QueryArgumentsr(Nr)rrrr�QueryArguments�r+r6cOr,r0)r6rrrr�query�r2zRaisingResolver.queryN)rrrrr-r6r7rrrrr5�r3r5c@r%)�RaisingCachez}
    A partial fake L{twisted.names.cache.Cache} whose methods raise an exception
    containing the supplied arguments.
    c@r')z!RaisingCache.CacheResultArgumentsr(Nr)rrrr�CacheResultArguments�r+r9cOr,r0)r9rrrr�cacheResult�r2zRaisingCache.cacheResultN)rrrrr-r9r:rrrrr8�r3r8cOsHg}t�|j�|�tj|j�||i|��|�dd�|D�|�dS)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}
    cSsg|]}|dd�qS)rrr)�.0�mrrr�
<listcomp>�sz$assertLogMessage.<locals>.<listcomp>N)r
�addObserver�append�
addCleanup�removeObserver�assertEqual)�testCase�expectedMessages�callablerr�loggedMessagesrrr�assertLogMessage�s
rGc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2d`da�Z3dbdc�Z4ddde�Z5dfdg�Z6dhdi�Z7djdk�Z8dldm�Z9dndo�Z:dpdq�Z;drds�Z<dtdu�Z=dvdw�Z>dxdy�Z?dzd{�Z@d|d}�ZAd~d�ZBd�d��ZCd�S)��DNSServerFactoryTestsz/
    Tests for L{server.DNSServerFactory}.
    cCs|�t��jtj�dS)zd
        L{server.DNSServerFactory.resolver} is a L{resolve.ResolverChain}
        instance
        N)�assertIsInstancer�DNSServerFactory�resolverr�
ResolverChain�rrrr�test_resolverType��z'DNSServerFactoryTests.test_resolverTypecCs|�t��jjg�dS)zn
        L{server.DNSServerFactory.resolver} is an empty L{resolve.ResolverChain}
        by default.
        N�rBrrJrK�	resolversrMrrr�test_resolverDefaultEmpty�rOz/DNSServerFactoryTests.test_resolverDefaultEmptycC�&t�}|�tj|gd�jj|g�dS)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��objectrBrrJrKrQ�r�
dummyResolverrrr�test_authorities��
�z&DNSServerFactoryTests.test_authoritiescCrS)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}.
        ��cachesNrUrWrrr�test_caches�rZz!DNSServerFactoryTests.test_cachescCrS)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}.
        ��clientsNrUrWrrr�test_clientsrZz"DNSServerFactoryTests.test_clientscCsVGdd�d�}Gdd�d�}Gdd�d�}|�tj|g|g|gd�jj|||g�dS)	zz
        L{server.DNSServerFactory.resolver} contains an ordered list of
        authorities, caches and clients.
        c@�eZdZdS)z@DNSServerFactoryTests.test_resolverOrder.<locals>.DummyAuthorityN�rrrrrrr�DummyAuthority�rcc@ra)z<DNSServerFactoryTests.test_resolverOrder.<locals>.DummyCacheNrbrrrr�
DummyCacherdrec@ra)z=DNSServerFactoryTests.test_resolverOrder.<locals>.DummyClientNrbrrrr�DummyClientrdrf)rTr\r_NrP)rrcrerfrrr�test_resolverOrders��z(DNSServerFactoryTests.test_resolverOrdercC�|�t��j�dS)zI
        L{server.DNSServerFactory.cache} is L{None} by default.
        N)�assertIsNonerrJ�cacherMrrr�test_cacheDefault(�z'DNSServerFactoryTests.test_cacheDefaultcCs&t�}|�tjt�|gd�j|�dS)z�
        L{server.DNSServerFactory.__init__} assigns the last object in the
        C{caches} list to L{server.DNSServerFactory.cache}.
        r[N)rVrBrrJrjrWrrr�test_cacheOverride.s
�z(DNSServerFactoryTests.test_cacheOverridecCrh)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)�assertFalserrJ�
canRecurserMrrr�test_canRecurseDefault9sz,DNSServerFactoryTests.test_canRecurseDefaultcCs|�tjdgd�jd�dS)z~
        L{server.DNSServerFactory.__init__} sets C{canRecurse} to L{True} if it
        is supplied with C{clients}.
        Nr^T)rBrrJrorMrrr�test_canRecurseOverrideAsz-DNSServerFactoryTests.test_canRecurseOverridecCrh)zJ
        L{server.DNSServerFactory.verbose} defaults to L{False}.
        N)rnrrJ�verboserMrrr�test_verboseDefaultHrlz)DNSServerFactoryTests.test_verboseDefaultcCs|�tjdd�j�dS)z�
        L{server.DNSServerFactory.__init__} accepts a C{verbose} argument which
        overrides L{server.DNSServerFactory.verbose}.
        T�rrN)�
assertTruerrJrrrMrrr�test_verboseOverrideNrOz*DNSServerFactoryTests.test_verboseOverridecCs|�tttj��dS)zL
        L{server.DNSServerFactory} implements L{IProtocolFactory}.
        N)rurrrrJrMrrr�test_interfaceU�z$DNSServerFactoryTests.test_interfacecCs|�tjjtj�dS)zU
        L{server.DNSServerFactory.protocol} defaults to L{dns.DNSProtocol}.
        N)�assertIsrrJr r�DNSProtocolrMrrr�test_defaultProtocol[rxz*DNSServerFactoryTests.test_defaultProtocolcs\Gdd�d�}|���fdd�}t��}||_|jdd�}|��|fif||j|jf�dS)z�
        L{server.DNSServerFactory.buildProtocol} builds a protocol by calling
        L{server.DNSServerFactory.protocol} with its self as a positional
        argument.
        c@seZdZdZdZdZdS)zNDNSServerFactoryTests.test_buildProtocolProtocolOverride.<locals>.FakeProtocolN)rrr�factoryrrrrrr�FakeProtocolhsr}cs|�_|�_�Srrr��stubProtocolrr�fakeProtocolFactoryoszUDNSServerFactoryTests.test_buildProtocolProtocolOverride.<locals>.fakeProtocolFactoryN)�addr)rrJr �
buildProtocolrBrr)rr}r��f�prr~r�"test_buildProtocolProtocolOverrideas"z8DNSServerFactoryTests.test_buildProtocolProtocolOverridecCst��}t|g|jd�dS)zm
        L{server.DNSServerFactory._verboseLog} does not log messages unless
        C{verbose > 0}.
        �Foo BarN�rrJrG�_verboseLog�rr�rrr�test_verboseLogQuietzsz*DNSServerFactoryTests.test_verboseLogQuietcCs"tjdd�}t|dg|jd�dS)zZ
        L{server.DNSServerFactory._verboseLog} logs a message if C{verbose > 0}.
        �rtr�Nr�r�rrr�test_verboseLogVerbose�sz,DNSServerFactoryTests.test_verboseLogVerbosecCs.t��}tdd�}t|dg|j|ddd�dS)z�
        L{server.DNSServerFactory.messageReceived} logs about an empty query if
        the message had no queries and C{verbose} is C{>0}.
        r�rtz$Empty query from ('192.0.2.100', 53)N�z192.0.2.100�5�r�protor!)r�MessagerrG�messageReceived�rr<r�rrr�"test_messageReceivedLoggingNoQuery�s

�z8DNSServerFactoryTests.test_messageReceivedLoggingNoQuerycC�Nt��}|jdtjd�|jdtjd�tdd�}t|dg|j|ddd�dS)	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�rtz&MX AAAA query from ('192.0.2.100', 53)Nr�r��rr��addQuery�MX�AAAArrGr�r�rrr�test_messageReceivedLogging1�s

�z2DNSServerFactoryTests.test_messageReceivedLogging1cCr�)	z�
        L{server.DNSServerFactory.messageReceived} logs the repr of all queries
        in the message if C{verbose} is set to C{2}.
        r�r��rtzT<Query example.com MX IN> <Query example.com AAAA IN> query from ('192.0.2.100', 53)Nr�r�r�r�rrr�test_messageReceivedLogging2�s
�
�z2DNSServerFactoryTests.test_messageReceivedLogging2csNt��}t�}t��|�tjd�fdd��|j|ddd�|�|j	��dS)zv
        L{server.DNSServerFactory.messageReceived} assigns a unix timestamp to
        the received message.
        �timec��Srrr��trr�<lambda>�r$zEDNSServerFactoryTests.test_messageReceivedTimestamp.<locals>.<lambda>Nr�)
rr�rrV�patchrr�r�rB�timeReceivedr�rr�r�test_messageReceivedTimestamp�sz3DNSServerFactoryTests.test_messageReceivedTimestampcCs^t��}t�}t�}t�}|jtj|j|||d�}|j\}}|�||||f�|�|i�dS)z�
        L{server.DNSServerFactory.messageReceived} passes all messages to
        L{server.DNSServerFactory.allowQuery} along with the receiving protocol
        and origin address.
        r�N)	rr�rVr&�assertRaisesr*r�rrB)rr�
dummyProtocol�dummyAddressr��errrrr�test_messageReceivedAllowQuery�s�
z4DNSServerFactoryTests.test_messageReceivedAllowQuerycsjGdd�dt��G�fdd�dtj�}|�}|j�|jt��ddd�}|j\\}}}}|�|j	tj
�dS)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@ra)zFDNSServerFactoryTests.test_allowQueryFalse.<locals>.SendReplyExceptionNrbrrrr�SendReplyException�rdr�cs eZdZdd�Z�fdd�ZdS)zKDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactoryc_r)NFrrrrrr"��zVDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactory.allowQuerycs
�||��rrr�r�rrr#�s
zUDNSServerFactoryTests.test_allowQueryFalse.<locals>.RaisingDNSServerFactory.sendReplyN)rrrr"r#rr�rrr&�sr&Nr�)r-rrJr�r�rr�rrB�rCode�EREFUSED)rr&r�r�r�rr!rrr�r�test_allowQueryFalse�s�z*DNSServerFactoryTests.test_allowQueryFalsecsXdg|_g��fdd�}t�}t�d�}t|||�|�||�|��||dfg�dS)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}
        Ncs��|||f�dSr�r?�rr r!��receivedMessagesrr�fakeHandlersz?DNSServerFactoryTests._messageReceivedTest.<locals>.fakeHandler)�queriesr4rrJ�setattrr�rB)r�
methodNamerr�r r|rr�r�_messageReceivedTests
z*DNSServerFactoryTests._messageReceivedTestcC�|�dtjtjd��dS)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_QUERY} on to L{DNSServerFactory.handleQuery}.
        �handleQuery��opCodeN)r�rr��OP_QUERYrMrrr�test_queryMessageReceived�z/DNSServerFactoryTests.test_queryMessageReceivedcCr�)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_INVERSE} on to L{DNSServerFactory.handleInverseQuery}.
        �handleInverseQueryr�N)r�rr��
OP_INVERSErMrrr� test_inverseQueryMessageReceived&s�z6DNSServerFactoryTests.test_inverseQueryMessageReceivedcCr�)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_STATUS} on to L{DNSServerFactory.handleStatus}.
        �handleStatusr�N)r�rr��	OP_STATUSrMrrr�test_statusMessageReceived/r�z0DNSServerFactoryTests.test_statusMessageReceivedcCr�)z�
        L{DNSServerFactory.messageReceived} passes messages with an opcode of
        C{OP_NOTIFY} on to L{DNSServerFactory.handleNotify}.
        �handleNotifyr�N)r�rr��	OP_NOTIFYrMrrr�test_notifyMessageReceived6r�z0DNSServerFactoryTests.test_notifyMessageReceivedcCr�)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�rr��	OP_UPDATErMrrr�test_updateMessageReceived=sz0DNSServerFactoryTests.test_updateMessageReceivedcCs�t�t�}}t��}|�|�|�|j|g�|�|�|�|j||g�|�|�|�|j|g�|�|�|�|jg�dS)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)rVrrJ�connectionMaderB�connections�connectionLost)r�protoA�protoBr|rrr�test_connectionTrackingFs



z-DNSServerFactoryTests.test_connectionTrackingcCsht��}|�d�|�d�t��}t�|_|jtj|j	|t
�dd�}|j\\}}|�||j
d�dS)z�
        L{server.DNSServerFactory.handleQuery} takes the first query from the
        supplied message and dispatches it to
        L{server.DNSServerFactory.resolver.query}.
        �one.example.comstwo.example.comNr�r)rr�r�rrJr5rKr�r6r�r4rrBr�)rr<r�r�r7rrrr�test_handleQueryWs

�z&DNSServerFactoryTests.test_handleQuerycs�t��}t���G�fdd�d�}|�|_g��fdd�}||_t��}|�d�t	�}t
�}|j|||d�t
�}��|�|�
�||||fifg�dS)aC
        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�eZdZ�fdd�ZdS)zDDNSServerFactoryTests.test_handleQueryCallback.<locals>.FakeResolvercr�rrr��drrr7zr�zJDNSServerFactoryTests.test_handleQueryCallback.<locals>.FakeResolver.queryN�rrrr7rr�rr�FakeResolvery�r�c���||f�dSrr�r)�gotResolverResponseArgsrr�fakeGotResolverResponse��zODNSServerFactoryTests.test_handleQueryCallback.<locals>.fakeGotResolverResponser�r�N)rrJr�DeferredrK�gotResolverResponserr�r�r4rVr��callbackrB)rr�r�r�r<rr��
dummyResponser)r�r�r�test_handleQueryCallbackms$

�z.DNSServerFactoryTests.test_handleQueryCallbackcs�t��}t���G�fdd�d�}|�|_g��fdd�}||_t��}|�d�t	�}t
�}|j|||d�t�
t��}��|�|��||||fifg�dS)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.
        cr�)zCDNSServerFactoryTests.test_handleQueryErrback.<locals>.FakeResolvercr�rrrr�rrr7�r�zIDNSServerFactoryTests.test_handleQueryErrback.<locals>.FakeResolver.queryNr�rr�rrr��r�r�cr�rr�r)�gotResolverErrorArgsrr�fakeGotResolverError�r�zKDNSServerFactoryTests.test_handleQueryErrback.<locals>.fakeGotResolverErrorr�r�N)rrJrr�rK�gotResolverErrorrr�r�r4rVr�r	�Failurer-�errbackrB)rr�r�r�r<rr��stubFailurer)r�r�r�test_handleQueryErrback�s"

�z-DNSServerFactoryTests.test_handleQueryErrbackcCstt��}g}g}g}|jtj|j|||ft�t��dd�}|j\\}}|�	|j
|�|�	|j|�|�	|j|�dS)z�
        L{server.DNSServerFactory.gotResolverResponse} accepts a tuple of
        resource record lists and triggers a response message containing those
        resource record lists.
        N�r rr!)
rrJr�r.r/r�rr�rry�answers�	authority�
additional)rr�r�r�r�r�rrrrr�test_gotResolverResponse�s �z.DNSServerFactoryTests.test_gotResolverResponsec
Csdt�}t|_t��}d|_|jt|jgggfd|dd�}|�	dt
|tjgggd�f|j|j
f�dS)z�
        L{server.DNSServerFactory.gotResolverResponse} calls
        L{server.DNSServerFactory._responseFromMessage} to generate a response.
        r�Nr�r)rr�r�r�r�)rr�_responseFromMessagerr�r�r�r
r�rB�dict�OKrr�rr|�requestr�rrr�0test_gotResolverResponseCallsResponseFromMessage�s0���

�zFDNSServerFactoryTests.test_gotResolverResponseCallsResponseFromMessagecCs4t��}tjddd�}|j|d�f}|�||�dS)z�
        L{server.DNSServerFactory._responseFromMessage} generates a response
        message which is a copy of the request message.
        F)�answer�recAv�rN)rrJrr�r��assertIsNot�rr|r��responserrr�"test_responseFromMessageNewMessage�sz8DNSServerFactoryTests.test_responseFromMessageNewMessagecCsTt��}d|_|jtjdd�d�}d|_|jtjdd�d�}|�d|j|jf�dS)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)r�r��TFN)rrJror�rr�rBr��rr|�	response1�	response2rrr�*test_responseFromMessageRecursionAvailablesz@DNSServerFactoryTests.test_responseFromMessageRecursionAvailablecC�6t��}t��}d|_|j|d�}|�|j|j�dS)z�
        L{server.DNSServerFactory._responseFromMessage} generates a response
        message whose C{timeReceived} attribute has the same value as that found
        on the request.
        i�r�N)rrJrr�r�r�rBr�rrr�$test_responseFromMessageTimeReceived
�
z:DNSServerFactoryTests.test_responseFromMessageTimeReceivedcCr)z�
        L{server.DNSServerFactory._responseFromMessage} generates a response
        message whose C{maxSize} attribute has the same value as that found
        on the request.
        rr�N)rrJrr��maxSizer�rBr�rrr�test_responseFromMessageMaxSizerz5DNSServerFactoryTests.test_responseFromMessageMaxSizecCs|�tjtjj�dS)z{
        L{server.DNSServerFactory} has a C{_messageFactory} attribute which is
        L{dns.Message} by default.
        N)ryrr�rrJ�_messageFactoryrMrrr�test_messageFactory'�z)DNSServerFactoryTests.test_messageFactoryc
Csdt��}|�tdt�t��}|jt|j|tj	d�}|�
dt|j|tj	|j
dd�f|j|jf�dS)a4
        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.
        r��rr�rF)�responseConstructorrr�r��authN)rrJr�rrr�r�r
r�r�rBr�r
rorrr�rrr�+test_responseFromMessageCallsMessageFactory.s$���

�zADNSServerFactoryTests.test_responseFromMessageCallsMessageFactorycCsXt��}|jt��tjdd�gd�}|jt��tjdd�gd�}|�d|j|jf�dS)z�
        L{server.DNSServerFactory._responseFromMessage} marks the response
        message as authoritative if any of the answer records are authoritative.
        T)r)rr�FrN)rrJr�rr��RRHeaderrBrrrrr�,test_responseFromMessageAuthoritativeMessageKs��
�zBDNSServerFactoryTests.test_responseFromMessageAuthoritativeMessagec	CsRtdd�}t��g}t��g}t��g}t|dg|j|||ft�t��dd�dS)z�
        L{server.DNSServerFactory.gotResolverResponse} logs the total number of
        records in the response if C{verbose > 0}.
        r�rtzLookup found 3 recordsNr�)rrrrGr�r4r�)rr�r�r�r�rrr�test_gotResolverResponseLogging\s




�z5DNSServerFactoryTests.test_gotResolverResponseLoggingcCs�tt�gd�}t��}|�d�t��g}g}g}|jtj|j|||ft	�|dd�}|j
\\}\}}	}
}|�|jjd�|�
||�|�
|	|�|�
|
|�dS)z�
        L{server.DNSServerFactory.gotResolverResponse} caches the response if at
        least one cache was provided in the constructor.
        r[sexample.comNr�)rr8rr�r�rr�r9r�r4rrBr�ry)rr�r<�expectedAnswers�expectedAuthority�expectedAdditionalr�r7r�r�r�rrrr�test_gotResolverResponseCachingps&

�z5DNSServerFactoryTests.test_gotResolverResponseCachingcCsbt�}t|_t��}d|_|jt|jt	�
t���d|dd�}|�
dt|tjd�f|j|jf�dS)z�
        L{server.DNSServerFactory.gotResolverError} calls
        L{server.DNSServerFactory._responseFromMessage} to generate a response.
        r�Nr�rr
)rrr�rr�r�r�r
r�r	r�r�DomainErrorrBr��ENAMErrr�rrr�-test_gotResolverErrorCallsResponseFromMessage�s��zCDNSServerFactoryTests.test_gotResolverErrorCallsResponseFromMessagecCsLt��}|jtj|jt�|�t�t�	�dd�}|j
\\}}|�|j|�dS)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�)
rrJr�r.r/r�r	r�rr�rrBr�)r�
responseError�expectedMessageCoder�r�rrrrr�_assertMessageRcodeForError�s�z1DNSServerFactoryTests._assertMessageRcodeForErrorcC�|�t��tj�dS)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)rrrrrrMrrr� test_gotResolverErrorDomainError�rz6DNSServerFactoryTests.test_gotResolverErrorDomainErrorcCr)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)rr�AuthoritativeDomainErrorrrrMrrr�-test_gotResolverErrorAuthoritativeDomainError�szCDNSServerFactoryTests.test_gotResolverErrorAuthoritativeDomainErrorcCs.|�t�tj�|�t�}|�t|�d�dS)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.
        r�N)r�KeyErrorr�ESERVER�flushLoggedErrorsrB�len)rr�rrr�test_gotResolverErrorOtherError�s
z5DNSServerFactoryTests.test_gotResolverErrorOtherErrorc	Cs8tdd�}t|dg|jt�t���t�t�	�dd�dS)zZ
        L{server.DNSServerFactory.gotResolver} logs a message if C{verbose > 0}.
        r�rtz
Lookup failedNr�)
rrGr�r	r�rrr4rr�r�rrr�test_gotResolverErrorLogging�s

�z2DNSServerFactoryTests.test_gotResolverErrorLoggingcs�t��}g��fdd�|_tjddd�}t�t�g|_t�t�g|_t�t�g|_|j	t
�t�
��d|dd�|�tjddd�g��dS)	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�
��|�Srr��r r�r!��	responsesrrr����zUDNSServerFactoryTests.test_gotResolverErrorResetsResponseAttributes.<locals>.<lambda>T��
authenticData�checkingDisabledNr���r�r�)rrJr#rr�rVr�r�r�r�r	r�rrrB�rr|r�rr*r�-test_gotResolverErrorResetsResponseAttributes�s�zCDNSServerFactoryTests.test_gotResolverErrorResetsResponseAttributescs�t��}g��fdd�|_tjddd�}t�t�g|_t�t�g|_t�t�g|_|j	gggfd|dd�|�
tjddd�g��dS)	a
        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.
        cr(rr�r)r*rrr�	r,zXDNSServerFactoryTests.test_gotResolverResponseResetsResponseAttributes.<locals>.<lambda>Tr-Nr�rr1)rrJr#rr�rVr�r�r�r�rBr2rr*r�0test_gotResolverResponseResetsResponseAttributess�zFDNSServerFactoryTests.test_gotResolverResponseResetsResponseAttributescCsZt��}t�}t��}|jtj|jt�||d�}|j	\}}|�
|||f�|�
|i�dS)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)rr�rVrrJr�r.r/r#rrB)rr<r�r�r�rrrrr�test_sendReplyWithAddresss�
z/DNSServerFactoryTests.test_sendReplyWithAddresscCsRt��}t��}|jtj|jt�|dd�}|j\}}|�	||f�|�	|i�dS)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�)
rr�rrJr�r.r/r#rrB)rr<r�r�rrrrr�test_sendReplyWithoutAddress+s�
z2DNSServerFactoryTests.test_sendReplyWithoutAddresscCsN|�tjddd��t��}d|_tjdd�}t|ddg|jt	�|d	d
�d	S)z�
        If L{server.DNSServerFactory.sendReply} logs a "no answers" message if
        the supplied message has no answers.
        r�cSr�Ni�Qrrrrrr�Cr$zFDNSServerFactoryTests.test_sendReplyLoggingNoAnswers.<locals>.<lambda>�Qr�rtzReplying with no answers� Processed query in 1.000 secondsNr�)
r�rr�rr�r�rJrGr#r4r�rrr�test_sendReplyLoggingNoAnswers>s
�z4DNSServerFactoryTests.test_sendReplyLoggingNoAnswerscCs�|�tjddd��t��}|j�tjt�d�d��|j	�tjt�d�d��|j
�tjt�d�d��d|_tjdd�}t
|gd	�|jt�|d
d�d
S)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�cSrr7rrrrrr�Vr$zHDNSServerFactoryTests.test_sendReplyLoggingWithAnswers.<locals>.<lambda>z	127.0.0.1)�payloadr8r�rt)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>r9Nr�)r�rr�rr�r�r?r�Record_Ar�r�r�rJrGr#r4r�rrr� test_sendReplyLoggingWithAnswersPs
�z6DNSServerFactoryTests.test_sendReplyLoggingWithAnswerscC�Ft��}|jtj|jt��t�dd�}|j\\}}|�	|j
tj�dS)z�
        L{server.DNSServerFactory.handleInverseQuery} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr�)rrJr�r.r/r�rr�rrBr��ENOTIMP�rr�r�rrrrr�test_handleInverseQueryk��z-DNSServerFactoryTests.test_handleInverseQuerycC�,tdd�}t|dg|jt��t�dd�dS)zz
        L{server.DNSServerFactory.handleInverseQuery} logs the message origin
        address if C{verbose > 0}.
        r�rtzInverse query from ('::1', 53)�z::1r�r�N)rrGr�rr�r4r�rrr�test_handleInverseQueryLogging|�

�z4DNSServerFactoryTests.test_handleInverseQueryLoggingcCr>)z�
        L{server.DNSServerFactory.handleStatus} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr�)rrJr�r.r/r�rr�rrBr�r?r@rrr�test_handleStatus�rBz'DNSServerFactoryTests.test_handleStatuscCrC)zt
        L{server.DNSServerFactory.handleStatus} logs the message origin address
        if C{verbose > 0}.
        r�rtzStatus request from ('::1', 53)rDr�N)rrGr�rr�r4r�rrr�test_handleStatusLogging�rFz.DNSServerFactoryTests.test_handleStatusLoggingcCr>)z�
        L{server.DNSServerFactory.handleNotify} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr�)rrJr�r.r/r�rr�rrBr�r?r@rrr�test_handleNotify�rBz'DNSServerFactoryTests.test_handleNotifycCrC)zt
        L{server.DNSServerFactory.handleNotify} logs the message origin address
        if C{verbose > 0}.
        r�rtzNotify message from ('::1', 53)rDr�N)rrGr�rr�r4r�rrr�test_handleNotifyLogging�rFz.DNSServerFactoryTests.test_handleNotifyLoggingcCr>)z�
        L{server.DNSServerFactory.handleOther} triggers the sending of a
        response message with C{rCode} set to L{dns.ENOTIMP}.
        Nr�)rrJr�r.r/r�rr�rrBr�r?r@rrr�test_handleOther�rBz&DNSServerFactoryTests.test_handleOthercCrC)zs
        L{server.DNSServerFactory.handleOther} logs the message origin address
        if C{verbose > 0}.
        r�rtz$Unknown op code (0) from ('::1', 53)rDr�N)rrGr�rr�r4r�rrr�test_handleOtherLogging�rFz-DNSServerFactoryTests.test_handleOtherLoggingN)DrrrrrNrRrYr]r`rgrkrmrprqrsrvrwr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr	rrrrrrrrr!r&r'r3r4r5r6r:r=rArErGrHrIrJrKrLrrrrrH�s�
		('!



rHN)r�zope.interface.verifyr�twisted.internetr�twisted.internet.interfacesr�
twisted.namesrrrr�twisted.pythonr	r
�
twisted.trialrr-r
rrJrr&r.r4r5r8rG�TestCaserHrrrr�<module>s"
	! 

Anon7 - 2022
AnonSec Team