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_dns.cpython-310.pyc
o

�b�s�@sdZddlZddlmZddlmZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZejejejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4gZ5Gdd�dej6�Z7Gdd�dej8�Z9Gdd�dej8�Z:Gdd�dej8�Z;Gdd�dej8�Z<dZ=dZ>Gdd�dej6�Z?Gdd�deej6�Z@Gdd�d�ZAGd d!�d!ej8�ZBGd"d#�d#eA�ZCGd$d%�d%ej8�ZDGd&d'�d'ej8�ZEGd(d)�d)eej8�ZFGd*d+�d+ej8�ZGGd,d-�d-ej6�ZHd.d/�ZId0d1�ZJGd2d3�d3ej6�ZKGd4d5�d5�ZLGd6d7�d7eej8�ZMGd8d9�d9eej8�ZNGd:d;�d;eO�ZPGd<d=�d=�ZQGd>d?�d?�ZRGd@dA�dA�ZSGdBdC�dC�ZTGdDdE�dE�ZUGdFdG�dG�ZVGdHdI�dI�ZWGdJdK�dK�ZXGdLdM�dMee�ZY	djdNdO�ZZGdPdQ�dQ�Z[GdRdS�dS�Z\GdTdU�dUe[e\ej6�Z]GdVdW�dWe[e\ej6�Z^GdXdY�dYe[ej6�Z_GdZd[�d[eej6�Z`Gd\d]�d]�ZaGd^d_�d_eaej6�ZbGd`da�daeaej6�ZcGdbdc�dcej6�ZdGddde�deej6�ZeGdfdg�dg�ZfGdhdi�diej6�ZgdS)kz
Tests for twisted.names.dns.
�N)�BytesIO)�cast)�verifyClass)�address�task)�CannotListenError�ConnectionDone)�dns)�Failure)�FancyEqMixin�
FancyStrMixin)�
proto_helpers)�ComparisonTestsMixin)�unittestc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�DomainStringTestscCs|�dt�d��dS)zA
        L{dns.domainString} returns L{bytes} unchanged.
        stwistedmatrix.comN��assertEqualr	�domainString��self�r�=/usr/lib/python3/dist-packages/twisted/names/test/test_dns.py�
test_bytes8s�zDomainStringTests.test_bytescC�|�dt�d��dS)z`
        L{dns.domainString} converts a native string to L{bytes}
        if necessary.
        �example.com�example.comNrrrrr�test_nativeA�zDomainStringTests.test_nativecCr)zS
        L{dns.domainString} always converts a unicode string to L{bytes}.
        sfoo.examplezfoo.exampleNrrrrr�	test_textH�zDomainStringTests.test_textcCr)�A
        L{dns.domainString} encodes Unicode using IDNA.
        sxn--fwg.testu‽.testNrrrrr�	test_idnaNrzDomainStringTests.test_idnacCs*|�ttjd�|�ttjt�d��dS)r i(#zbar.exampleN)�assertRaises�	TypeErrorr	r�Namerrrr�
test_nonsenseTszDomainStringTests.test_nonsenseN)�__name__�
__module__�__qualname__rrrr!r%rrrrr7s	rc@�eZdZdZdd�ZdS)�
Ord2ByteTestsz&
    Tests for L{dns._ord2bytes}.
    cCr)z�
        L{dns._ord2byte} accepts an integer and returns a byte string of length
        one with an ordinal value equal to the given integer.
        ��N)rr	�
_ord2bytesrrrr�
test_ord2bytearzOrd2ByteTests.test_ord2byteN)r&r'r(�__doc__r.rrrrr*\�r*c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�
Str2TimeTestsz$
    Tests for L{dns.str2name}.
    cCst�}|�|t�|��dS)zY
        When passed a non-string object, L{dns.str2name} returns it unmodified.
        N)�object�assertIsr	�str2time)r�timerrr�test_nonStringnszStr2TimeTests.test_nonStringcCr)z�
        Passed a string giving a number of seconds, L{dns.str2time} returns the
        number of seconds represented.  For example, C{"10S"} represents C{10}
        seconds.
        �
�10SN�rr	r4rrrr�test_secondsu�zStr2TimeTests.test_secondscCr)z�
        Like C{test_seconds}, but for the C{"M"} suffix which multiplies the
        time value by C{60} (the number of seconds in a minute!).
        �x�2MNr9rrrr�test_minutes}rzStr2TimeTests.test_minutescCr)z�
        Like C{test_seconds}, but for the C{"H"} suffix which multiplies the
        time value by C{3600}, the number of seconds in an hour.
        i0*�3HNr9rrrr�
test_hours�rzStr2TimeTests.test_hourscCr)z�
        Like L{test_seconds}, but for the C{"D"} suffix which multiplies the
        time value by C{86400}, the number of seconds in a day.
        iF�4DNr9rrrr�	test_days�rzStr2TimeTests.test_dayscCr)z�
        Like L{test_seconds}, but for the C{"W"} suffix which multiplies the
        time value by C{604800}, the number of seconds in a week.
        i�$.�5WNr9rrrr�
test_weeks�rzStr2TimeTests.test_weekscCr)z�
        Like L{test_seconds}, but for the C{"Y"} suffix which multiplies the
        time value by C{31536000}, the number of seconds in a year.
        i5G�6YNr9rrrr�
test_years�rzStr2TimeTests.test_yearscCs|�ttjd�dS)zY
        If a non-integer prefix is given, L{dns.str2time} raises L{ValueError}.
        �fooSN)r"�
ValueErrorr	r4rrrr�test_invalidPrefix��z Str2TimeTests.test_invalidPrefixN)r&r'r(r/r6r:r>r@rBrDrFrIrrrrr1isr1c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�	NameTestsz�
    Tests for L{Name}, the representation of a single domain name with support
    for encoding into and decoding from DNS message format.
    cCs6|�ttjd�|�ttjt��|�ttjg�dS)zy
        When constructed with a name which is neither C{bytes} nor C{str},
        L{Name} raises L{TypeError}.
        �{N)r"r#r	r$r2rrrr�test_nonStringName�szNameTests.test_nonStringNamecCs*t�d�}|�|jt�|�d|j�dS)zg
        L{dns.Name} automatically encodes unicode domain name using C{idna}
        encoding.
        uéchec.example.orgsxn--chec-9oa.example.orgN)r	r$�assertIsInstance�name�bytesr)rrOrrr�test_unicodeName�s
zNameTests.test_unicodeNamecCs(t��}|�td��|�|jd�dS)z�
        L{Name.decode} populates the L{Name} instance with name information read
        from the file-like object passed to it.
        �
examplecomrN)r	r$�decoderrrO)r�nrrr�test_decode�szNameTests.test_decodecCs.t�d�}t�}|�|�|�|��d�dS)zy
        L{Name.encode} encodes its name information and writes it to the
        file-like object passed to it.
        �foo.example.comsfooexamplecomN)r	r$r�encoder�getvalue�rrO�streamrrr�test_encode�s

zNameTests.test_encodecCstt�d�}ddi}d}t�}|�|�t|�tjj}|�||�|�d|�	�t|�d��|�d|d�|�dS)am
        If a compression dictionary is passed to it, L{Name.encode} uses offset
        information from it to encode its name with references to existing
        labels in the stream instead of including another copy of them in the
        output.  It also updates the compression dictionary with the location of
        the name it writes to the stream.
        rVr�ssome prefix to change .tell()sfoo�N)rrV)
r	r$r�write�len�Message�
headerSizerWrrX)rrO�compression�previousrZ�expectedrrr�test_encodeWithCompression�s


�z$NameTests.test_encodeWithCompressioncCs�d}t��}|�|�|�|jtjdddd�g�|�|jtjddddtjddd�d	�g�|�|j	tjd
tj
tjdtjddd�d	�g�|�
�}|�||�dS)
z�
        A resource record of unknown type and class is parsed into an
        L{UnknownRecord} instance with its data preserved, and an
        L{UnknownRecord} instance is serialized to a string equal to the one it
        was parsed from.
        sDfoobarޭ��ޭ��somedatabazban�foo.bari��i�)�type�clsissomedata��ttl�rfrgri�payloadsbaz.ban�1.2.3.4N)r	r_�fromStrr�queries�Query�answers�RRHeader�
UnknownRecord�
additional�A�IN�Record_A�toStr)r�wire�msg�encrrr�test_unknown�sB�
��������
zNameTests.test_unknowncCs�td�}|�d�t��}|�|�|�d|j�|�d|���|�|�|�|jd�|�d|���|�|�|�|jd�|�d|���d	S)
a
        If the leading byte of an encoded label (in bytes read from a stream
        passed to L{Name.decode}) has its two high bits set, the next byte is
        treated as a pointer to another label in the stream and that label is
        included in the name being decoded.
        s,xxxxxxxxxxxxxxxxxxxxfisiarpafoo�bar� �s
f.isi.arpa� sfoo.f.isi.arpa�&sbar.foo.f.isi.arpa�,N)r�seekr	r$rSrrO�tell)rrZrOrrr�test_decodeWithCompression5s�



z$NameTests.test_decodeWithCompressioncCs$t��}td�}|�t|j|�dS)z�
        L{Name.decode} raises L{ValueError} if the stream passed to it includes
        a compression pointer which forms a loop, causing the name to be
        undecodable.
        s�N)r	r$rr"rHrSrYrrr�test_rejectCompressionLoopTsz$NameTests.test_rejectCompressionLoopcCs:t�d�}t�d�}|�||�t�d�}|�||�dS)z�
        L{Name} instances are equal as long as they have the same value for
        L{Name.name}, regardless of the case.
        resfOO.barN)r	r$r)r�name1�name2�name3rrr�
test_equality^s



zNameTests.test_equalitycCs$t�d�}t�d�}|�||�dS)zq
        L{Name} instances are not equal as long as they have different
        L{Name.name} attributes.
        resbar.fooN)r	r$�assertNotEqual)rr�r�rrr�test_inequalityjs

zNameTests.test_inequalityN)r&r'r(r/rMrQrUr[rdr{r�r�r�r�rrrrrK�s			
J
rKc@s�eZdZdZgd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5S)6�RoundtripDNSTestsz5
    Encoding and then decoding various objects.
    )�example.orgsgo-away.fish.tvs23strikesback.netcCsR|jD]#}t�}t�|��|�|�dd�t��}|�|�|�|j|�qdS)Nr)	�namesrr	r$rWr�rSrrO�rrT�f�resultrrr�	test_name{s

�zRoundtripDNSTests.test_namecCs�|jD]D}tdd�D]<}tdd�D]4}t�}t�|||��|�|�dd�t��}|�|�|�|j	j	|�|�|j
|�|�|j|�qq
qdS)z�
        L{dns.Query.encode} returns a byte string representing the fields of the
        query which can be decoded into a new L{dns.Query} instance using
        L{dns.Query.decode}.
        ���rN)r��rangerr	rorWr�rSrrOrfrg)rrT�dnstype�dnsclsr�r�rrr�
test_query�s

���zRoundtripDNSTests.test_querycCs|t�}t�dddd��|�|�dd�t��}|�|�|�|jt�d��|�|j	d�|�|j
d�|�|jd�dS)a
        L{dns.RRHeader.encode} encodes the record header's information and
        writes it to the file-like object passed to it and
        L{dns.RRHeader.decode} reads from a file-like object to re-construct a
        L{dns.RRHeader} instance.
        stest.org��r�rN)rr	rqrWr�rSrrOr$rfrgri)rr�r�rrr�test_resourceRecordHeader�s
z+RoundtripDNSTests.test_resourceRecordHeadercCsF|�td��tjtjt��d�Wd�dS1swYdS)zy
        L{RRHeader()} raises L{ValueError} when the given type and the type
        of the payload don't match.
        z#Payload type \(AAAA\) .* type \(A\)�rfrkN)�assertRaisesRegexrHr	rqrt�Record_AAAArrrr�%test_resourceRecordHeaderTypeMismatch�s"�z7RoundtripDNSTests.test_resourceRecordHeaderTypeMismatchcCsZd}|D]&}t�}t�|��|�|�dd�t��}|�|�|�|jt�|��qdS)a

        L{dns.SimpleRecord.encode} encodes the record's name information and
        writes it to the file-like object passed to it and
        L{dns.SimpleRecord.decode} reads from a file-like object to re-construct
        a L{dns.SimpleRecord} instance.
        )sthis.are.test.names0will.compress.will.this.will.name.will.hopefullystest.CASE.preSErVatIOn.YeAHsa.s.h.o.r.t.c.a.s.e.t.o.t.e.s.ts	singletonrN)	rr	�SimpleRecordrWr�rSrrOr$)rr��sr�r�rrr�test_resources�s
�z RoundtripDNSTests.test_resourcescCsLtD]!}|�|�}}t|�}t|�}|�|||�d|�d|�d��qdS)z=
        Instances of all record types are hashable.
        z != z (for �)N)�RECORD_TYPES�hashr)r�k�k1�k2�hk1�hk2rrr�
test_hashable�s"�zRoundtripDNSTests.test_hashablecCsR|jD]#}t�}t�|��|�|�dd�t��}|�|�|�|j|�qdS)z8
        Test L{dns.Charstr} encode and decode.
        rN)	r�rr	�CharstrrWr�rSr�stringr�rrr�test_Charstr�s

�zRoundtripDNSTests.test_CharstrcCsHt�}|�|�|��}|�dd�|��}|�||�|�||�dS)z�
        Assert that encoding C{record} and then decoding the resulting bytes
        creates a record which compares equal to C{record}.

        @type record: L{dns.IEncodable}
        @param record: A record instance to encode
        rN)rrWr�r��	__class__rSr)r�recordrZ�length�replicarrr�_recordRoundtripTest�s
z&RoundtripDNSTests._recordRoundtripTestcCs$t�}|�|�|�|��|�dS)a3
        Assert that encoding C{record} produces the expected bytes.

        @type record: L{dns.IEncodable}
        @param record: A record instance to encode

        @type expectedEncoding: L{bytes}
        @param expectedEncoding: The value which C{record.encode()}
            should produce.
        N)rrWrrX)r�expectedEncodingr�rZrrr�assertEncodedFormat�s
z%RoundtripDNSTests.assertEncodedFormatcCs"|�tjdddddddd��d	S)
z�
        The byte stream written by L{dns.Record_SOA.encode} can be used by
        L{dns.Record_SOA.decode} to reconstruct the state of the original
        L{dns.Record_SOA} instance.
        �foo�bar��"�8�N�Z)�mname�rname�serial�refresh�retry�expire�minimumN)r�r	�
Record_SOArrrr�test_SOA	s��zRoundtripDNSTests.test_SOAcC�|�t�d��dS)z�
        The byte stream written by L{dns.Record_A.encode} can be used by
        L{dns.Record_A.decode} to reconstruct the state of the original
        L{dns.Record_A} instance.
        rlN)r�r	rvrrrr�test_A�zRoundtripDNSTests.test_AcCr�)z�
        The byte stream written by L{dns.Record_NULL.encode} can be used by
        L{dns.Record_NULL.decode} to reconstruct the state of the original
        L{dns.Record_NULL} instance.
        sfoo barN)r�r	�Record_NULLrrrr�	test_NULL#r�zRoundtripDNSTests.test_NULLcC�|�t�ddd��dS)z�
        The byte stream written by L{dns.Record_WKS.encode} can be used by
        L{dns.Record_WKS.decode} to reconstruct the state of the original
        L{dns.Record_WKS} instance.
        rlr�sxyzN)r�r	�
Record_WKSrrrr�test_WKS+�zRoundtripDNSTests.test_WKScCr�)z�
        The byte stream written by L{dns.Record_AAAA.encode} can be used by
        L{dns.Record_AAAA.decode} to reconstruct the state of the original
        L{dns.Record_AAAA} instance.
        z::1N)r�r	r�rrrr�	test_AAAA3r�zRoundtripDNSTests.test_AAAAcCr�)z�
        The byte stream written by L{dns.Record_A6.encode} can be used by
        L{dns.Record_A6.decode} to reconstruct the state of the original
        L{dns.Record_A6} instance.
        �z::1:2r�N)r�r	�	Record_A6rrrr�test_A6;r�zRoundtripDNSTests.test_A6cCs|�tjddddd��dS)z�
        The byte stream written by L{dns.Record_SRV.encode} can be used by
        L{dns.Record_SRV.decode} to reconstruct the state of the original
        L{dns.Record_SRV} instance.
        r��r�r)�priority�weight�port�targetN)r�r	�
Record_SRVrrrr�test_SRVC��zRoundtripDNSTests.test_SRVcCs:d}tjtjjtjj|d�}|�|�|�d||�dS)z�
        The byte stream written by L{dns.Record_SSHFP.encode} can be used by
        L{dns.Record_SSHFP.decode} to reconstruct the state of the original
        L{dns.Record_SSHFP} instance.
        s�9��^kK
2U��`���	)�	algorithm�fingerprintType�fingerprintsN)r	�Record_SSHFP�
ALGORITHM_DSS�FINGERPRINT_TYPE_SHA1r�r�)r�fp�rrrrr�
test_SSHFPMs��
zRoundtripDNSTests.test_SSHFPc	Cs�ddg}|D]c\}}}}}}t�||||||�}t�}	|�|	�|	�dd�t��}
|
�|	�|�|j|
j�|�|j|
j�|�|j	|
j	�|�|j
|
j
�|�|j|
j�|�|jj
|
jj
�|�|j|
j�qdS)z=
        Test L{dns.Record_NAPTR} encode and decode.
        )�dr7�u�sip+E2Us!!^.*$!sip:information@domain.tld!�)r��2�sshttp+I2L+I2C+I2Rr�s_http._tcp.gatech.edurN)r	�Record_NAPTRrrWr�rSr�order�
preference�flags�service�regexp�replacementrOri)r�naptrsr�r�r�r�r�r��rin�e�routrrr�
test_NAPTR`s(��

�zRoundtripDNSTests.test_NAPTRcC�|�tjddd��dS)z�
        The byte stream written by L{dns.Record_AFSDB.encode} can be used by
        L{dns.Record_AFSDB.decode} to reconstruct the state of the original
        L{dns.Record_AFSDB} instance.
        r�r)�subtype�hostnameN)r�r	�Record_AFSDBrrrr�
test_AFSDBzr�zRoundtripDNSTests.test_AFSDBcCr�)z�
        The byte stream written by L{dns.Record_RP.encode} can be used by
        L{dns.Record_RP.decode} to reconstruct the state of the original
        L{dns.Record_RP} instance.
        �alice.example.comr)�mbox�txtN)r�r	�	Record_RPrrrr�test_RP�s�zRoundtripDNSTests.test_RPcCr�)z�
        The byte stream written by L{dns.Record_HINFO.encode} can be used by
        L{dns.Record_HINFO.decode} to reconstruct the state of the original
        L{dns.Record_HINFO} instance.
        sfastsgreat)�cpu�osN)r�r	�Record_HINFOrrrr�
test_HINFO�r�zRoundtripDNSTests.test_HINFOcCr�)z�
        The byte stream written by L{dns.Record_MINFO.encode} can be used by
        L{dns.Record_MINFO.decode} to reconstruct the state of the original
        L{dns.Record_MINFO} instance.
        r�r�)�rmailbx�emailbxN)r�r	�Record_MINFOrrrr�
test_MINFO�r�zRoundtripDNSTests.test_MINFOcCr�)z�
        The byte stream written by L{dns.Record_MX.encode} can be used by
        L{dns.Record_MX.decode} to reconstruct the state of the original
        L{dns.Record_MX} instance.
        r�r)r�rON)r�r	�	Record_MXrrrr�test_MX�r�zRoundtripDNSTests.test_MXcCsxd}tjdddd|d�}|�|�d|d}|�||�tjd	d
dtjd|d
�}|�|�d|d}|�||�dS)z�
        The byte stream written by L{dns.Record_TSIG.encode} can be used by
        L{dns.Record_TSIG.decode} to reconstruct the state of the original
        L{dns.Record_TSIG} instance.
        s !"#0123zhmac-md5.sig-alg.reg.int�/qUZ�*r�)r��
timeSigned�
originalID�fudge�MACs$hmac-md5sig-algregintZUq/s*zhmac-sha256l'��s�)r�rr�error�	otherDatarshmac-sha256�'s���N)r	�Record_TSIGr�r��EBADTIME)r�macr��rdatarrr�	test_TSIG�s@�
����
���zRoundtripDNSTests.test_TSIGcCs|�t�dd��dS)z�
        The byte stream written by L{dns.Record_TXT.encode} can be used by
        L{dns.Record_TXT.decode} to reconstruct the state of the original
        L{dns.Record_TXT} instance.
        r�r�N)r�r	�
Record_TXTrrrr�test_TXT�r;zRoundtripDNSTests.test_TXTN)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�rrrrrrrrrr�ts8	


)r�s sc@s�eZdZdZdd�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&S)'�MessageTestsz1
    Tests for L{twisted.names.dns.Message}.
    cC�|�t��jd�dS)zC
        L{dns.Message.authenticData} has default value 0.
        rN�rr	r_�
authenticDatarrrr�test_authenticDataDefault�rz&MessageTests.test_authenticDataDefaultcC�|�tjdd�jd�dS)z�
        L{dns.Message.__init__} accepts a C{authenticData} argument which
        is assigned to L{dns.Message.authenticData}.
        r��rNrrrrr�test_authenticDataOverride��z'MessageTests.test_authenticDataOverridecC�|�tjdd���t�dS)zr
        L{dns.Message.toStr} encodes L{dns.Message.authenticData} into
        byte4 of the byte string.
        r�rN)rr	r_rw�MESSAGE_AUTHENTIC_DATA_BYTESrrrr�test_authenticDataEncode���z%MessageTests.test_authenticDataEncodecC�$t��}|�t�|�|jd�dS)zp
        L{dns.Message.fromStr} decodes byte4 and assigns bit3 to
        L{dns.Message.authenticData}.
        r�N)r	r_rmr#rr�r�mrrr�test_authenticDataDecode�
z%MessageTests.test_authenticDataDecodecCr)zF
        L{dns.Message.checkingDisabled} has default value 0.
        rN�rr	r_�checkingDisabledrrrr�test_checkingDisabledDefaultrz)MessageTests.test_checkingDisabledDefaultcCr)z�
        L{dns.Message.__init__} accepts a C{checkingDisabled} argument which
        is assigned to L{dns.Message.checkingDisabled}.
        r��r,Nr+rrrr�test_checkingDisabledOverrider!z*MessageTests.test_checkingDisabledOverridecCr")zu
        L{dns.Message.toStr} encodes L{dns.Message.checkingDisabled} into
        byte4 of the byte string.
        r�r.N)rr	r_rw�MESSAGE_CHECKING_DISABLED_BYTESrrrr�test_checkingDisabledEncoder%z(MessageTests.test_checkingDisabledEncodecCr&)zs
        L{dns.Message.fromStr} decodes byte4 and assigns bit4 to
        L{dns.Message.checkingDisabled}.
        r�N)r	r_rmr0rr,r'rrr�test_checkingDisabledDecode'r*z(MessageTests.test_checkingDisabledDecodecCs|�dtt����dS)z�
        L{dns.Message.__repr__} omits field values and sections which are
        identical to their defaults. The id field value is always shown.
        z<Message id=0>N)r�reprr	r_rrrr�test_reprDefaults1�zMessageTests.test_reprDefaultsc	Cs,tjdddddddd�}|�dt|��dS)zM
        L{dns.Message.__repr__} displays flags if they are L{True}.
        T)�answer�auth�trunc�recDes�recAvrr,zR<Message id=0 flags=answer,auth,trunc,recDes,recAv,authenticData,checkingDisabled>N�r	r_rr3r'rrr�test_reprFlagsIfSet8s�	�z MessageTests.test_reprFlagsIfSetcCs&tjddddd�}|�dt|��dS)zk
        L{dns.Message.__repr__} displays field values if they differ from their
        defaults.
        r7r|��()�id�opCode�rCode�maxSizez-<Message id=10 opCode=20 rCode=30 maxSize=40>Nr;r'rrr�test_reprNonDefautFieldsNs
�z%MessageTests.test_reprNonDefautFieldscCsDt��}gd�|_gd�|_gd�|_gd�|_|�dt|��dS)�e
        L{dns.Message.__repr__} displays sections which differ from their
        defaults.
        �r�r�r��r�r����r��	�r7�r�z^<Message id=0 queries=[1, 2, 3] answers=[4, 5, 6] authority=[7, 8, 9] additional=[10, 11, 12]>N)r	r_rnrp�	authorityrsrr3r'rrr�test_reprNonDefaultSectionsY�



�z(MessageTests.test_reprNonDefaultSectionscCst��}|�t|jd�dS)zy
        Test that a message which has been truncated causes an EOFError to
        be raised when it is parsed.
        r�N)r	r_r"�EOFErrorrm�rryrrr�test_emptyMessagenszMessageTests.test_emptyMessagecCs�t��}|�d�|�|jd�|�|jd�|�|jtj�|�|j	d�|�|j
d�|�|jg�|�|jg�|�|j
g�|�|jg�dS)ze
        Test that bytes representing an empty query message can be decoded
        as such.
        s�z)Message was not supposed to be an answer.z-Message was not supposed to be authoritative.z)Message was not supposed to be truncated.N)r	r_rmrr?�assertFalser6r@�OP_QUERYr7r8rnrprMrsrQrrr�test_emptyQueryvs�
zMessageTests.test_emptyQuerycCs�d�dd�td�D��}t�|�}tjdtj|d�}t��}|j�|�t	�}|�
|�|�dd�t��}|�|�|�
|jdjtj�|�|jdjj|�dS)	z|
        A I{NULL} record with an arbitrary payload can be encoded and decoded as
        part of a L{dns.Message}.
        r�cS�g|]}t�|��qSr�r	r-��.0�irrr�
<listcomp>��z*MessageTests.test_NULL.<locals>.<listcomp>rS�testname�rkrN)�joinr�r	r�rq�NULLr_rp�appendrrWr�rSrNrkr�rrP�recr��msg1r��msg2rrrr��s


zMessageTests.test_NULLcCs|�t���d�tj�dS)z�
        L{Message.lookupRecordType} returns C{dns.UnknownRecord} if it is
        called with an integer which doesn't correspond to any known record
        type.
        i�N)r3r	r_�lookupRecordTyperrrrrr�test_lookupRecordTypeDefault�s	z)MessageTests.test_lookupRecordTypeDefaultcCsft�}tjtjddd�d�}|�|�t��}|�d|���|�|j	|g�|�
|j	dj�dS)z�
        The L{RRHeader} instances created by L{Message} from a non-authoritative
        message are marked as not authoritative.
        rlrrhr_sN)rr	rqrvrWr_rmrXrrprTr7�r�bufr6�messagerrr�test_nonAuthoritativeMessage�s
	��z)MessageTests.test_nonAuthoritativeMessagecCslt�}tjtjddd�d�}|�|�t��}|�d|���d|_|�	|j
|g�|�|j
dj�dS)z�
        The L{RRHeader} instances created by L{Message} from an authoritative
        message are marked as authoritative.
        rlrrhr_sTN)rr	rqrvrWr_rmrXr7rrp�
assertTruerirrr�test_authoritativeMessage�s
	��z&MessageTests.test_authoritativeMessageN)r&r'r(r/rr r$r)r-r/r1r2r4r<rCrNrRrVr�rhrlrnrrrrr�s(	
	
rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�MessageComparisonTestszD
    Tests for the rich comparison of L{dns.Message} instances.
    cOsl|�dg�}|�dg�}|�dg�}|�dg�}tjdi|��}|r%||_|r*||_|r/||_|r4||_|S)a�
        Create a L{dns.Message}.

        The L{dns.Message} constructor doesn't accept C{queries}, C{answers},
        C{authority}, C{additional} arguments, so we extract them from the
        kwargs supplied to this factory function and assign them to the message.

        @param args: Positional arguments.
        @param kwargs: Keyword arguments.
        @return: A L{dns.Message} instance.
        rnrprMrsNr)�popr	r_rnrprMrs)r�args�kwargsrnrprMrsr(rrr�messageFactory�sz%MessageComparisonTests.messageFactorycC�*|�|jdd�|jdd�|jdd��dS)zd
        Two L{dns.Message} instances compare equal if they have the same id
        value.
        r7�r?r|N��"assertNormalEqualityImplementationrsrrrr�test_id�



�zMessageComparisonTests.test_idcCrt)zg
        Two L{dns.Message} instances compare equal if they have the same answer
        flag.
        r��r6rNrvrrrr�test_answerryz"MessageComparisonTests.test_answercCrt)zh
        Two L{dns.Message} instances compare equal if they have the same opCode
        value.
        r7�r@r|Nrvrrrr�test_opCoderyz"MessageComparisonTests.test_opCodecCrt)zg
        Two L{dns.Message} instances compare equal if they have the same recDes
        flag.
        r��r9rNrvrrrr�test_recDes!ryz"MessageComparisonTests.test_recDescCrt)zf
        Two L{dns.Message} instances compare equal if they have the same recAv
        flag.
        r��r:rNrvrrrr�
test_recAv,ryz!MessageComparisonTests.test_recAvcCrt)ze
        Two L{dns.Message} instances compare equal if they have the same auth
        flag.
        r��r7rNrvrrrr�	test_auth7ryz MessageComparisonTests.test_authcCrt)zg
        Two L{dns.Message} instances compare equal if they have the same rCode
        value.
        r7�rAr|Nrvrrrr�
test_rCodeBryz!MessageComparisonTests.test_rCodecCrt)zf
        Two L{dns.Message} instances compare equal if they have the same trunc
        flag.
        r��r8rNrvrrrr�
test_truncMryz!MessageComparisonTests.test_trunccCrt)zi
        Two L{dns.Message} instances compare equal if they have the same
        maxSize value.
        r7�rBr|Nrvrrrr�test_maxSizeXryz#MessageComparisonTests.test_maxSizecCrt)zn
        Two L{dns.Message} instances compare equal if they have the same
        authenticData flag.
        r�rrNrvrrrr�test_authenticDatacryz)MessageComparisonTests.test_authenticDatacCrt)zq
        Two L{dns.Message} instances compare equal if they have the same
        checkingDisabled flag.
        r�r.rNrvrrrr�test_checkingDisablednryz,MessageComparisonTests.test_checkingDisabledcC�B|�|jt�d�gd�|jt�d�gd�|jt�d�gd��dS)zc
        Two L{dns.Message} instances compare equal if they have the same
        queries.
        r�rnr�N�rwrsr	rorrrr�test_queriesy�
�z#MessageComparisonTests.test_queriesc
C�`|�|jtjdt�d�d�gd�|jtjdt�d�d�gd�|jtjdt�d�d�gd��dS)zc
        Two L{dns.Message} instances compare equal if they have the same
        answers.
        rrlr_�rpr��4.3.2.1N�rwrsr	rqrvrrrr�test_answers������z#MessageComparisonTests.test_answersc
C�f|�|jtjdtjt��d�gd�|jtjdtjt��d�gd�|jtjdtjt��d�gd��dS)zm
        Two L{dns.Message} instances compare equal if they have the same
        authority records.
        rr��rMr�N�rwrsr	rq�SOAr�rrrr�test_authority���������z%MessageComparisonTests.test_authorityc
C�`|�|jtjdt�d�d�gd�|jtjdt�d�d�gd�|jtjdt�d�d�gd��dS)zn
        Two L{dns.Message} instances compare equal if they have the same
        additional records.
        rrlr_�rsr�Nr�rrrr�test_additional���������z&MessageComparisonTests.test_additionalN)r&r'r(r/rsrxr{r}rr�r�r�r�r�r�r�r�r�r�r�rrrrro�s$roc@s"eZdZdZdd�Zddd�ZdS)�TestControllerz�
    Pretend to be a DNS query processor for a DNSDatagramProtocol.

    @ivar messages: the list of received messages.
    @type messages: C{list} of (msg, protocol, address)
    cCs
g|_dS)zG
        Initialize the controller: create a list of messages.
        N)�messagesrrrr�__init__�s
zTestController.__init__NcCs|j�|||f�dS)zN
        Save the message so that it can be checked during the tests.
        N)r�rb)rry�proto�addrrrr�messageReceived�rzTestController.messageReceived�N)r&r'r(r/r�r�rrrrr��sr�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�DatagramProtocolTestsz=
    Test various aspects of L{dns.DNSDatagramProtocol}.
    cCsDt��|_t�|_t�|j�|_t�	�}|j�
|�|jj|j_dS)zQ
        Create a L{dns.DNSDatagramProtocol} with a deterministic clock.
        N)r�Clock�clockr��
controllerr	�DNSDatagramProtocolr�r
�FakeDatagramTransport�makeConnection�	callLater)r�	transportrrr�setUp�s
zDatagramProtocolTests.setUpcCs,|j�dt�ddd��|�|jjg�dS)z�
        Test that when a short datagram is received, datagramReceived does
        not raise an exception while processing it.
        r��UDP�	127.0.0.1i90N)r��datagramReceivedr�IPv4Addressrr�r�rrrr�test_truncatedPacket�sz*DatagramProtocolTests.test_truncatedPacketcs��j�dt�d�g�}��t�jj���d�t��}t	t
�jj����|_tjtj
dd�d�g|_�fdd�}|�|��j�|��d�|S)	�6
        Test content received after a query.
        �r�iaSr�r�rl�rr_c���|jdj��d�dS�Nrrl�rrprk�
dottedQuad�r�rrr�cb��z2DatagramProtocolTests.test_simpleQuery.<locals>.cb)r��queryr	rorr^�liveMessages�keysr_�next�iterr?rqrvrp�addCallbackr�rw)r�dr(r�rrr�test_simpleQuery�s
z&DatagramProtocolTests.test_simpleQuerycCs\|j�dt�d�g�}|�t|jj�d�|j�d�|�	|tj
�|�t|jj�d�|S)�>
        Test that query timeouts after some seconds.
        r�r�r�r7r�r�r�r	rorr^r�r��advance�
assertFailure�DNSQueryTimeoutError�rr�rrr�test_queryTimeoutsz'DatagramProtocolTests.test_queryTimeoutcCs4dd�}||jj_|j�dt�d�g�}|�|t�S)z�
        Exceptions raised by the transport's write method should be turned into
        C{Failure}s passed to errbacks of the C{Deferred} returned by
        L{DNSDatagramProtocol.query}.
        cS�td���N�bar��RuntimeError)rkr�rrr�
writeError�z9DatagramProtocolTests.test_writeError.<locals>.writeErrorr�r��r�r�r]r�r	ror�r��rr�r�rrr�test_writeError
s
z%DatagramProtocolTests.test_writeErrorcCs:dd�}||j_d|j_|j�dt�d�g�}|�|t�S)z�
        Exception L{CannotListenError} raised by C{listenUDP} should be turned
        into a C{Failure} passed to errback of the C{Deferred} returned by
        L{DNSDatagramProtocol.query}.
        cSstddd��r�)rrrrr�startListeningError#�zCDatagramProtocolTests.test_listenError.<locals>.startListeningErrorNr�r�)r��startListeningr�r�r	ror�r)rr�r�rrr�test_listenErrors
z&DatagramProtocolTests.test_listenErrorcCs\t��}d|_tjtjdd�d�g|_|j�|��d�|�	|j
jdd��|���dS)	z�
        When receiving a message whose id is not in
        L{DNSDatagramProtocol.liveMessages} or L{DNSDatagramProtocol.resends},
        the message will be received by L{DNSDatagramProtocol.controller}.
        r�rlr�r_r����rN)r	r_r?rqrvrpr�r�rwrr�r�)rrkrrr�$test_receiveMessageNotInLiveMessages-s
$z:DatagramProtocolTests.test_receiveMessageNotInLiveMessagesN)r&r'r(r/r�r�r�r�r�r�r�rrrrr��sr�c@�(eZdZdZdd�Zdd�Zdd�ZdS)	�TestTCPControllera	
    Pretend to be a DNS query processor for a DNSProtocol.

    @ivar connections: A list of L{DNSProtocol} instances which have
        notified this controller that they are connected and have not
        yet notified it that their connection has been lost.
    cCst�|�g|_dSr�)r�r��connectionsrrrrr�Cs

zTestTCPController.__init__cC�|j�|�dSr�)r�rb�rr�rrr�connectionMadeG�z TestTCPController.connectionMadecCr�r�)r��remover�rrr�connectionLostJr�z TestTCPController.connectionLostN)r&r'r(r/r�r�r�rrrrr�:s
r�c@�@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�DNSProtocolTestsz5
    Test various aspects of L{dns.DNSProtocol}.
    cCs@t��|_t�|_t�|j�|_|j�t	�
��|jj|j_dS)zI
        Create a L{dns.DNSProtocol} with a deterministic clock.
        N)rr�r�r�r�r	�DNSProtocolr�r�r
�StringTransportr�rrrrr�Ss

zDNSProtocolTests.setUpcCs<|�|jj|jg�|j�ttd���|�|jjg�dS)z�
        L{dns.DNSProtocol} calls its controller's C{connectionMade}
        method with itself when it is connected to a transport and its
        controller's C{connectionLost} method when it is disconnected.
        zFake Connection DoneN)rr�r�r�r�r
rrrrr�test_connectionTracking]sz(DNSProtocolTests.test_connectionTrackingcCsZ|j�t�d�g�}|�t|jj�d�|j�d�|�	|tj
�|�t|jj�d�|S)r�r�r��<rr�r�rrrr�gsz"DNSProtocolTests.test_queryTimeoutcs��j�t�d�g�}��t�jj���d�t��}t	t
�jj����|_tjtj
dd�d�g|_�fdd�}|�|�|��}t�dt|��|}�j�|�|S)	r�r�r�rlr�r_cr�r�r�r�rrrr�|r�z-DNSProtocolTests.test_simpleQuery.<locals>.cb�!H)r�r�r	rorr^r�r�r_r�r�r?rqrvrpr�rw�struct�pack�dataReceived)rr�r(r�r�rrrr�rs
z!DNSProtocolTests.test_simpleQuerycCs2dd�}||jj_|j�t�d�g�}|�|t�S)z�
        Exceptions raised by the transport's write method should be turned into
        C{Failure}s passed to errbacks of the C{Deferred} returned by
        L{DNSProtocol.query}.
        cSr�r�r�)rkrrrr��r�z4DNSProtocolTests.test_writeError.<locals>.writeErrorr�r�r�rrrr��s
z DNSProtocolTests.test_writeErrorcCsrt��}d|_tjtjdd�d�g|_|��}t�dt	|��|}|j
�|�|�|j
jdd��|���dS)	z�
        When receiving a message whose id is not in L{DNSProtocol.liveMessages}
        the message will be received by L{DNSProtocol.controller}.
        r�rlr�r_r�r�rN)r	r_r?rqrvrprwr�r�r^r�r�rr�r�)rrkr�rrrr��s$z5DNSProtocolTests.test_receiveMessageNotInLiveMessagesN)
r&r'r(r/r�r�r�r�r�r�rrrrr�Ns

r�c@s�eZdZdZdd�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�Zd4S)5�	ReprTestszE
    Tests for the C{__repr__} implementation of record classes.
    cC�|�tt�dd��d�dS)z�
        The repr of a L{dns.Record_NS} instance includes the name of the
        nameserver and the TTL of the record.
        r��z<NS name=example.com ttl=4321>N)rr3r	�	Record_NSrrrr�test_ns�r%zReprTests.test_nscCr�)z�
        The repr of a L{dns.Record_MD} instance includes the name of the
        mail destination and the TTL of the record.
        rr�z<MD name=example.com ttl=4321>N)rr3r	�	Record_MDrrrr�test_md�r%zReprTests.test_mdcCr�)z�
        The repr of a L{dns.Record_MF} instance includes the name of the
        mail forwarder and the TTL of the record.
        rr�z<MF name=example.com ttl=4321>N)rr3r	�	Record_MFrrrr�test_mf�r%zReprTests.test_mfcCr�)z�
        The repr of a L{dns.Record_CNAME} instance includes the name of the
        mail forwarder and the TTL of the record.
        rr�z!<CNAME name=example.com ttl=4321>N)rr3r	�Record_CNAMErrrr�
test_cname���zReprTests.test_cnamecCr�)z}
        The repr of a L{dns.Record_MB} instance includes the name of the
        mailbox and the TTL of the record.
        rr�z<MB name=example.com ttl=4321>N)rr3r	�	Record_MBrrrr�test_mb�r%zReprTests.test_mbcCr�)z�
        The repr of a L{dns.Record_MG} instance includes the name of the
        mail group member and the TTL of the record.
        rr�z<MG name=example.com ttl=4321>N)rr3r	�	Record_MGrrrr�test_mg�r%zReprTests.test_mgcCr�)z�
        The repr of a L{dns.Record_MR} instance includes the name of the
        mail rename domain and the TTL of the record.
        rr�z<MR name=example.com ttl=4321>N)rr3r	�	Record_MRrrrr�test_mr�r%zReprTests.test_mrcCr�)z~
        The repr of a L{dns.Record_PTR} instance includes the name of the
        pointer and the TTL of the record.
        rr�z<PTR name=example.com ttl=4321>N)rr3r	�
Record_PTRrrrr�test_ptr�r�zReprTests.test_ptrcCr�)z�
        The repr of a L{dns.Record_DNAME} instance includes the name of the
        non-terminal DNS name redirection and the TTL of the record.
        rr�z!<DNAME name=example.com ttl=4321>N)rr3r	�Record_DNAMErrrr�
test_dname�r�zReprTests.test_dnamecCr�)z�
        The repr of a L{dns.Record_A} instance includes the dotted-quad
        string representation of the address it is for and the TTL of the
        record.
        rli7z<A address=1.2.3.4 ttl=567>N)rr3r	rvrrrr�test_a�r�zReprTests.test_ac
Cs*|�ttjddddddddd	��d
�dS)zh
        The repr of a L{dns.Record_SOA} instance includes all of the
        authority fields.
        smNamesrNamerL���r7rLr�)r�r�r�r�r�r�r�rizZ<SOA mname=mName rname=rName serial=123 refresh=456 retry=789 expire=10 minimum=11 ttl=12>N)rr3r	r�rrrr�test_soas���zReprTests.test_soacCr�)z
        The repr of a L{dns.Record_NULL} instance includes the repr of its
        payload and the TTL of the record.
        sabcdrLz<NULL payload='abcd' ttl=123>N)rr3r	r�rrrr�	test_nullr%zReprTests.test_nullcC� |�ttjdddd��d�dS)z�
        The repr of a L{dns.Record_WKS} instance includes the dotted-quad
        string representation of the address it is for, the IP protocol
        number it is for, and the TTL of the record.
        z2.3.4.5rIr�rhz&<WKS address=2.3.4.5 protocol=7 ttl=8>N)rr3r	r�rrrr�test_wks$s�zReprTests.test_wkscCs|�ttjddd��d�dS)z�
        The repr of a L{dns.Record_AAAA} instance includes the colon-separated
        hex string representation of the address it is for and the TTL of the
        record.
        z
8765::1234r7rhz <AAAA address=8765::1234 ttl=10>N)rr3r	r�rrrr�	test_aaaa/s�zReprTests.test_aaaac	Cs"|�ttjddddd��d�dS)z�
        The repr of a L{dns.Record_A6} instance includes the colon-separated
        hex string representation of the address it is for and the TTL of the
        record.
        rz
1234::5678rer7rhz,<A6 suffix=1234::5678 prefix=foo.bar ttl=10>N)rr3r	r�rrrr�test_a6:s�zReprTests.test_a6c
Cs"|�tt�ddddd��d�dS)z�
        The repr of a L{dns.Record_SRV} instance includes the name and port of
        the target and the priority, weight, and TTL of the record.
        r�r�r�r�r�z9<SRV priority=1 weight=2 target=example.org port=3 ttl=4>N)rr3r	r�rrrr�test_srvEs�zReprTests.test_srvc	Cs*t�ddddddd�}|�t|�d�d	S)
z�
        The repr of a L{dns.Record_NAPTR} instance includes the order,
        preference, flags, service, regular expression, replacement, and TTL of
        the record.
        r�rJ�S�https
/foo/bar/i�bazr�zY<NAPTR order=5 preference=9 flags=S service=http regexp=/foo/bar/i replacement=baz ttl=3>N)r	r�rr3�rr�rrr�
test_naptrOs
�zReprTests.test_naptrcC�|�tt�ddd��d�dS)z{
        The repr of a L{dns.Record_AFSDB} instance includes the subtype,
        hostname, and TTL of the record.
        r�r�r�z,<AFSDB subtype=3 hostname=example.org ttl=5>N)rr3r	r�rrrr�
test_afsdb\��zReprTests.test_afsdbcCr)zw
        The repr of a L{dns.Record_RP} instance includes the mbox, txt, and TTL
        fields of the record.
        r�sadmin.example.comr�z7<RP mbox=alice.example.com txt=admin.example.com ttl=3>N)rr3r	r�rrrr�test_rpfrzReprTests.test_rpcCr)zx
        The repr of a L{dns.Record_HINFO} instance includes the cpu, os, and
        TTL fields of the record.
        ssparcsminixr�z%<HINFO cpu='sparc' os='minix' ttl=12>N)rr3r	rrrrr�
test_hinfoprzReprTests.test_hinfocCs"t�ddd�}|�t|�d�dS)z�
        The repr of a L{dns.Record_MINFO} instance includes the rmailbx,
        emailbx, and TTL fields of the record.
        r��bob.example.com�zF<MINFO responsibility=alice.example.com errors=bob.example.com ttl=15>N)r	rrr3rrrr�
test_minfozs
�zReprTests.test_minfocCr)z~
        The repr of a L{dns.Record_MX} instance includes the preference, name,
        and TTL fields of the record.
        �
smx.example.comr�z,<MX preference=13 name=mx.example.com ttl=2>N)rr3r	rrrrr�test_mx�rzReprTests.test_mxcCr)zr
        The repr of a L{dns.Record_TXT} instance includes the data and ttl
        fields of the record.
        r�r�rrhz <TXT data=['foo', 'bar'] ttl=15>N)rr3r	rrrrr�test_txt���zReprTests.test_txtcCr)zr
        The repr of a L{dns.Record_SPF} instance includes the data and ttl
        fields of the record.
        r�r�rrhz <SPF data=['foo', 'bar'] ttl=15>N)rr3r	�
Record_SPFrrrr�test_spf�r#zReprTests.test_spfcCr�)zu
        The repr of a L{dns.UnknownRecord} instance includes the data and ttl
        fields of the record.
        sfoobarr�z"<UNKNOWN data='foo\x1fbar' ttl=12>N)rr3r	rrrrrrr{�r�zReprTests.test_unknownN)r&r'r(r/r�r�r�r�rrrrrr	rr
rrrrrrrrrr!r"r%r{rrrrr��s6			
			


	







r�c@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#dBS)C�
EqualityTestszM
    Tests for the equality and non-equality behavior of record classes.
    cCs|�|||�Sr�)rw)r�
firstValueOne�secondValueOne�valueTworrr�
_equalityTest�s�zEqualityTests._equalityTestcC�$|�t�d�t�d�t�d��dS)zt
        Two L{dns.Charstr} instances compare equal if and only if they have the
        same string value.
        �abc�defN)r*r	r�rrrr�test_charstr�s�zEqualityTests.test_charstrcCr+)zo
        Two L{dns.Name} instances compare equal if and only if they have the
        same name value.
        r,r-N)r*r	r$rrrrr��s$zEqualityTests.test_namecCsD|�|dd�|dd�|dd��|�|dd�|dd�|dd��dS)z�
        Assert that instances of C{cls} with the same attributes compare equal
        to each other and instances with different attributes compare as not
        equal.

        @param cls: A L{dns.SimpleRecord} subclass.
        rrLiAr�N)r*)rrgrrr�_simpleEqualityTest�s	��z!EqualityTests._simpleEqualityTestc
Cs~|�tjdt�d�d�tjdt�d�d�tjdt�d�d��|�tjdt�d�d�tjdt�d�d�tjdt�d�d��|�t�dtj�t�dtj�t�dtj��|�tjdtjt�d�d�tjdtjt�d�d�tjdtjt�d�d��|�tjddt�d�d�tjddt�d�d�tjdd	t�d�d��|�tjdd
t�d�d�tjdd
t�d�d�tjddt�d�d��d
S)z�
        Two L{dns.RRHeader} instances compare equal if and only if they have
        the same name, type, class, time to live, payload, and authoritative
        bit.
        rrlr_r��1.2.3.5)rgrkr�)rirkr<r�)r7rkrN)r*r	rqrvrt�MXru�CSrrrr�
test_rrheader�s<������zEqualityTests.test_rrheadercC�|�tj�dS)zv
        Two L{dns.Record_NS} instances compare equal if and only if they have
        the same name and TTL.
        N)r/r	r�rrrrr�
�zEqualityTests.test_nscCr4�zv
        Two L{dns.Record_MD} instances compare equal if and only if they have
        the same name and TTL.
        N)r/r	r�rrrrr�r5zEqualityTests.test_mdcCr4)zv
        Two L{dns.Record_MF} instances compare equal if and only if they have
        the same name and TTL.
        N)r/r	r�rrrrr�r5zEqualityTests.test_mfcCr4)zy
        Two L{dns.Record_CNAME} instances compare equal if and only if they
        have the same name and TTL.
        N)r/r	r�rrrrr�r5zEqualityTests.test_cnamecCr4)zv
        Two L{dns.Record_MB} instances compare equal if and only if they have
        the same name and TTL.
        N)r/r	r�rrrrr&r5zEqualityTests.test_mbcCr4)zv
        Two L{dns.Record_MG} instances compare equal if and only if they have
        the same name and TTL.
        N)r/r	rrrrrr-r5zEqualityTests.test_mgcCr4)zv
        Two L{dns.Record_MR} instances compare equal if and only if they have
        the same name and TTL.
        N)r/r	rrrrrr4r5zEqualityTests.test_mrcCr4)zw
        Two L{dns.Record_PTR} instances compare equal if and only if they have
        the same name and TTL.
        N)r/r	rrrrrr;r5zEqualityTests.test_ptrcCr4r6)r/r	rrrrrrBr5zEqualityTests.test_dnamecCsP|�t�dd�t�dd�t�dd��|�t�dd�t�dd�t�dd��dS)zx
        Two L{dns.Record_A} instances compare equal if and only if they have
        the same address and TTL.
        rlr�rGr0N)r*r	rvrrrrr	I�


�


�zEqualityTests.test_acCsT|�t�dddddddd�t�dddddddd�t�d	ddddddd��|�t�dddddddd�t�dddddddd�t�dd	dddddd��|�t�dddddddd�t�dddddddd�t�ddd
ddddd��|�t�dddddddd�t�dddddddd�t�dddd
dddd��|�t�dddddddd�t�dddddddd�t�ddddd
ddd��|�t�dddddddd�t�dddddddd�t�dddddd
dd��|�t�dddddddd�t�dddddddd�t�ddddddd
d��|�t�dddddddd�t�dddddddd�t�dd	dddddd
��dS)z�
        Two L{dns.Record_SOA} instances compare equal if and only if they have
        the same mname, rname, serial, refresh, minimum, expire, retry, and
        ttl.
        smnamesrnamerLr
rr7r|r=sxnamer�N)r*r	r�rrrrr[sP��������zEqualityTests.test_soacC�P|�t�dd�t�dd�t�dd��|�t�dd�t�dd�t�dd��dS)z{
        Two L{dns.Record_NULL} instances compare equal if and only if they have
        the same payload and ttl.
        zfoo barr7zbar foor�N)r*r	r�rrrrr
�r7zEqualityTests.test_nullc
C��|�t�dddd�t�dddd�t�dddd��|�t�dddd�t�dddd�t�dddd��|�t�dddd�t�dddd�t�dddd��|�t�dddd�t�dddd�t�dddd��d	S)
z�
        Two L{dns.Record_WKS} instances compare equal if and only if they have
        the same address, protocol, map, and ttl.
        rlr��foor�r�r�r���N)r*r	r�rrrrr��(����zEqualityTests.test_wkscCr8)z{
        Two L{dns.Record_AAAA} instances compare equal if and only if they have
        the same address and ttl.
        z1::2r�z2::1r7N)r*r	r�rrrrr�r7zEqualityTests.test_aaaac
Cr9)
z�
        Two L{dns.Record_A6} instances compare equal if and only if they have
        the same prefix, prefix length, suffix, and ttl.
        r,z::abcdrr7r}z::abcd:0r�r�N)r*r	r�rrrrr�s(	����zEqualityTests.test_a6cCs|�t�ddddd�t�ddddd�t�ddddd��|�t�ddddd�t�ddddd�t�ddddd��|�t�ddddd�t�ddddd�t�ddddd��|�t�ddddd�t�ddddd�t�dddd	d��|�t�ddddd�t�ddddd�t�ddddd
��dS)z�
        Two L{dns.Record_SRV} instances compare equal if and only if they have
        the same priority, weight, port, target, and ttl.
        r7r|r=rr>r�r;i,r��N)r*r	r�rrrrr�s2�����zEqualityTests.test_srvc
Cs�|�t�dddd�t�dddd�t�dddd��|�t�dddd�t�dddd�t�dddd��|�t�dddd�t�dddd�t�dddd��|�t�dddd�t�dddd�t�dddd��dS)z�
        Two L{dns.Record_SSHFP} instances compare equal if and only if
        they have the same key type, fingerprint type, fingerprint, and ttl.
        r�r�shappydayr>shappxday�-N)r*r	r�rrrr�
test_sshfpr<zEqualityTests.test_sshfpc
Cs�|�t�ddddddd�t�ddddddd�t�ddddddd��|�t�ddddddd�t�ddddddd�t�ddddddd��|�t�ddddddd�t�ddddddd�t�ddd	dddd��|�t�ddddddd�t�ddddddd�t�dddd
ddd��|�t�ddddddd�t�ddddddd�t�ddddddd��|�t�ddddddd�t�ddddddd�t�ddddddd��|�t�ddddddd�t�ddddddd�t�ddddddd
��dS)z�
        Two L{dns.Record_NAPTR} instances compare equal if and only if they
        have the same order, preference, flags, service, regexp, replacement,
        and ttl.
        r�r�r�r�s	/foo/bar/rr�r��prs	/bar/foo/squuxr�N)r*r	r�rrrrr7sF�������zEqualityTests.test_naptrc	Cs�|�t�ddd�t�ddd�t�ddd��|�t�ddd�t�ddd�t�ddd��|�t�ddd�t�ddd�t�ddd��dS)z�
        Two L{dns.Record_AFSDB} instances compare equal if and only if they
        have the same subtype, hostname, and ttl.
        r�rr�r�r�N)r*r	r�rrrrrh����zEqualityTests.test_afsdbc	C�|�t�ddd�t�ddd�t�ddd��|�t�ddd�t�ddd�t�ddd��|�t�ddd�t�ddd�t�ddd��dS)zx
        Two L{Record_RP} instances compare equal if and only if they have the
        same mbox, txt, and ttl.
        r�s
alice is nicer7rsalice is not nicer�N)r*r	r�rrrrr�rAzEqualityTests.test_rpc	CrB)z}
        Two L{dns.Record_HINFO} instances compare equal if and only if they
        have the same cpu, os, and ttl.
        zx86-64�plan9r7�i386�plan11r�N)r*r	rrrrrr�rAzEqualityTests.test_hinfoc	CrB)z�
        Two L{dns.Record_MINFO} instances compare equal if and only if they
        have the same rmailbx, emailbx, and ttl.
        srmailboxsemailboxr7s	someplaces	somethingr�N)r*r	rrrrrr�rAzEqualityTests.test_minfoc	CrB)z�
        Two L{dns.Record_MX} instances compare equal if and only if they have
        the same preference, name, and ttl.
        r7r�r|r�sexample.netr;N)r*r	rrrrrr!�rAzEqualityTests.test_mxc
C�|�tjdddd�tjdddd�tjddddd��|�tjdddd�tjdddd�tjdddd��|�tjdddd�tjdddd�tjdddd��dS)zw
        Two L{dns.Record_TXT} instances compare equal if and only if they have
        the same data and ttl.
        r:r�r7rh�bazr�N)r*r	rrrrrr"�����zEqualityTests.test_txtc
CrF)zs
        L{dns.Record_SPF} instances compare equal if and only if they have the
        same data and ttl.
        r:r�r7rhrGr�N)r*r	r$rrrrr%�rHzEqualityTests.test_spfc	Cs�dddddtjddd�}d	d
ddd
tjddd�}|��D]%}|��}||||<|�tjdi|��tjdi|��tjdi|���qdS)z�
        L{dns.Record_TSIG} instances compare equal if and only if they have the
        same RDATA (algorithm, timestamp, MAC, etc.) and ttl.
        zhmac-sha224r	r�s�cr�r>)r�rr
rrrrrizhmac-sha512i�pUZrsi���r=Nr)r	�OKrr��copyr*r)r�baseargs�altargs�kw�alteredrrr�	test_tsig	s6��
��zEqualityTests.test_tsigcCs�|�tjddd�tjddd�tjddd��|�tjddd�tjddd�tjddd��|�tjddd�tjddd�tjddd��dS)zv
        L{dns.UnknownRecord} instances compare equal if and only if they have
        the same data and ttl.
        r:r7rh�foobarr�r�N)r*r	rrrrrrr{2	rAzEqualityTests.test_unknownN)$r&r'r(r/r*r.r�r/r3r�r�r�r�rrrrrr	rr
rrrrr?rrrrrr!r"r%rQr{rrrrr&�sD	17!$1"r&c@r�)	�
RRHeaderTestsz2
    Tests for L{twisted.names.dns.RRHeader}.
    cC�&|�ttjdtjtjdt�d��dS)z�
        Attempting to create a L{dns.RRHeader} instance with a negative TTL
        causes L{ValueError} to be raised.
        rr�r�N�r"rHr	rqrtrurvrrrr�test_negativeTTLP	��zRRHeaderTests.test_negativeTTLc	Cs6d}t�dtjtj|t�d��}|�|jt|��dS)z<
        L{dns.RRHeader} converts TTLs to integers.
        g������^@rr�N)r	rqrtrurvrri�int)r�
ttlAsFloat�headerrrr�test_nonIntegralTTL_	s
�z!RRHeaderTests.test_nonIntegralTTLcCrT)z�
        Attempting to create a L{dns.RRHeader} instance with a TTL
        that L{int} cannot convert to an integer raises a L{TypeError}.
        rzthis is not a numberr�NrUrrrr�!test_nonNumericTTLRaisesTypeErrori	rWz/RRHeaderTests.test_nonNumericTTLRaisesTypeErrorN)r&r'r(r/rVr[r\rrrrrSK	s

rSc@r�)�NameToLabelsTestsz7
    Tests for L{twisted.names.dns._nameToLabels}.
    cCs|�t�d�dg�dS)zp
        L{dns._nameToLabels} returns a list containing a single
        empty label for an empty name.
        r�N�rr	�
_nameToLabelsrrrr�
test_empty~	r5zNameToLabelsTests.test_emptycCs|�t�d�dg�dS)z
        L{dns._nameToLabels} returns a list containing a single
        empty label for a name containing only a dot.
        �.r�Nr^rrrr�test_onlyDot�	r5zNameToLabelsTests.test_onlyDotcCs|�t�d�ddg�dS)z{
        L{dns._nameToLabels} returns a list ending with an empty
        label for a name without a trailing dot.
        �comr�Nr^rrrr�test_withoutTrailingDot�	r!z)NameToLabelsTests.test_withoutTrailingDotcCs|�t�d�ddg�dS)zx
        L{dns._nameToLabels} returns a list ending with an empty
        label for a name with a trailing dot.
        scom.rcr�Nr^rrrr�test_withTrailingDot�	r!z&NameToLabelsTests.test_withTrailingDotcC�|�t�d�gd��dS)zt
        L{dns._nameToLabels} returns a list containing entries
        for all labels in a subdomain name.
        sfoo.bar.baz.example.com.)r�r�rsexamplercr�Nr^rrrr�test_subdomain�	s�z NameToLabelsTests.test_subdomaincCrf)z`
        L{dns._nameToLabels} preserves the case of ascii
        characters in labels.
        �EXAMPLE.COM)sEXAMPLEsCOMr�Nr^rrrr�test_casePreservation�	r!z'NameToLabelsTests.test_casePreservationN)
r&r'r(r/r`rbrdrergrirrrrr]y	s
r]cC�"|�t�||�|�d|���dS)a\
    Assert that C{descendant} *is* a subdomain of C{ancestor}.

    @type testCase: L{unittest.SynchronousTestCase}
    @param testCase: The test case on which to run the assertions.

    @type descendant: C{str}
    @param descendant: The subdomain name to test.

    @type ancestor: C{str}
    @param ancestor: The superdomain name to test.
    z is not a subdomain of N)rmr	�_isSubdomainOf��testCase�
descendant�ancestorrrr�assertIsSubdomainOf�	�
�rpcCrj)a`
    Assert that C{descendant} *is not* a subdomain of C{ancestor}.

    @type testCase: L{unittest.SynchronousTestCase}
    @param testCase: The test case on which to run the assertions.

    @type descendant: C{str}
    @param descendant: The subdomain name to test.

    @type ancestor: C{str}
    @param ancestor: The superdomain name to test.
    z is a subdomain of N)rTr	rkrlrrr�assertIsNotSubdomainOf�	rqrrc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�IsSubdomainOfTestsz8
    Tests for L{twisted.names.dns._isSubdomainOf}.
    cCst|dd�dS)z[
        L{dns._isSubdomainOf} returns C{True} for identical
        domain names.
        rN�rprrrr�test_identical�	r5z!IsSubdomainOfTests.test_identicalcC�t|dd�dS)z�
        L{dns._isSubdomainOf} returns C{True} when the first
        name is an immediate descendant of the second name.
        rVrNrtrrrr�test_parent�	r5zIsSubdomainOfTests.test_parentcCrv)z
        L{dns._isSubdomainOf} returns C{True} when the first
        name is a distant descendant of the second name.
        sfoo.bar.baz.example.comrcNrtrrrr�test_distantAncestor�	r5z'IsSubdomainOfTests.test_distantAncestorcCrv)zw
        L{dns._isSubdomainOf} returns C{False} when the first
        name is an ancestor of the second name.
        rrVN�rrrrrr�test_superdomain�	r5z#IsSubdomainOfTests.test_superdomaincCrv)zs
        L{dns._isSubdomainOf} returns C{False} if the first name
        is a sibling of the second name.
        rVsbar.example.comNryrrrr�test_sibling�	r5zIsSubdomainOfTests.test_siblingcCrv)zx
        L{dns._isSubdomainOf} returns C{False} even when domain
        names happen to share a common suffix.
        sfoo.myexample.comrNryrrrr�test_unrelatedCommonSuffix�	r5z-IsSubdomainOfTests.test_unrelatedCommonSuffixcCrv)z�
        L{dns._isSubdomainOf} returns C{True} if the first name
        is a subdomain of the second name but the first name has a
        trailing ".".
        �foo.example.com.rNrtrrrr�test_subdomainWithTrailingDot
�z0IsSubdomainOfTests.test_subdomainWithTrailingDotcCrv)z�
        L{dns._isSubdomainOf} returns C{True} if the first name
        is a subdomain of the second name but the second name has a
        trailing ".".
        rV�example.com.Nrtrrrr�test_superdomainWithTrailingDot	
rz2IsSubdomainOfTests.test_superdomainWithTrailingDotcCrv)z�
        L{dns._isSubdomainOf} returns C{True} if the first name
        is a subdomain of the second name and both names have a
        trailing ".".
        r}r�Nrtrrrr�test_bothWithTrailingDot
rz+IsSubdomainOfTests.test_bothWithTrailingDotcCrv)zw
        L{dns._isSubdomainOf} returns C{False} if the first name
        is empty and the second name is not.
        r�rNryrrrr�test_emptySubdomain
r5z&IsSubdomainOfTests.test_emptySubdomaincCrv)zv
        L{dns._isSubdomainOf} returns C{True} if the second name
        is empty and the first name is not.
        rVr�Nrtrrrr�test_emptySuperdomain 
r5z(IsSubdomainOfTests.test_emptySuperdomaincCst|dd�t|dd�dS)z`
        L{dns._isSubdomainOf} does case-insensitive comparison
        of name labels.
        rVrhsFOO.EXAMPLE.COMrNrtrrrr�test_caseInsensitiveComparison'
sz1IsSubdomainOfTests.test_caseInsensitiveComparisonN)r&r'r(r/rurwrxrzr{r|r~r�r�r�r�r�rrrrrs�	srsc@s*eZdZdZeddd��Zedd��ZdS)	�OPTNonStandardAttributesz�
    Generate byte and instance representations of an L{dns._OPTHeader}
    where all attributes are set to non-default values.

    For testing whether attributes have really been read from the byte
    string during decoding.
    FcCsd}|rd}d|S)aT
        Return L{bytes} representing an encoded OPT record.

        @param excludeName: A flag that controls whether to exclude
            the name field. This allows a non-standard name to be
            prepended during the test.
        @type excludeName: L{bool}

        @param excludeOptions: A flag that controls whether to exclude
            the RDLEN field. This allows encoded variable options to be
            appended during the test.
        @type excludeOptions: L{bool}

        @return: L{bytes} representing the encoded OPT record returned
            by L{object}.
        rJr�s	)�r)rg�excludeName�excludeOptions�rdlenrrrrP:
s�zOPTNonStandardAttributes.bytescCstjddddd�S)z�
        Return a new L{dns._OPTHeader} instance.

        @return: A L{dns._OPTHeader} instance with attributes that
            match the encoded record returned by L{bytes}.
        �r�r�T)�udpPayloadSize�
extendedRCODE�version�dnssecOK)r	�
_OPTHeader�rgrrrr2Y
s�zOPTNonStandardAttributes.objectN)FF)r&r'r(r/�classmethodrPr2rrrrr�1
sr�c@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@S)A�OPTHeaderTestsz4
    Tests for L{twisted.names.dns._OPTHeader}.
    cC�ttjtj�dS)zA
        L{dns._OPTHeader} implements L{dns.IEncodable}.
        N)rr	�
IEncodabler�rrrr�test_interfacek
�zOPTHeaderTests.test_interfacecCs|�t��jt�d��dS)zq
        L{dns._OPTHeader.name} is an instance attribute whose value is
        fixed as the root domain
        r�N)rr	r�rOr$rrrrr�q
szOPTHeaderTests.test_namec	Cs$t��}|�tt|dt�d��dS)z5
        L{dns._OPTHeader.name} is readonly.
        rOrN)r	r�r"�AttributeError�setattrr$�r�hrrr�test_nameReadonlyx
sz OPTHeaderTests.test_nameReadonlycCr)z^
        L{dns._OPTHeader.type} is an instance attribute with fixed value
        41.
        �)N)rr	r�rfrrrr�	test_type
rzOPTHeaderTests.test_typecCs t��}|�tt|dtj�dS)z5
        L{dns._OPTHeader.type} is readonly.
        rfN)r	r�r"r�r�rtr�rrr�test_typeReadonly�
sz OPTHeaderTests.test_typeReadonlycCr)zt
        L{dns._OPTHeader.udpPayloadSize} defaults to 4096 as
        recommended in rfc6891 section-6.2.5.
        �N�rr	r�r�rrrr�test_udpPayloadSize�
rz"OPTHeaderTests.test_udpPayloadSizecCr)z`
        L{dns._OPTHeader.udpPayloadSize} can be overridden in the
        constructor.
        r��r�Nr�rrrr�test_udpPayloadSizeOverride�
r!z*OPTHeaderTests.test_udpPayloadSizeOverridecCr)z@
        L{dns._OPTHeader.extendedRCODE} defaults to 0.
        rN�rr	r�r�rrrr�test_extendedRCODE�
rz!OPTHeaderTests.test_extendedRCODEcCr)z_
        L{dns._OPTHeader.extendedRCODE} can be overridden in the
        constructor.
        r��r�Nr�rrrr�test_extendedRCODEOverride�
r!z)OPTHeaderTests.test_extendedRCODEOverridecCr)z:
        L{dns._OPTHeader.version} defaults to 0.
        rN�rr	r�r�rrrr�test_version�
rzOPTHeaderTests.test_versioncCr)zY
        L{dns._OPTHeader.version} can be overridden in the
        constructor.
        r��r�Nr�rrrr�test_versionOverride�
r!z#OPTHeaderTests.test_versionOverridecCs|�t��j�dS)z?
        L{dns._OPTHeader.dnssecOK} defaults to False.
        N)rTr	r�r�rrrr�
test_dnssecOK�
rJzOPTHeaderTests.test_dnssecOKcCs|�tjdd�j�dS)zZ
        L{dns._OPTHeader.dnssecOK} can be overridden in the
        constructor.
        T�r�N)rmr	r�r�rrrr�test_dnssecOKOverride�
r5z$OPTHeaderTests.test_dnssecOKOverridecCs|�t��jg�dS)zC
        L{dns._OPTHeader.options} defaults to empty list.
        N)rr	r��optionsrrrr�test_options�
rzOPTHeaderTests.test_optionscCs"tjdgd�}|�|jdg�dS)zY
        L{dns._OPTHeader.options} can be overridden in the
        constructor.
        )r�r���r�N)r	r�rr�r�rrr�test_optionsOverride�
sz#OPTHeaderTests.test_optionsOverridecCs,t�}t���|�|�|��t���dS)z�
        L{dns._OPTHeader.encode} packs the header fields and writes
        them to a file like object passed in as an argument.
        N)rr�r2rWrrXrP)r�brrrr[�
szOPTHeaderTests.test_encodecCsRt��}t�dd�t�dd�g|_t�}|�|�|�|��tj	dd�d�dS)	z�
        L{dns._OPTHeader.options} is a list of L{dns._OPTVariableOption}
        instances which are packed into the rdata area of the header.
        r��	foobarbazr��quxT�r��	foobarbazquxN)
r�r2r	�_OPTVariableOptionr�rrWrrXrP)rr�r�rrr�test_encodeWithOptions�
s

�

��z%OPTHeaderTests.test_encodeWithOptionscCs.t��}|�tt����|�|t���dS)z�
        L{dns._OPTHeader.decode} unpacks the header fields from a file
        like object and populates the attributes of an existing
        L{dns._OPTHeader} instance.
        N)r	r�rSrr�rPrr2)r�
decodedHeaderrrrrU�
szOPTHeaderTests.test_decodecCs:tt���}t��}|�|�|�|��t|�	���dS)zk
        L{dns._OPTHeader.decode} reads all the bytes of the record
        that is being decoded.
        N�
rr�rPr	r�rSrr�r^rX�rr�r�rrr�test_decodeAllExpectedBytess
z*OPTHeaderTests.test_decodeAllExpectedBytescCsFtt��d�}t��}|�|�|�|��t|�	��td��dS)z�
        L{dns._OPTHeader.decode} reads only the bytes from the current
        file position to the end of the record that is being
        decoded. Trailing bytes are not consumed.
        sxxxxNr�r�rrr�test_decodeOnlyExpectedBytes
s
$z+OPTHeaderTests.test_decodeOnlyExpectedBytescCs>ttjdd�d�}t��}|�|�|�|jt�d��dS)z�
        L{dns._OPTHeader.decode} discards the name which is encoded in
        the supplied bytes. The name attribute of the resulting
        L{dns._OPTHeader} instance will always be L{dns.Name(b'')}.
        T)r�rRr�N)	rr�rPr	r�rSrrOr$�rr�r�rrr�test_decodeDiscardsNames�
z&OPTHeaderTests.test_decodeDiscardsNamecC�0ttjdd�d�}t��}|�t|j|�dS)zj
        L{dns._OPTHeader.decode} raises an exception if the supplied
        RDLEN is too short.
        Tr�sN�rr�rPr	r�r"rPrSr�rrr�test_decodeRdlengthTooShort(�
��	z*OPTHeaderTests.test_decodeRdlengthTooShortcCr�)zi
        L{dns._OPTHeader.decode} raises an exception if the supplied
        RDLEN is too long.
        Tr�sNr�r�rrr�test_decodeRdlengthTooLong9r�z)OPTHeaderTests.test_decodeRdlengthTooLongcCsLttjdd�d�}t��}|�|�|�|jt�dd�t�dd�g�dS)	z�
        If the OPT bytes contain variable options,
        L{dns._OPTHeader.decode} will populate a list
        L{dns._OPTHeader.options} with L{dns._OPTVariableOption}
        instances.
        Tr�r�r�r�r�r�N)	rr�rPr	r�rSrr�r�r�rrr�test_decodeWithOptionsJs
��


��z%OPTHeaderTests.test_decodeWithOptionsc	CsXtjdtjddt�d�d�}tj�|�}tjddddtjdd	d
�gd�}|�||�dS)
z�
        L{_OPTHeader.fromRRHeader} accepts an L{RRHeader} instance and
        returns an L{_OPTHeader} instance whose attribute values have
        been derived from the C{cls}, C{ttl} and C{payload} attributes
        of the original header.
        rrl�}s��abcrj��Tr,)�code�data)r�r�r�r�r�N)r	rq�OPTrrr��fromRRHeaderr�r)r�
genericHeader�decodedOptHeader�expectedOptHeaderrrr�test_fromRRHeaderis ��z OPTHeaderTests.test_fromRRHeadercCs|�tt���d�dS)z�
        L{dns._OPTHeader.__repr__} displays the name and type and all
        the fixed and extended header values of the OPT record.
        zb<_OPTHeader name= type=41 udpPayloadSize=4096 extendedRCODE=0 version=0 dnssecOK=False options=[]>N)rr3r	r�rrrr�	test_repr�s
�zOPTHeaderTests.test_reprcC�*|�tjdd�tjdd�tjdd��dS)zh
        Two L{OPTHeader} instances compare equal if they have the same
        udpPayloadSize.
        r�r�r�N�rwr	r�rrrr�test_equalityUdpPayloadSize�ryz*OPTHeaderTests.test_equalityUdpPayloadSizecCr�)zg
        Two L{OPTHeader} instances compare equal if they have the same
        extendedRCODE.
        r�r�r�Nr�rrrr�test_equalityExtendedRCODE�ryz)OPTHeaderTests.test_equalityExtendedRCODEcCr�)za
        Two L{OPTHeader} instances compare equal if they have the same
        version.
        r�r�r�Nr�rrrr�test_equalityVersion�ryz#OPTHeaderTests.test_equalityVersioncCr�)zh
        Two L{OPTHeader} instances compare equal if they have the same
        dnssecOK flags.
        Tr�FNr�rrrr�test_equalityDnssecOK�ryz$OPTHeaderTests.test_equalityDnssecOKc	CsH|�tjt�dd�gd�tjt�dd�gd�tjt�dd�gd��dS)za
        Two L{OPTHeader} instances compare equal if they have the same
        options.
        r��xr�r��yN)rwr	r�r�rrrr�test_equalityOptions�s
�z#OPTHeaderTests.test_equalityOptionsN)#r&r'r(r/r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r[r�rUr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�f
sB


r�c@r�)�OPTVariableOptionTestsz.
    Tests for L{dns._OPTVariableOption}.
    cCr�)zI
        L{dns._OPTVariableOption} implements L{dns.IEncodable}.
        N)rr	r�r�rrrrr��r�z%OPTVariableOptionTests.test_interfacecCs,t�dd�}|�|jd�|�|jd�dS)z�
        L{dns._OPTVariableOption.__init__} requires code and data
        arguments which are saved as public instance attributes.
        r�r�N)r	r�rr�r�r�rrr�test_constructorArguments�sz0OPTVariableOptionTests.test_constructorArgumentscCr�)zf
        L{dns._OPTVariableOption.__repr__} displays the code and data
        of the option.
        r�r�z"<_OPTVariableOption code=1 data=x>N)rr3r	r�rrrrr��r�z OPTVariableOptionTests.test_reprcCr8)zs
        Two OPTVariableOption instances compare equal if they have the same
        code and data values.
        r�r�r�r�N)rwr	r�rrrrr��s


�


�z$OPTVariableOptionTests.test_equalitycCs0t�dd�}t�}|�|�|�|��d�dS)z�
        L{dns._OPTVariableOption.encode} encodes the code and data
        instance attributes to a byte string which also includes the
        data length.
        r��foobar�
foobarN)r	r�rrWrrX)r�or�rrrr[�s
�z"OPTVariableOptionTests.test_encodecCs:td�}t��}|�|�|�|jd�|�|jd�dS)z�
        L{dns._OPTVariableOption.decode} is a classmethod that decodes
        a byte string and returns a L{dns._OPTVariableOption} instance.
        r�r�r�N)rr	r�rSrr�r�)rr�r�rrrrUs�
z"OPTVariableOptionTests.test_decodeN)
r&r'r(r/r�r�r�r�r[rUrrrrr��s	
r�c@r))�
RaisedArgszp
    An exception which can be raised by fakes to test that the fake is called
    with expected arguments.
    cCs||_||_dS)z�
        Store the positional and keyword arguments as attributes.

        @param args: The positional args.
        @param kwargs: The keyword args.
        N�rqrr�rrqrrrrrr�#s
zRaisedArgs.__init__N)r&r'r(r/r�rrrrr�sr�c@�(eZdZdZedd��Zedd��ZdS)�MessageEmptyz^
    Generate byte string and constructor arguments for an empty
    L{dns._EDNSMessage}.
    cC�	dS)��
        Bytes which are expected when encoding an instance constructed using
        C{kwargs} and which are expected to result in an identical instance when
        decoded.

        @return: The L{bytes} of a wire encoded message.
        s��rr�rrrrP4�
�zMessageEmpty.bytescCstddtjddddddd�	S)��
        Keyword constructor arguments which are expected to result in an
        instance which returns C{bytes} when encoded.

        @return: A L{dict} of keyword arguments.
        rSTrN�	r?r6r@r7r8r9r:rA�ednsVersion)�dictr	�	OP_STATUSr�rrrrrGs�zMessageEmpty.kwargsN�r&r'r(r/r�rPrrrrrrr�.s
r�c@r�)�MessageTruncatedz=
    An empty response message whose TR bit is set to 1.
    cCr�)r�s�rr�rrrrPar�zMessageTruncated.bytescCstdddddddddd�	S)r�rSr�rNr�)r�r�rrrrrts�zMessageTruncated.kwargsNr�rrrrr�\s
r�c@r�)�MessageNonAuthoritativez.
    A minimal non-authoritative message.
    cCr�)r�srr�rrrrP�r�zMessageNonAuthoritative.bytesc
Cs(tdddtjdtjddd�dd�gd	�S)
r�rSrNr�rlrhF�rkr7�r?r7r�rp�r�r	rqrvr�rrrrr����zMessageNonAuthoritative.kwargsNr�rrrrr���
r�c@r�)�MessageAuthoritativez*
    A minimal authoritative message.
    cCr�)r�srr�rrrrP�r�zMessageAuthoritative.bytesc
Cs(tdddtjdtjddd�dd	�gd
�S)r�rSr�Nr�rlrrhTr�r�r�r�rrrrr�r�zMessageAuthoritative.kwargsNr�rrrrr��r�r�c@r�)�MessageCompletez�
    An example of a fully populated non-edns response message.

    Contains name compression, answers, authority, and additional records.
    cCr�)r�sn��examplecom�����'ns1�
hostmaster������������������������)�)����rr�rrrrP�r�zMessageComplete.bytescCs�tddtjdddddt�dtj�gtjdtjddtjddd	d
ddd
dd�d�gtjdtjddtjddd�d�gtjdtj	ddtj
ddd�d�gd�S)r�rSr�rNr���T�ns1.example.com�hostmaster.example.com�������������rir�r�r�r�r�r�r��rfrir7rk�ns1.example.comrh�5.6.7.8)r?r6r@r7r9r:rAr�rnrprMrs�r�r	r�ror�rqr��NSr�rtrvr�rrrrr$
sX�����
���zMessageComplete.kwargsNr�rrrrr��s
1r�c@r�)�MessageEDNSQueryz'
    A minimal EDNS query message.
    cCr�)r�s,wwwexamplecom)rr�rrrrPb
r�zMessageEDNSQuery.bytescCs,tddtjddddddt�dtj�ggd�S)r�rr�Fswww.example.com)r?r6r@r7r9r:rAr�r�rnrs)r�r	rUrortr�rrrrr�
s�zMessageEDNSQuery.kwargsNr�rrrrr]
s
rc@r�)�MessageEDNSCompletez�
    An example of a fully populated edns response message.

    Contains name compression, answers, authority, and additional records.
    cCr�)r�sy��examplecom�����'ns1�
hostmaster������������������������)�)����)�rr�rrrrP�
r�zMessageEDNSComplete.bytescCs�td(idd�dd�dtj�dd�dd�d	d�d
d�dd�d
d�dd�dd�dd�dd�dt�dtj�g�dtjdtjddtjddddddddd �d!�g�d"tjdtjddtjd#dd$�d!�g�d%tjdtj	ddtj
d&dd$�d!�g��S))r�r?rSr6r�r@r7r8rr9r:rArr�r�r�Trr,rB�rnrrpr�r�r�r�r�r�r�r�rrrMrrhrsrNrrr�rrrrr�
s���������	�
���
������"���+���zMessageEDNSComplete.kwargsNr�rrrrr�
s
9rc@r�)�MessageEDNSExtendedRCODEz?
    An example of an EDNS message with an extended RCODE.
    cCr�)r�s)�rr�rrrrPr�zMessageEDNSExtendedRCODE.bytescCs(tddtjddddddddggggd�S)r�rFi�
r�)r?r6r@r7r8r9r:rAr�r�rBrnrprMrs)r�r	rUr�rrrrr7s"�zMessageEDNSExtendedRCODE.kwargsNr�rrrrr	s
r	c@s(eZdZdZdZZdd�Zdd�ZdS)�MessageComparablez�
    A wrapper around L{dns.Message} which is comparable so that it can be tested
    using some of the L{dns._EDNSMessage} tests.
    )r?r6r@r7r8r9r:rArnrprMrscCs
||_dSr�)�original)rrrrrr�g�
zMessageComparable.__init__cCst|j|�Sr�)�getattrr)r�keyrrr�__getattr__jr�zMessageComparable.__getattr__N)r&r'r(r/�showAttributes�compareAttributesr�rrrrrr
Rs
r
c	Cs^|dur|}i}||d�}|�}t||�|d<|di||i��}t||�|d<|�||�dS)a�
    Verify that an attribute has the expected default value and that a
    corresponding argument passed to a constructor is assigned to that
    attribute.

    @param testCase: The L{TestCase} whose assert methods will be
        called.
    @type testCase: L{unittest.TestCase}

    @param cls: The constructor under test.
    @type cls: L{type}

    @param argName: The name of the constructor argument under test.
    @type argName: L{str}

    @param defaultVal: The expected default value of C{attrName} /
        C{argName}
    @type defaultVal: L{object}

    @param altVal: A value which is different from the default. Used to
        test that supplied constructor arguments are actually assigned to the
        correct attribute.
    @type altVal: L{object}

    @param attrName: The name of the attribute under test if different
        from C{argName}. Defaults to C{argName}
    @type attrName: L{str}
    N��
defaultVal�altValrrr)r
r)	rmrg�argNamerr�attrName�actualrcr�rrr�verifyConstructorArgumentns
rc@s eZdZdZdd�Zdd�ZdS)�ConstructorTestsMixinzl
    Helper methods for verifying default attribute values and corresponding
    constructor arguments.
    cCst||j|||d�dS)a�
        Wrap L{verifyConstructorArgument} to provide simpler interface for
        testing Message and _EDNSMessage constructor arguments.

        @param argName: The name of the constructor argument.
        @param defaultVal: The expected default value.
        @param altVal: An alternative value which is expected to be assigned to
            a correspondingly named attribute.
        �rmrgrrrN�rrs)rrrrrrr�_verifyConstructorArgument�s

�z0ConstructorTestsMixin._verifyConstructorArgumentcCs&|dvsJ�t||j|||d�dS)a

        Wrap L{verifyConstructorArgument} to provide simpler interface for
        testing  _EDNSMessage constructor flags.

        @param argName: The name of the constructor flag argument
        @param defaultVal: The expected default value of the flag
        )TFrNr)rrrrrr�_verifyConstructorFlag�s
�z,ConstructorTestsMixin._verifyConstructorFlagN)r&r'r(r/rrrrrrr�src@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�CommonConstructorTestsMixina�
    Tests for constructor arguments and their associated attributes that are
    common to both L{twisted.names.dns._EDNSMessage} and L{dns.Message}.

    TestCase classes that use this mixin must provide a C{messageFactory} method
    which accepts any argment supported by L{dns.Message.__init__}.

    TestCases must also mixin ConstructorTestsMixin which provides some custom
    assertions for testing constructor arguments.
    cC�|jdddd�dS)zk
        L{dns._EDNSMessage.id} defaults to C{0} and can be overridden in
        the constructor.
        r?rr�rN�rrrrrrx��z#CommonConstructorTestsMixin.test_idcC�|jddd�dS)zs
        L{dns._EDNSMessage.answer} defaults to C{False} and can be overridden in
        the constructor.
        r6F�rN�rrrrrr{��z'CommonConstructorTestsMixin.test_answercCs|jdtjtjd�dS)zz
        L{dns._EDNSMessage.opCode} defaults to L{dns.OP_QUERY} and can be
        overridden in the constructor.
        r@rN)rr	rUr�rrrrr}�s

�z'CommonConstructorTestsMixin.test_opCodecCr")zq
        L{dns._EDNSMessage.auth} defaults to C{False} and can be overridden in
        the constructor.
        r7Fr#Nr$rrrrr��r%z%CommonConstructorTestsMixin.test_authcCr")zr
        L{dns._EDNSMessage.trunc} defaults to C{False} and can be overridden in
        the constructor.
        r8Fr#Nr$rrrrr��r%z&CommonConstructorTestsMixin.test_trunccCr")zs
        L{dns._EDNSMessage.recDes} defaults to C{False} and can be overridden in
        the constructor.
        r9Fr#Nr$rrrrr�r%z'CommonConstructorTestsMixin.test_recDescCr")zr
        L{dns._EDNSMessage.recAv} defaults to C{False} and can be overridden in
        the constructor.
        r:Fr#Nr$rrrrr��r%z&CommonConstructorTestsMixin.test_recAvcCr)zn
        L{dns._EDNSMessage.rCode} defaults to C{0} and can be overridden in the
        constructor.
        rArrLrNr rrrrr�r!z&CommonConstructorTestsMixin.test_rCodecCr)zr
        L{dns._EDNSMessage.maxSize} defaults to C{512} and can be overridden in
        the constructor.
        rBr�rrNr rrrrr�r!z(CommonConstructorTestsMixin.test_maxSizecC�|�|��jg�dS)z@
        L{dns._EDNSMessage.queries} defaults to C{[]}.
        N)rrsrnrrrrr�rz(CommonConstructorTestsMixin.test_queriescCr&)z@
        L{dns._EDNSMessage.answers} defaults to C{[]}.
        N)rrsrprrrrr�rz(CommonConstructorTestsMixin.test_answerscCr&)zB
        L{dns._EDNSMessage.authority} defaults to C{[]}.
        N)rrsrMrrrrr�rz*CommonConstructorTestsMixin.test_authoritycCr&)zC
        L{dns._EDNSMessage.additional} defaults to C{[]}.
        N)rrsrsrrrrr�%rz+CommonConstructorTestsMixin.test_additionalN)r&r'r(r/rxr{r}r�r�rr�r�r�r�r�r�r�rrrrr�s	rc@�eZdZdZejZdS)�EDNSMessageConstructorTestszt
    Tests for L{twisted.names.dns._EDNSMessage} constructor arguments that are
    shared with L{dns.Message}.
    N�r&r'r(r/r	�_EDNSMessagersrrrrr(,�
r(c@r')�MessageConstructorTestszt
    Tests for L{twisted.names.dns.Message} constructor arguments that are shared
    with L{dns._EDNSMessage}.
    N)r&r'r(r/r	r_rsrrrrr,7r+r,c@s�eZdZdZejZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�EDNSMessageSpecificsTestsz�
    Tests for L{dns._EDNSMessage}.

    These tests are for L{dns._EDNSMessage} APIs which are not shared with
    L{dns.Message}.
    cCs|jdddd�dS)zt
        L{dns._EDNSMessage.ednsVersion} defaults to C{0} and can be overridden
        in the constructor.
        r�rNrr rrrr�test_ednsVersionLr!z*EDNSMessageSpecificsTests.test_ednsVersioncCr")zu
        L{dns._EDNSMessage.dnssecOK} defaults to C{False} and can be overridden
        in the constructor.
        r�Fr#Nr$rrrrr�Sr%z'EDNSMessageSpecificsTests.test_dnssecOKcCr")zz
        L{dns._EDNSMessage.authenticData} defaults to C{False} and can be
        overridden in the constructor.
        rFr#Nr$rrrrr�Zr%z,EDNSMessageSpecificsTests.test_authenticDatacCr")z}
        L{dns._EDNSMessage.checkingDisabled} defaults to C{False} and can be
        overridden in the constructor.
        r,Fr#Nr$rrrrr�ar%z/EDNSMessageSpecificsTests.test_checkingDisabledcCs.|jt�d�gd�}|�|jt�d�g�dS)zS
        L{dns._EDNSMessage.queries} can be overridden in the constructor.
        rr�N)rsr	rorrnrQrrr�test_queriesOverridehsz.EDNSMessageSpecificsTests.test_queriesOverridecC�B|jtjdt�d�d�gd�}|�|jtjdt�d�d�g�dS)zS
        L{dns._EDNSMessage.answers} can be overridden in the constructor.
        rrlr_r�N)rsr	rqrvrrprQrrr�test_answersOverrideps��z.EDNSMessageSpecificsTests.test_answersOverridecCsF|jtjdtjt��d�gd�}|�|jtjdtjt��d�g�dS)�U
        L{dns._EDNSMessage.authority} can be overridden in the constructor.
        rr�r�N)rsr	rqr�r�rrMrQrrr�test_authorityOverride|s���z0EDNSMessageSpecificsTests.test_authorityOverridecCr0)r2rrlr_r�N)rsr	rqrvrrsrQrrr�test_additionalOverride�s��z1EDNSMessageSpecificsTests.test_additionalOverridecC�|�dt|����dS)z�
        L{dns._EDNSMessage.__repr__} omits field values and sections which are
        identical to their defaults. The id field value is always shown.
        z<_EDNSMessage id=0>N�rr3rsrrrrr4�r5z+EDNSMessageSpecificsTests.test_reprDefaultsc
Cs.|jddddddddd�}|�dt|��dS)zR
        L{dns._EDNSMessage.__repr__} displays flags if they are L{True}.
        T)r6r7r8r9r:rr,r�z`<_EDNSMessage id=0 flags=answer,auth,trunc,recDes,recAv,authenticData,checkingDisabled,dnssecOK>N�rsrr3r'rrrr<�s�
�z-EDNSMessageSpecificsTests.test_reprFlagsIfSetcCs(|jdddddd�}|�dt|��dS)	zp
        L{dns._EDNSMessage.__repr__} displays field values if they differ from
        their defaults.
        r7r|r=r>r�)r?r@rArBr�zA<_EDNSMessage id=10 opCode=20 rCode=30 maxSize=40 ednsVersion=50>Nr7r'rrrrC�s
�z2EDNSMessageSpecificsTests.test_reprNonDefautFieldscCsD|��}gd�|_gd�|_gd�|_gd�|_|�dt|��dS)rDrErFrHrKzc<_EDNSMessage id=0 queries=[1, 2, 3] answers=[4, 5, 6] authority=[7, 8, 9] additional=[10, 11, 12]>N)rsrnrprMrsrr3r'rrrrN�rOz5EDNSMessageSpecificsTests.test_reprNonDefaultSectionscCsPGdd�d�}t��}||_t�}|�t|j|�}|�|fif|j|j	f�dS)z�
        L{dns._EDNSMessage.fromString} calls L{dns._EDNSMessage._messageFactory}
        to create a new L{dns.Message} instance which is used to decode the
        supplied bytes.
        c@r))zUEDNSMessageSpecificsTests.test_fromStrCallsMessageFactory.<locals>.FakeMessageFactory�/
            Fake message factory.
            c_s
t||��)z�
                Fake fromStr method which raises the arguments it was passed.

                @param args: positional arguments
                @param kwargs: keyword arguments
                �r�r�rrrrm�s
z]EDNSMessageSpecificsTests.test_fromStrCallsMessageFactory.<locals>.FakeMessageFactory.fromStrN�r&r'r(r/rmrrrr�FakeMessageFactory�r0r;N)
r	r*�_messageFactoryr2r"r�rmrrqrr)rr;r(�
dummyBytesr�rrr�test_fromStrCallsMessageFactory�sz9EDNSMessageSpecificsTests.test_fromStrCallsMessageFactorycsft��}Gdd�d�}|���fdd�|_dd�}||_|�t|jd�}|��fif|j|j	f�dS)	z~
        L{dns._EDNSMessage.fromString} calls L{dns._EDNSMessage._fromMessage}
        with a L{dns.Message} instance
        c@r))zREDNSMessageSpecificsTests.test_fromStrCallsFromMessage.<locals>.FakeMessageFactoryr8cSsdS)zw
                A noop fake version of fromStr

                @param bytes: the bytes to be decoded
                Nr)rrPrrrrm�zZEDNSMessageSpecificsTests.test_fromStrCallsFromMessage.<locals>.FakeMessageFactory.fromStrNr:rrrrr;�r0r;c��Sr�rr��fakeMessagerr�<lambda>r?zHEDNSMessageSpecificsTests.test_fromStrCallsFromMessage.<locals>.<lambda>c_�
t||��r�r9r�rrr�fakeFromMessage
rzOEDNSMessageSpecificsTests.test_fromStrCallsFromMessage.<locals>.fakeFromMessager�N)
r	r*r<�_fromMessager"r�rmrrqrr)rr(r;rEr�rrAr�test_fromStrCallsFromMessage�sz6EDNSMessageSpecificsTests.test_fromStrCallsFromMessagecCs@t��}dd�}||_|�t|j�}|�dif|j|jf�dS)zP
        L{dns._EDNSMessage.toStr} calls L{dns._EDNSMessage._toMessage}
        c_rDr�r9r�rrr�
fakeToMessagerzIEDNSMessageSpecificsTests.test_toStrCallsToMessage.<locals>.fakeToMessagerN)	r	r*�
_toMessager"r�rwrrqrr)rr(rHr�rrr�test_toStrCallsToMessages
z2EDNSMessageSpecificsTests.test_toStrCallsToMessagecsFt��}t��G�fdd�d���fdd�}||_|��|���dS)z}
        L{dns._EDNSMessage.toStr} calls C{toStr} on the message returned by
        L{dns._EDNSMessage._toMessage}.
        cseZdZdZ�fdd�ZdS)zLEDNSMessageSpecificsTests.test_toStrCallsToMessageToStr.<locals>.FakeMessagez&
            Fake Message
            cr@)zk
                Fake toStr which returns dummyBytes.

                @return: dummyBytes
                rr�r=rrrw.szREDNSMessageSpecificsTests.test_toStrCallsToMessageToStr.<locals>.FakeMessage.toStrN)r&r'r(r/rwrrKrr�FakeMessage)srLcs��Sr�rr�)rLrrrH6szNEDNSMessageSpecificsTests.test_toStrCallsToMessageToStr.<locals>.fakeToMessageN)r	r*r2rIrrw)rr(rHr)rLr=r�test_toStrCallsToMessageToStr!s
z7EDNSMessageSpecificsTests.test_toStrCallsToMessageToStrN)r&r'r(r/r	r*rsr.r�r�r�r/r1r3r4r4r<rCrNr>rGrJrMrrrrr-Bs&

r-c@s�eZdZdZejZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�EDNSMessageEqualityTestsz�
    Tests for equality between L{dns._EDNSMessage} instances.

    These tests will not work with L{dns.Message} because it does not use
    L{twisted.python.util.FancyEqMixin}.
    cCrt)zc
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        id.
        r�rur�NrvrrrrrxHryz EDNSMessageEqualityTests.test_idcCrt)zl
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        answer flag.
        TrzFNrvrrrrr{Sryz$EDNSMessageEqualityTests.test_answercCs0|�|jtjd�|jtjd�|jtjd��dS)zg
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        opCode.
        r|N)rwrsr	r��
OP_INVERSErrrrr}^s
�z$EDNSMessageEqualityTests.test_opCodecCrt)zj
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        auth flag.
        Tr�FNrvrrrrr�iryz"EDNSMessageEqualityTests.test_authcCrt)zk
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        trunc flag.
        Tr�FNrvrrrrr�tryz#EDNSMessageEqualityTests.test_trunccCrt)zl
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        recDes flag.
        Tr~FNrvrrrrrryz$EDNSMessageEqualityTests.test_recDescCrt)zk
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        recAv flag.
        Tr�FNrvrrrrr��ryz#EDNSMessageEqualityTests.test_recAvcCrt)zf
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        rCode.
        r,r�rNrvrrrrr��ryz#EDNSMessageEqualityTests.test_rCodecCs*|�|jdd�|jdd�|jdd��dS)zl
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        ednsVersion.
        r��r�Nrvrrrrr.�ryz)EDNSMessageEqualityTests.test_ednsVersioncCrt)zi
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        dnssecOK.
        Tr�FNrvrrrrr��ryz&EDNSMessageEqualityTests.test_dnssecOKcCrt)zt
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        authenticData flags.
        TrFNrvrrrrr��ryz+EDNSMessageEqualityTests.test_authenticDatacCrt)zw
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        checkingDisabled flags.
        Tr.FNrvrrrrr��ryz.EDNSMessageEqualityTests.test_checkingDisabledcCrt)zh
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        maxSize.
        ir�rNrvrrrrr��ryz%EDNSMessageEqualityTests.test_maxSizecCr�)zh
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        queries.
        rr�r�Nr�rrrrr��r�z%EDNSMessageEqualityTests.test_queriesc
Cr�)zh
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        answers.
        rrlr_r�r�r�Nr�rrrrr��r�z%EDNSMessageEqualityTests.test_answersc
Cr�)zr
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        authority records.
        rr�r�r�Nr�rrrrr��r�z'EDNSMessageEqualityTests.test_authorityc
Cr�)zs
        Two L{dns._EDNSMessage} instances compare equal if they have the same
        additional records.
        rrlr_r�r�Nr�rrrrr�
r�z(EDNSMessageEqualityTests.test_additionalN)r&r'r(r/r	r*rsrxr{r}r�r�rr�r�r.r�r�r�r�r�r�r�r�rrrrrN>s(rNc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�StandardEncodingTestsMixina�
    Tests for the encoding and decoding of various standard (not EDNS) messages.

    These tests should work with both L{dns._EDNSMessage} and L{dns.Message}.

    TestCase classes that use this mixin must provide a C{messageFactory} method
    which accepts any argment supported by L{dns._EDNSMessage.__init__}.

    EDNS specific arguments may be discarded if not supported by the message
    class under construction.
    cC�(|�|jdit������t���dS)z2
        An empty message can be encoded.
        Nr)rrsr�rrrwrPrrrr�test_emptyMessageEncode/s�z2StandardEncodingTestsMixin.test_emptyMessageEncodecC�6|��}|�t���|�||jdit�����dS)z@
        An empty message byte sequence can be decoded.
        Nr)rsrmr�rPrrrr'rrr�test_emptyMessageDecode7s z2StandardEncodingTestsMixin.test_emptyMessageDecodecCrR)zA
        A fully populated query message can be encoded.
        Nr)rrsr�rrrwrPrrrr�test_completeQueryEncode@s�z3StandardEncodingTestsMixin.test_completeQueryEncodecCs8|��}|�t���f|�||jdit�����dS)zG
        A fully populated message byte string can be decoded.
        Nr)rsrmr�rPrrrr'rrr�test_completeQueryDecodeIs z3StandardEncodingTestsMixin.test_completeQueryDecodecCs�d�dd�td�D��}t�|�}tjdtj|d�}|��}|j�|�|�	�}|��}|�
|�|�|jdjtj�|�
|jdjj|�dS)	zu
        A I{NULL} record with an arbitrary payload can be encoded and decoded as
        part of a message.
        r�cSrWrrXrYrrrr\Wr]z8StandardEncodingTestsMixin.test_NULL.<locals>.<listcomp>rSr^r_rN)r`r�r	r�rqrarsrprbrwrmrNrkrrcrrrr�Rs

z$StandardEncodingTestsMixin.test_NULLcCrR)zv
        If the message C{authoritative} attribute is set to 0, the encoded bytes
        will have AA bit 0.
        Nr)rrsr�rrrwrPrrrr�"test_nonAuthoritativeMessageEncoded��z=StandardEncodingTestsMixin.test_nonAuthoritativeMessageEncodecCrT)z�
        The L{dns.RRHeader} instances created by a message from a
        non-authoritative message byte string are marked as not authoritative.
        Nr)rsrmr�rPrrrr'rrr�"test_nonAuthoritativeMessageDecoden� z=StandardEncodingTestsMixin.test_nonAuthoritativeMessageDecodecCrR)zv
        If the message C{authoritative} attribute is set to 1, the encoded bytes
        will have AA bit 1.
        Nr)rrsr�rrrwrPrrrr�test_authoritativeMessageEncodexrYz:StandardEncodingTestsMixin.test_authoritativeMessageEncodecCrT)z�
        The message and its L{dns.RRHeader} instances created by C{decode} from
        an authoritative message byte string, are marked as authoritative.
        Nr)rsrmr�rPrrrr'rrr�test_authoritativeMessageDecode�r[z:StandardEncodingTestsMixin.test_authoritativeMessageDecodecCrR)zm
        If the message C{trunc} attribute is set to 1 the encoded bytes will
        have TR bit 1.
        Nr)rrsr�rrrwrPrrrr�test_truncatedMessageEncode�rYz6StandardEncodingTestsMixin.test_truncatedMessageEncodecCrT)zn
        The message instance created by decoding a truncated message is marked
        as truncated.
        Nr)rsrmr�rPrrrr'rrr�test_truncatedMessageDecode�r[z6StandardEncodingTestsMixin.test_truncatedMessageDecodeN)r&r'r(r/rSrUrVrWr�rXrZr\r]r^r_rrrrrQ"s			




rQc@r')� EDNSMessageStandardEncodingTestszq
    Tests for the encoding and decoding of various standard (non-EDNS) messages
    by L{dns._EDNSMessage}.
    Nr)rrrrr`�r+r`c@seZdZdZedd��ZdS)�MessageStandardEncodingTestszl
    Tests for the encoding and decoding of various standard (non-EDNS) messages
    by L{dns.Message}.
    cKsl|�dg�}|�dg�}|�dg�}|�dg�}|�dd�tjdi|��}||_||_||_||_t|�S)a�
        This function adapts constructor arguments expected by
        _EDNSMessage.__init__ to arguments suitable for use with the
        Message.__init__.

        Also handles the fact that unlike L{dns._EDNSMessage},
        L{dns.Message.__init__} does not accept queries, answers etc as
        arguments.

        Also removes any L{dns._EDNSMessage} specific arguments.

        @param args: The positional arguments which will be passed to
            L{dns.Message.__init__}.

        @param kwargs: The keyword arguments which will be stripped of EDNS
            specific arguments before being passed to L{dns.Message.__init__}.

        @return: An L{dns.Message} instance.
        rnrprMrsr�Nr)rpr	r_rnrprMrsr
)rrrnrprMrsr(rrrrs�sz+MessageStandardEncodingTests.messageFactoryN)r&r'r(r/�staticmethodrsrrrrra�srac@sfeZdZdZejZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�ZdS)�EDNSMessageEDNSEncodingTestszz
    Tests for the encoding and decoding of various EDNS messages.

    These test will not work with L{dns.Message}.
    cCs(|��}|�t���|�|jg�dS)z�
        The L(_EDNSMessage} instance created by L{dns._EDNSMessage.decode} from
        an EDNS query never includes OPT records in the additional section.
        N)rsrmrrPrrsr'rrr�&test_ednsMessageDecodeStripsOptRecords�szCEDNSMessageEDNSEncodingTests.test_ednsMessageDecodeStripsOptRecordscCsHt��}tjdd�tjdd�g|_t��}|�|���|�|j�dS)a
        An L(_EDNSMessage} instance created from a byte string containing
        multiple I{OPT} records will discard all the C{OPT} records.

        C{ednsVersion} will be set to L{None}.

        @see: U{https://tools.ietf.org/html/rfc6891#section-6.1.1}
        r�r�r�N)	r	r_r�rsr*rmrw�assertIsNoner�)rr(�ednsMessagerrr�(test_ednsMessageDecodeMultipleOptRecords�s
	zEEDNSMessageEDNSEncodingTests.test_ednsMessageDecodeMultipleOptRecordscCsjt��}|�t���tj�|�}g}dD]}t||�t||�ur&|�|�q|r3|�	d|f�dSdS)z�
        L{dns._EDNSMessage._fromMessage} returns an L{_EDNSMessage} instance
        whose queries, answers, authority and additional lists are copies (not
        references to) the original message lists.
        )rnrprMrsz\Message and _EDNSMessage shared references to the following section lists after decoding: %sN)
r	r_rmrrPr*rFr
rb�fail)r�standardMessagerf�
duplicatesrrrr�test_fromMessageCopiesSections�s
����z;EDNSMessageEDNSEncodingTests.test_fromMessageCopiesSectionscCs&tjdd�}|��|�|jg�dS)zf
        L{dns._EDNSMessage.toStr} makes no in place changes to the message
        instance.
        r�rPN)r	r*rwrrs)rrfrrr�test_toMessageCopiesSectionssz9EDNSMessageEDNSEncodingTests.test_toMessageCopiesSectionscCs�t�}tjdd�}|�|�t��}|�d�|�|�t��}|g|_g}|�	tj
�|�j�|j�	tjtj
d��|�	tj
�|�j�|j�dtjtj
d��|�	tj
�|�j�|�dgd|�dS)a
        L{dns._EDNSMessage} can decode OPT records, regardless of their position
        in the additional records section.

        "The OPT RR MAY be placed anywhere within the additional data section."

        @see: U{https://tools.ietf.org/html/rfc6891#section-6.1.1}
        r�r�r)rfr�N)rr	r�rWrqr�rSr_rsrbr*rFr�rt�insertr)rr��	optRecord�optRRHeaderr(�actualMessagesrrr�test_optHeaderPositions



z3EDNSMessageEDNSEncodingTests.test_optHeaderPositioncCrT)z�
        The L(_EDNSMessage} instance created by L{dns._EDNSMessage.fromStr}
        derives its edns specific values (C{ednsVersion}, etc) from the supplied
        OPT record.
        Nr)rsrmrrPrrrr'rrr�test_ednsDecode9s z,EDNSMessageEDNSEncodingTests.test_ednsDecodecCrR)z�
        The L(_EDNSMessage} instance created by L{dns._EDNSMessage.toStr}
        encodes its edns specific values (C{ednsVersion}, etc) into an OPT
        record added to the additional section.
        Nr)rrsrrrrwrPrrrr�test_ednsEncodeD��z,EDNSMessageEDNSEncodingTests.test_ednsEncodecCrR)z�
        The L(_EDNSMessage.toStr} encodes the extended I{RCODE} (>=16) by
        assigning the lower 4bits to the message RCODE field and the upper 4bits
        to the OPT pseudo record.
        Nr)rrsr	rrrwrPrrrr�test_extendedRcodeEncodeOrtz5EDNSMessageEDNSEncodingTests.test_extendedRcodeEncodecCrT)z�
        The L(_EDNSMessage} instance created by L{dns._EDNSMessage.fromStr}
        derives RCODE from the supplied OPT record.
        Nr)rsrmr	rPrrrr'rrr�test_extendedRcodeDecodeZr[z5EDNSMessageEDNSEncodingTests.test_extendedRcodeDecodecCs4|jddd�}|��}|�d|j|jdjf�dS)z�
        Note that EXTENDED-RCODE value 0 indicates that an unextended RCODE is
        in use (values 0 through 15).

        https://tools.ietf.org/html/rfc6891#section-6.1.3
        rr)rAr�)rrN)rsrIrrArsr�)rrfrirrr�test_extendedRcodeZerods�z3EDNSMessageEDNSEncodingTests.test_extendedRcodeZeroN)r&r'r(r/r	r*rsrdrgrkrlrqrrrsrurvrwrrrrrc�s
	
rcc@r�)�ResponseFromMessageTestsz0
    Tests for L{dns._responseFromMessage}.
    cCs(t��}tjtj|d�}|�||�dS)z�
        L{dns.Message._responseFromMessage} is a constructor function which
        generates a new I{answer} message from an existing L{dns.Message} like
        instance.
        ��responseConstructorrkN)r	r_�_responseFromMessage�assertIsNot�r�request�responserrr�$test_responseFromMessageResponseTypeys
�z=ResponseFromMessageTests.test_responseFromMessageResponseTypecCs0Gdd�d�}tj}|�tj||�d�|�dS)zN
        L{dns._responseFromMessage} returns a new instance of C{cls}
        c@seZdZdZgZdS)zAResponseFromMessageTests.test_responseType.<locals>.SuppliedClassr�N)r&r'r(r?rnrrrr�
SuppliedClass�sr�ryN)r	r_rNr{)rr��
expectedClassrrr�test_responseType�s��z*ResponseFromMessageTests.test_responseTypecCs&|�dtjtjtjdd�d�j�dS)zi
        L{dns._responseFromMessage} copies the C{id} attribute of the original
        message.
        i�ruryN)rr	r{r_r?rrrr�test_responseId�s��z(ResponseFromMessageTests.test_responseIdcCs0t��}tjtj|d�}|�d|j|jf�dS)zP
        L{dns._responseFromMessage} sets the C{answer} flag to L{True}
        ry)FTN)r	r_r{rr6r}rrr�test_responseAnswer�s
�z,ResponseFromMessageTests.test_responseAnswercCsDt��}t�t�t�g}|dd�|_|�|tjtj|d�j�dS)zn
        L{dns._responseFromMessage} copies the C{queries} attribute of the
        original message.
        Nry)r	r_r2rnrr{)rr~�expectedQueriesrrr�test_responseQueries�s��z-ResponseFromMessageTests.test_responseQueriescCs$|�dtjtjt��dd�j�dS)z�
        L{dns._responseFromMessage} accepts other C{kwargs} which are assigned
        to the new message before it is returned.
        rL)rzrkrAN)rr	r{r_rArrrr�test_responseKwargs�s��z,ResponseFromMessageTests.test_responseKwargsN)
r&r'r(r/r�r�r�r�r�r�rrrrrxts
rxc@s4eZdZdZ						d
dd	�Zd
efdd�ZdS)�Fooz�
    An example class for use in L{dns._compactRepr} tests.
    It follows the pattern of initialiser settable flags, fields and sections
    found in L{dns.Message} and L{dns._EDNSMessage}.
    r�r��ASTFNcCs4||_||_||_||_||_|durg}||_dS)zK
        Set some flags, fields and sections as public attributes.
        N)�field1�field2�alwaysShowField�flagTrue�	flagFalse�section1)rr�r�r�r�r�r�rrrr��s
zFoo.__init__�returnc	Cs*tttj|d��d��d��d��d��S)zO
        Call L{dns._compactRepr} to generate a string representation.
        r�zfield1 field2 alwaysShowFieldzflagTrue flagFalsezsection1 section2)�
alwaysShow�
fieldNames�	flagNames�sectionNames)r�strr	�_compactRepr�splitrrrr�__repr__�s��zFoo.__repr__)r�r�r�TFN)r&r'r(r/r�r�r�rrrrr��s
�r�c@s4eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
S)�CompactReprTestsz(
    Tests for L{dns._compactRepr}.
    cCr5)z�
        L{dns._compactRepr} omits field values and sections which have the
        default value. Flags which are True are always shown.
        z)<Foo alwaysShowField='AS' flags=flagTrue>Nr6rrrr�
test_defaults�s�zCompactReprTests.test_defaultscCs"|jddd�}|�dt|��dS)zV
        L{dns._compactRepr} displays flags if they have a non-default value.
        T)r�r�z3<Foo alwaysShowField='AS' flags=flagTrue,flagFalse>Nr7r'rrr�test_flagsIfSets
�z CompactReprTests.test_flagsIfSetcCs"|jddd�}|�dt|��dS)zg
        L{dns._compactRepr} displays field values if they differ from their
        defaults.
        r7r|)r�r�z=<Foo field1=10 field2=20 alwaysShowField='AS' flags=flagTrue>Nr7r'rrr�test_nonDefautFieldss
�z%CompactReprTests.test_nonDefautFieldscCs0|��}gd�|_gd�|_|�dt|��dS)zY
        L{dns._compactRepr} displays sections which differ from their defaults.
        )r�r�r�)r�r�r�zO<Foo alwaysShowField='AS' flags=flagTrue section1=[1, 1, 1] section2=[2, 2, 2]>N)rsr��section2rr3r'rrr�test_nonDefaultSections!s

�z(CompactReprTests.test_nonDefaultSectionsN)
r&r'r(r/r�rsr�r�r�r�rrrrr��s	
r�r�)hr/r��ior�typingr�zope.interface.verifyr�twisted.internetrr�twisted.internet.errorrr�
twisted.namesr	�twisted.python.failurer
�twisted.python.utilrr�twisted.testr
�twisted.test.testutilsr�
twisted.trialrr�r�r�r�r�rrrrrvr�r�r�r�r�r�rrrrr�r�r�r�rrrr��SynchronousTestCaser�TestCaser*r1rKr�r#r0rror�r�r�r�r�r&rSr]rprrrsr�r�r��	Exceptionr�r�r�r�r�r�rrr	r
rrrr(r,r-rNrQr`rarcrxr�r�rrrr�<module>s��%
>Ne��ueaT".3_5iP.-11r;;
�.*
f�
�}e
�
�,V-

Anon7 - 2022
AnonSec Team