HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/names/test/__pycache__/test_names.cpython-38.pyc
U


W[X��@s�dZddlmZmZddlZddlZddlZddlmZddl	m
Z
mZddlm
Z
ddlmZddlmZmZmZdd	lmZdd
lmZmZmZmZmZddlmZmZmZm Z m!Z!m"Z"ddl#m$Z$dd
l%m&Z&ddl'm(Z(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0m1Z1dd�Z2Gdd�dej3�Z4ej!ddddddddd�Z5ej!ddd d!d"d#d$d%d�Z6ej!d&d'd(d)dd*dd+�Z7e4de5fe5e� d,�e�8d-�e�9d.�e�9d/d0�e�:d1d2�ej;d3d4d5�e�<d6�e�=d7�e�>d8�e�?d9d:�e�@dd;d<�e�@d=d>d?�e�@d@dAdB�e�?dC�e�AdD�ejBdEdFdG�ejCddHdI�ejDdJdKdL�e�EdMejFdN�e�Gdd1dOdPdQ�e�HdR�ge�IdSdTdUdV�ge� dW�e� dX�ge� dY�e� dZ�ge�<d�ge� d[�gd\�d]�ZJe4de6fd^e�Kd_�e6gid]�ZLe4d`e7fd`e7ej d[dadb�ej8dcdddb�ej8dedfdb�ejIdSdTdUdVdgdb�gid]�ZMGdhdi�diejN�ZOGdjdk�dkejN�ZPGdldm�dmejN�ZQGdndo�doejN�ZRGdpdq�dqejN�ZSGdrds�dsejN�ZTGdtdu�duejN�ZUGdvdw�dwejN�ZVGdxdy�dyejN�ZWdzZXGd{d|�d|ejN�ZYdS)}z
Test cases for twisted.names.
�)�absolute_import�divisionN)�BytesIO)�partial�reduce)�pack)�unittest)�reactor�defer�error)�succeed)�client�server�common�	authority�dns)�SOA�Message�RRHeader�Record_A�
Record_SOA�Query)�DomainError)�Resolver)�SecondaryAuthorityService�SecondaryAuthority)�nativeString)�FilePath)�StringTransport�MemoryReactorClock�waitUntilAllDisconnectedcCsdd�|dD�S)NcSsg|]
}|j�qS���payload��.0�rr!r!�?/usr/lib/python3/dist-packages/twisted/names/test/test_names.py�
<listcomp>$szjustPayload.<locals>.<listcomp>rr!��resultsr!r!r'�justPayload#sr+c@seZdZdd�ZdS)�NoFileAuthoritycCstj�|�|||_|_dS�N)rZResolverBase�__init__�soa�records)�selfr/r0r!r!r'r.'szNoFileAuthority.__init__N)�__name__�
__module__�__qualname__r.r!r!r!r'r,&sr,�test-domain.comzroot.test-domain.com�d��i��H?&����mname�rname�serial�refresh�minimum�expire�retry�ttls93.84.28.in-addr.arpa�xi1�i~����
my-domain.comspostmaster.test-domain.com�i90i?B)r<r=r>r?r@rArBs	127.0.0.1s39.28.189.39�#v=spf1 mx/30 mx:example.org/30 -all�v=spf1 +mx a:colo�.example.com/28 -all not valid�
�host.test-domain.com�Linux�A Fast One, Dontcha know)�os�cpuscanonical.name.comsmailbox.test-domain.comsmail.group.someplace�A First piece of Text�a SecoNd pieces
ABCD::4321��s	0:0069::0ssome.network.tld�s$0:5634:1294:AFCB:56AC:48EF:34C3:01FFs
tra.la.la.net�+Some more text, haha!  Yes.    Still here?smail.redirect.or.whatevers
r mail boxs
e mail box)�rmailbx�emailbxsafsdb.test-domain.com)�subtype�hostnameswhatever.i.dunnossome.more.text)�mbox�txts12.54.78.12����u�sip+E2U�!!^.*$!sip:information@domain.tld!s'AF43:5634:1294:AFCB:56AC:48EF:34C3:01FF��?骪ssome.other.place.fool�123.242.1.5�0.255.0.255s255.255.255.254s0.0.0.0s1.2.3.4)r5shttp.tcp.test-domain.com�host.test-domain.comshost-two.test-domain.comscname.test-domain.comsanothertest-domain.com�r/r0s123.93.84.28.in-addr.arpastest.host-reverse.lookup.coms
my-domain.com�1S�rCs
ns1.domains2Ms
ns2.domain�3H�4Dc@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�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<S)=�ServerDNSTestsz/
    Test cases for DNS server and client.
    cCs�tjtttgdd�|_t�|j�}tj	d|jdd�}|�
|j�|��j
}ztj||dd�}Wntjk
rtYq"X|�
|j�q�q"||_||_tjd|fgd�|_dS)N�)�verboser�	127.0.0.1)Z	interface�Zservers)rZDNSServerFactory�test_domain_com�reverse_domain�
my_domain_com�factoryr�DNSDatagramProtocolr	Z	listenTCPZ
addCleanupZ
stopListeningZgetHost�portZ	listenUDPrZCannotListenError�listenerTCP�listenerUDPr
r�resolver)r1�pryrxrzr!r!r'�setUp�s(��
zServerDNSTests.setUpcCs6|jjdd�D]}|j��qtt|jjdd��S)zu
        Clean up any server connections associated with the
        L{DNSServerFactory} created in L{setUp}
        N)rvZconnections�	transportZloseConnectionr r	)r1Zconnr!r!r'�tearDown�szServerDNSTests.tearDowncs��fdd�}|�|�|S)aD
        Assert that the DNS response C{querying} will eventually fire with
        contains exactly a certain collection of records.

        @param querying: A L{Deferred} returned from one of the DNS client
            I{lookup} methods.

        @param expectedRecords: A L{list} of L{IRecord} providers which must be
            in the response or the test will be failed.

        @return: A L{Deferred} that fires when the assertion has been made.  It
            fires with a success result if the assertion succeeds and with a
            L{Failure} if it fails.
        cs t|�}��t��t|��dSr-)r+�assertEqual�set)ZresponseZreceivedRecords��expectedRecordsr1r!r'�checkResults�sz.ServerDNSTests.namesTest.<locals>.checkResults)�addCallback)r1Zqueryingr�r�r!r�r'�	namesTest�s
zServerDNSTests.namesTestcCs |�|j�d�tjddd�g�S)z"Test simple DNS 'A' record queries�test-domain.comrqr8rk�r�r{�
lookupAddressrr�r1r!r!r'�test_addressRecord1�s
�z"ServerDNSTests.test_addressRecord1cCs,|�|j�d�tjddd�tjddd�g�S)z1Test DNS 'A' record queries with multiple answersrNz123.242.1.5r8rkz0.255.0.255r�r�r!r!r'�test_addressRecord2�s
��z"ServerDNSTests.test_addressRecord2cCs,|�|j�d�tjddd�tjddd�g�S)z+Test DNS 'A' record queries with edge caseszhost-two.test-domain.comz255.255.255.254r8rk�0.0.0.0r�r�r!r!r'�test_addressRecord3�s
�z"ServerDNSTests.test_addressRecord3cCs|�|j�d�tg�S)zTest DNS 'SOA' record queriesr�)r�r{ZlookupAuthority�
soa_recordr�r!r!r'�test_authority�s
�zServerDNSTests.test_authorityc	Cs:|�|j�d�tjdddd�tjddd�tjddd�g�S)z�
        The DNS client can issue an MX query and receive a response including
        an MX record as well as any A record hints.
        r5rMrhr8rkrfrg)r�r{�lookupMailExchanger�	Record_MXrr�r!r!r'�test_mailExchangeRecords
��z&ServerDNSTests.test_mailExchangeRecordcCs |�|j�d�tjddd�g�S)zTest DNS 'NS' record queriesr�z39.28.189.39r8rk)r�r{�lookupNameserversr�	Record_NSr�r!r!r'�test_nameservers
�zServerDNSTests.test_nameservercCs"|�|j�d�tjdddd�g�S)zTest DNS 'HINFO' record queriesr�rOrPr8)rQrRrC)r�r{ZlookupHostInfor�Record_HINFOr�r!r!r'�
test_HINFOs
��zServerDNSTests.test_HINFOcCs |�|j�d�tjddd�g�S)zTest DNS 'PTR' record queriesz123.93.84.28.in-addr.arpaztest.host-reverse.lookup.comrErk)r�r{Z
lookupPointerr�
Record_PTRr�r!r!r'�test_PTR"s
�zServerDNSTests.test_PTRcCs |�|j�d�tjddd�g�S)zTest DNS 'CNAME' record queriesr�zcanonical.name.comr8rk)r�r{�lookupCanonicalNamer�Record_CNAMEr�r!r!r'�
test_CNAME*s
�zServerDNSTests.test_CNAMEcCs |�|j�d�tjddd�g�S)zTest DNS 'MB' record queriesr�zmailbox.test-domain.comr8rk)r�r{Z
lookupMailBoxr�	Record_MBr�r!r!r'�test_MB1s
�zServerDNSTests.test_MBcCs |�|j�d�tjddd�g�S)zTest DNS 'MG' record queriesr�zmail.group.someplacer8rk)r�r{ZlookupMailGroupr�	Record_MGr�r!r!r'�test_MG9s
�zServerDNSTests.test_MGcCs |�|j�d�tjddd�g�S)zTest DNS 'MR' record queriesr�zmail.redirect.or.whateverr8rk)r�r{ZlookupMailRenamer�	Record_MRr�r!r!r'�test_MRAs
�zServerDNSTests.test_MRcCs"|�|j�d�tjdddd�g�S)zTest DNS 'MINFO' record queriesr�z
r mail boxz
e mail boxr8)rYrZrC)r�r{ZlookupMailboxInfor�Record_MINFOr�r!r!r'�
test_MINFOIs
�zServerDNSTests.test_MINFOc
Cs&|�|j�d�tjdddddd�g�S)zTest DNS 'SRV' record querieszhttp.tcp.test-domain.comrcrdre�some.other.place.foolr8rk)r�r{Z
lookupServicer�
Record_SRVr�r!r!r'�test_SRVQs
�zServerDNSTests.test_SRVcCs"|�|j�d�tjdddd�g�S)zTest DNS 'AFSDB' record queriesr�r:zafsdb.test-domain.comr8)r[r\rC)r�r{ZlookupAFSDatabaser�Record_AFSDBr�r!r!r'�
test_AFSDBXs
�zServerDNSTests.test_AFSDBcCs"|�|j�d�tjdddd�g�S)zTest DNS 'RP' record queriesr�zwhatever.i.dunnozsome.more.textr8)r]r^rC)r�r{ZlookupResponsibilityr�	Record_RPr�r!r!r'�test_RP`s
�zServerDNSTests.test_RPcCs.|�|j�d�tjdddd�tjddd�g�S)zTest DNS 'TXT' record queriesr�rSrTr8rkrX)r�r{Z
lookupTextr�
Record_TXTr�r!r!r'�test_TXThs
����zServerDNSTests.test_TXTc	Cs.|�|j�d�tjddd�tjdddd�g�S)zH
        L{DNSServerFactory} can serve I{SPF} resource records.
        r�rJr8rkrKrL)r�r{ZlookupSenderPolicyr�
Record_SPFr�r!r!r'�test_spfss
����zServerDNSTests.test_spfc	Cs&|�|j�d�tjdtjddd�g�S)zTest DNS 'WKS' record queriesr�z12.54.78.12r_r8rk)r�r{ZlookupWellKnownServicesr�
Record_WKS�socket�IPPROTO_TCPr�r!r!r'�test_WKS�s

��zServerDNSTests.test_WKScCs^t�t�}tj|_|�|j�d�|tjddd�tj	ddd�tj	ddd�tj
d	d
ddd
d�g�S)NrH�1.2.3.4rjrkz
ns1.domainZ2Mz
ns2.domainrlrcrdrer�rm)�copy�my_soarArCr�r{�lookupAllRecordsrrr�r�)r1Z
result_soar!r!r'�test_someRecordsWithTTLs�s

��z'ServerDNSTests.test_someRecordsWithTTLscCs |�|j�d�tjddd�g�S)z%Test DNS 'AAAA' record queries (IPv6)r�z'AF43:5634:1294:AFCB:56AC:48EF:34C3:01FFr8rk)r�r{�lookupIPV6Addressr�Record_AAAAr�r!r!r'�	test_AAAA�s
�zServerDNSTests.test_AAAAcCsD|�|j�d�tjddddd�tjddd	dd�tjd
dddd�g�S)
z#Test DNS 'A6' record queries (IPv6)r�rz
ABCD::4321�r8rkrVz	0:0069::0zsome.network.tldrWz$0:5634:1294:AFCB:56AC:48EF:34C3:01FFz
tra.la.la.net)r�r{ZlookupAddress6r�	Record_A6r�r!r!r'�test_A6�s
��zServerDNSTests.test_A6cCsZtj}dd�ttjtj���D�}|D]}|jdkr&||_q&|�	|j
�d��dd��|�S)z9
        Test DNS 'AXFR' queries (Zone transfer)
        cSsg|]}t�|��qSr!)r�r$r!r!r'r(�sz4ServerDNSTests.test_zoneTransfer.<locals>.<listcomp>Nr�cSs|ddd�fS)Nr���r!)r&r!r!r'�<lambda>�rUz2ServerDNSTests.test_zoneTransfer.<locals>.<lambda>)
r�rAr�operator�addrsr0�valuesrCr�r{�
lookupZoner�)r1Zdefault_ttlr*r&r!r!r'�test_zoneTransfer�s
�z ServerDNSTests.test_zoneTransfercCs tdgd�}|�|�d�tj�S)zu
        A failed AXFR TCP connection errbacks the L{Deferred} returned
        from L{Resolver.lookupZone}.
        )znameserver.invalid�5rrzimpossible.invalid)r�
assertFailurer�rZDNSLookupError)r1r{r!r!r'� test_zoneTransferConnectionFails�s�z/ServerDNSTests.test_zoneTransferConnectionFailscCs |�|j�d�tjddd�g�S)z6Tests that unrelated zones don't mess with each other.zanothertest-domain.comr�r8rkr�r�r!r!r'�test_similarZonesDontInterfere�s
�z-ServerDNSTests.test_similarZonesDontInterferecCs(|�|j�d�tjddddddd�g�S)	z2
        Test DNS 'NAPTR' record queries.
        r�r6rMr`rarbr8rk)r�r{ZlookupNamingAuthorityPointerr�Record_NAPTRr�r!r!r'�
test_NAPTR�s
��zServerDNSTests.test_NAPTRN)!r2r3r4�__doc__r}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r!r!r!r'rn�s<	
	


rnc@seZdZdd�ZdS)�HelperTestscCs@|��}t�|�}td�D] }t�|�}|�||k�|}qdS)N�)�mktemprZ	getSerial�range�
assertTrue)r1�f�a�i�br!r!r'�test_serialGenerator�s

z HelperTests.test_serialGeneratorN)r2r3r4r�r!r!r!r'r��sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	AXFRTestscCs�d|_t��|_|j�|j�t�d|j�|_t	j
dt	jt	jddt	j
ddddddd	d
d�d�|_|jt	j
dt	jt	jd
dt	jdd
d�d�t	j
dt	jt	jd
dt	jddd
d�d�t	j
dt	jt	jd
dt	jdd
d�d�|jg|_dS)N�	fooby.comi�QFzhooj.fooby.comr6��i,i�i�iX)r<r=r>r?rBrAr@rC��name�type�clsrC�authr#��ns.twistedmatrix.com�r�rCrMz
mail.mv3d.com)�
preferenceZexchangerCz
64.123.27.105)�addressrC)r*r
ZDeferred�dr��_gotResultsr
ZAXFRController�
controllerrrr�INrr/�NSr�ZMXr��Arr0r�r!r!r'r}�s6
������zAXFRTests.setUpcCstjdddddddddd�	S)N��r:r�	�id�answerZopCodeZrecDesZrecAvr�ZrCodeZtruncZmaxSize)rrr�r!r!r'�_makeMessage�szAXFRTests._makeMessagecCsH|��}t�dtjtj�g|_|j|_|j�	|d�|�
|j|j�dS)Nr�)r�rr�AXFRr��queriesr0�answersr��messageReceivedr�r*)r1�mr!r!r'�test_bindAndTNamesStyle�s
z!AXFRTests.test_bindAndTNamesStylecCs
||_dSr-r))r1�resultr!r!r'r�szAXFRTests._gotResultscCsR|jdd�}|r>|��}g|_|�d�g|_|j�|d�q|�|j|j�dS�Nr)	r0r�r��popr�r�r�r�r*)r1r0r�r!r!r'�
test_DJBStyle
szAXFRTests.test_DJBStyleN)r2r3r4r}r�r�r�r�r!r!r!r'r��s
r�c@seZdZdd�Zdd�ZdS)�ResolvConfHandlingTestscCs2|��}tj|d�}|�|jdg�|j��dS)N�Zresolv�rqr�)r�r
rr��
dynServers�
_parseCall�cancel�r1Z
resolvConfr&r!r!r'�test_missingsz$ResolvConfHandlingTests.test_missingcCs@|��}t|d���tj|d�}|�|jdg�|j��dS)N�wr�r�)	r��open�closer
rr�r�r�r�rr!r!r'�
test_emptys
z"ResolvConfHandlingTests.test_emptyN)r2r3r4rrr!r!r!r'r�sr�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�AuthorityTestszs
    Tests for the basic response record selection code in L{FileAuthority}
    (independent of its fileness).
    cCs4t}d|jd}|�|�|��}|�|jt�dS)aJ
        L{FileAuthority} lookup methods errback with L{DomainError} if
        the requested C{name} shares a common suffix with its zone but
        is not actually a descendant of its zone, in terms of its
        sequence of DNS name labels. eg www.the-example.com has
        nothing to do with the zone example.com.
        �nonexistent.prefix-rN)rsr/�failureResultOfr��assertIsInstance�valuer)r1�
testDomain�testDomainNamer�r!r!r'�'test_domainErrorForNameWithCommonSuffix,sz6AuthorityTests.test_domainErrorForNameWithCommonSuffixc
Cs�tttj�tfttj�tt�d�gid�}|�ttj��}g}|�|j�|d\}}}|�	|g�|�	|tj
ttj�tjtjtdd�g�|�	|g�dS)a!
        If a L{FileAuthority} has a zone which includes an I{NS} record for a
        particular name and that authority is asked for another record for the
        same name which does not exist, the I{NS} record is not included in the
        authority section of the response.
        r�rirT�rCr#r�N)
r,�strr�r<rr�r�r��appendr�r�TYPErA)r1rr�r�r��
additionalr!r!r'�test_recordMissing:s2������z!AuthorityTests.test_recordMissingcCsJt}d|jd}ttj�d}|�|�t||d���}|�|j	t
�dS)z�
        Requesting a record of unknown type where no records exist for the name
        in question results in L{DomainError}.
        rrr:�r�r�N)rsr/�maxr�typeToMethodr�queryrr	r
r)r1rr�unknownTyper�r!r!r'�test_unknownTypeNXDOMAINVs�z'AuthorityTests.test_unknownTypeNXDOMAINcCs<ttj�d}|�t�td|d���\}}}|�|g�dS)z�
        Requesting a record of unknown type where other records exist for the
        name in question results in an empty answer set.
        r:rHrN)rrr�successResultOfrurrr�)r1rr�rrr!r!r'�test_unknownTypeMissingcs
��
z&AuthorityTests.test_unknownTypeMissingc
Cs�dttj�}t�d�}tttj�tf||gid�}t||�|�}|�|�\}}}|�|g�|�|tj	|tj
tj|dd�g�|�|g�dS)z�
        Create an authority and make a request against it.  Then verify that the
        result is a referral, including no records in the answers or additional
        sections, but with an I{NS} record in the authority section.
        zexample.r�riFrN)rr�r<rr�r,�getattrrr�rr�rA)r1�methodZ	subdomainZ
nameserverrr�r�rr!r!r'�
_referralTestos.
�����zAuthorityTests._referralTestcCs|�d�dS)a
        When an I{NS} record is found for a child zone, it is included in the
        authority section of the response. It is marked as non-authoritative if
        the authority is not also authoritative for the child zone (RFC 2181,
        section 6.1).
        r�N�rr�r!r!r'�
test_referral�szAuthorityTests.test_referralcCs|�d�dS)zT
        A referral is also generated for a request of type C{ALL_RECORDS}.
        r�Nrr�r!r!r'�test_allRecordsReferral�sz&AuthorityTests.test_allRecordsReferralN)r2r3r4r�r
rrrrr r!r!r!r!r'r&s

rc@s�eZdZdZe�d�Ze�d�Zdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�AdditionalProcessingTestszz
    Tests for L{FileAuthority}'s additional processing for those record types
    which require it (MX, CNAME, etc).
    s10.0.0.1sf080::1cCs8t|jj|f|jj||�g||id�}t||�tjj�S)a
        Perform a DNS lookup against a L{FileAuthority} configured with records
        as defined by C{makeRecord} and C{addresses}.

        @param method: The name of the lookup method to use; for example,
            C{"lookupNameservers"}.
        @type method: L{str}

        @param soa: A L{Record_SOA} for the zone for which the L{FileAuthority}
            is authoritative.

        @param makeRecord: A one-argument callable which accepts a name and
            returns an L{IRecord} provider.  L{FileAuthority} is constructed
            with this record.  The L{FileAuthority} is queried for a record of
            the resulting type with the given name.

        @param target: The extra name which the record returned by
            C{makeRecord} will be pointed at; this is the name which might
            require extra processing by the server so that all the available,
            useful information is returned.  For example, this is the target of
            a CNAME record or the mail exchange host pointed to by an MX record.
        @type target: L{bytes}

        @param addresses: A L{list} of records giving addresses of C{target}.

        @return: A L{Deferred} that fires with the result of the resolver
            method give by C{method}.
        ri)r,r<r�rr�)r1rr/�
makeRecord�target�	addressesrr!r!r'�_lookupSomeRecords�s
��z,AdditionalProcessingTests._lookupSomeRecordscCs(dd�}|�t||d�t||d��dS)a

        Assert that the L{RRHeader} instances given by C{expected} and
        C{computed} carry all the same information but without requiring the
        records appear in the same order.

        @param expected: A L{list} of L{RRHeader} instances giving the expected
            records.

        @param computed: A L{list} of L{RRHeader} instances giving the records
            computed by the scenario under test.

        @raise self.failureException: If the two collections of records
            disagree.
        cSs|jSr-)r�)�rrr!r!r'r��rUz>AdditionalProcessingTests.assertRecordsMatch.<locals>.<lambda>)�keyN)r��sorted)r1ZexpectedZcomputedr(r!r!r'�assertRecordsMatch�sz,AdditionalProcessingTests.assertRecordsMatchcsLdtjj�|�|t|�|�}|�|�\}}}|��fdd�|D�|�dS)aT
        Verify that certain address records are included in the I{additional}
        section of a response generated by L{FileAuthority}.

        @param method: See L{_lookupSomeRecords}

        @param makeRecord: See L{_lookupSomeRecords}

        @param addresses: A L{list} of L{IRecord} providers which the
            I{additional} section of the response is required to match
            (ignoring order).

        @raise self.failureException: If the I{additional} section of the
            response consists of different records than those given by
            C{addresses}.
        smail.c	s$g|]}tj�|jtj|dd��qS�Tr�rrrr�rA�r%r��r$r!r'r(�s��z=AdditionalProcessingTests._additionalTest.<locals>.<listcomp>N)r�r<r�r&rr*)r1rr#r%r�r�rrr!r.r'�_additionalTest�s�
��z)AdditionalProcessingTests._additionalTestcCs|�dttjd�|�dS)z�
        Verify that a response to an MX query has certain records in the
        I{additional} section.

        @param addresses: See C{_additionalTest}
        r�rMN)r/rrr��r1r%r!r!r'�_additionalMXTest�s

�z+AdditionalProcessingTests._additionalMXTestcCs|�|jg�dS)z�
        If the name of the MX response has A records, they are included in the
        additional section of the response.
        N)r1�_Ar�r!r!r'�test_mailExchangeAdditionalAsz6AdditionalProcessingTests.test_mailExchangeAdditionalAcCs|�|jg�dS)z�
        If the name of the MX response has AAAA records, they are included in
        the additional section of the response.
        N)r1�_AAAAr�r!r!r'�test_mailExchangeAdditionalAAAAsz9AdditionalProcessingTests.test_mailExchangeAdditionalAAAAcCs|�|j|jg�dS)z�
        If the name of the MX response has both A and AAAA records, they are
        all included in the additional section of the response.
        N)r1r2r4r�r!r!r'�test_mailExchangeAdditionalBothsz9AdditionalProcessingTests.test_mailExchangeAdditionalBothcCs|�dtj|�dS)z�
        Verify that a response to an NS query has certain records in the
        I{additional} section.

        @param addresses: See C{_additionalTest}
        r�N)r/rr�r0r!r!r'�_additionalNSTests
�z+AdditionalProcessingTests._additionalNSTestcCs|�|jg�dS)z�
        If the name of the NS response has A records, they are included in the
        additional section of the response.
        N)r7r2r�r!r!r'�test_nameserverAdditionalA*sz4AdditionalProcessingTests.test_nameserverAdditionalAcCs|�|jg�dS)z�
        If the name of the NS response has AAAA records, they are included in
        the additional section of the response.
        N)r7r4r�r!r!r'�test_nameserverAdditionalAAAA2sz7AdditionalProcessingTests.test_nameserverAdditionalAAAAcCs|�|j|jg�dS)z�
        If the name of the NS response has both A and AAAA records, they are
        all included in the additional section of the response.
        N)r7r2r4r�r!r!r'�test_nameserverAdditionalBoth:sz7AdditionalProcessingTests.test_nameserverAdditionalBothcsvdtjj�|�dttj�|�}|�|�\}}}tjtjjtjtj	t���dd�}|�
�fdd�|D�|g|�dS)z�
        Verify that a response to a CNAME query has certain records in the
        I{answer} section.

        @param addresses: See C{_additionalTest}
        swww.r�Trc	s$g|]}tj�|jtj|dd��qSr+r,r-r.r!r'r(Ss��z>AdditionalProcessingTests._answerCNAMETest.<locals>.<listcomp>N)r�r<r�r&rr�rrZCNAMErAr*)r1r%r�r�rr�aliasr!r.r'�_answerCNAMETestBs0��
���z*AdditionalProcessingTests._answerCNAMETestcCs|�|jg�dS)z�
        If the name of the CNAME response has A records, they are included in
        the answer section of the response.
        N)r<r2r�r!r!r'�test_canonicalNameAnswerAZsz3AdditionalProcessingTests.test_canonicalNameAnswerAcCs|�|jg�dS)z�
        If the name of the CNAME response has AAAA records, they are included
        in the answer section of the response.
        N)r<r4r�r!r!r'�test_canonicalNameAnswerAAAAbsz6AdditionalProcessingTests.test_canonicalNameAnswerAAAAcCs|�|j|jg�dS)z�
        If the name of the CNAME response has both A and AAAA records, they are
        all included in the answer section of the response.
        N)r<r2r4r�r!r!r'�test_canonicalNameAnswerBothjsz6AdditionalProcessingTests.test_canonicalNameAnswerBothN)r2r3r4r�rrr2r�r4r&r*r/r1r3r5r6r7r8r9r:r<r=r>r?r!r!r!r'r"�s$

'r"c@seZdZdd�ZdS)�NoInitialResponseTestscs��fdd�}dd�}tdgd�}||_g�|�tjd|�tjdtjtjd	d
tjdd	d�d
�g}tj	dddddddddd�	}||_
��|�|�|�
d�tj�S)z�
        If a request returns a L{dns.NS} response, but we can't connect to the
        given server, the request fails with the error returned at connection.
        cst��d��Sr�)rr�)r1�args�Zmessagesr!r'r{sz3NoInitialResponseTests.test_noAnswer.<locals>.queryc_st�t�d��S)NzCouldn't connect)r
Zfailr��gaierror)r1rA�kwargsr!r!r'�
queryProtocol�sz;NoInitialResponseTests.test_noAnswer.<locals>.queryProtocol)r�rrrrz	fooba.comr�Fr�r�r�r�r:rr�r�)rZ_queryZpatchrrwrr�r�r�rr�rr�Z
getHostByNamer�rC)r1rrEr{r0r�r!rBr'�
test_noAnswerus0����
�z$NoInitialResponseTests.test_noAnswerN)r2r3r4rFr!r!r!r'r@ssr@c@s eZdZdZdd�Zdd�ZdS)�SecondaryAuthorityServiceTestsz�
    Tests for L{SecondaryAuthorityService}, a service which keeps one or more
    authorities up to date by doing zone transfers from a master.
    cCs�d}t|ddg�}|�|j|�|�|jd�|�|jdj|�|�|jdjd�|�|jdjd�|�|jdj|�|�|jdjd�|�|jdjd�dS)a
        L{SecondaryAuthorityService} can be constructed with a C{str} giving a
        master server address and several domains, causing the creation of a
        secondary authority for each domain and that master server address and
        the default DNS port.
        �192.168.1.2�example.comzexample.orgr�rr:N)rr��primary�_port�domains�domain)r1rJ�servicer!r!r'�test_constructAuthorityFromHost�s�z>SecondaryAuthorityServiceTests.test_constructAuthorityFromHostcCs�d}d}t�||fddg�}|�|j|�|�|jd�|�|jdj|�|�|jdj|�|�|jdjd�|�|jdj|�|�|jdj|�|�|jdjd�dS)a\
        L{SecondaryAuthorityService.fromServerAddressAndDomains} constructs a
        new L{SecondaryAuthorityService} from a C{str} giving a master server
        address and DNS port and several domains, causing the creation of a secondary
        authority for each domain and that master server address and the given
        DNS port.
        z192.168.1.3i�zexample.netzexample.edurr:N)rZfromServerAddressAndDomainsr�rJrKrLrM)r1rJrxrNr!r!r'�&test_constructAuthorityFromHostAndPort�s�zESecondaryAuthorityServiceTests.test_constructAuthorityFromHostAndPortN)r2r3r4r�rOrPr!r!r!r'rG�srGc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�SecondaryAuthorityTestsz�
    L{twisted.names.secondary.SecondaryAuthority} correctly constructs objects
    with a specified IP address and optionally specified DNS port.
    cCs8tdd�}|�|jd�|�|jd�|�|jd�dS)zp
        When constructed using L{SecondaryAuthority.__init__}, the default port
        of 53 is used.
        �192.168.1.1�
inside.comr�N)rr�rJrKrM�r1�	secondaryr!r!r'�test_defaultPort�s
z(SecondaryAuthorityTests.test_defaultPortcCs:t�dd�}|�|jd�|�|jd�|�|jd�dS)z~
        When constructed using L{SecondaryAuthority.fromServerAddressAndDomain},
        the specified port is used.
        )rR��rSrRrWN)r�fromServerAddressAndDomainr�rJrKrMrTr!r!r'�test_explicitPort�s�z)SecondaryAuthorityTests.test_explicitPortcCs�t�dd�}t�|_}|��|j�d�\}}}}}|�|d�|�|d�|�||f�}t	�}	|�
|	�t�}
|
�t
|	��dd���|�t�dtjtj�g|
j�dS)z�
        An attempt is made to transfer the zone for the domain the
        L{SecondaryAuthority} was constructed with from the server address it
        was constructed with when L{SecondaryAuthority.transfer} is called.
        �rHr7rIrrHr7roN)rrXr�_reactor�transfer�
tcpClientsr�r��
buildProtocolr�makeConnectionr�decoderr
rrr�r�r�)r1rUr	�hostrxrv�timeout�bindAddress�protor~�msgr!r!r'�
test_transfer�s$�
�z%SecondaryAuthorityTests.test_transferc
Cs.t�dd�}t�|_}|��|j�d�\}}}}}|�||f�}t�}	|�	|	�t
ddd�}
|
�t|	�
�dd���tdd	d
ddd
ddd�}tddd�}t
|
jddd�}
|
j�tdt|d�td|d�tdt|d�g�|
��}|�tdt|��|�|�|�d��}|�td|dd�gggf|�dS)z�
        L{SecondaryAuthority.lookupAddress} returns a L{Deferred} that fires
        with the I{A} records the authority has cached from the primary.
        rZ�example.comrr:)r�r�roNsns1.example.comzadmin.example.comi@�ii�i i�%i�.r;s192.168.1.2rk)r�r�r�)r�r#r"z!HrIT)r#r�)rrXrr[r\r]r�r^rr_rr`rr
rrr�r��extendrrZtoStrZdataReceivedr�lenrr�r�)r1rUr	rarxrvrbrcrdr~rr/r�r��datar�r!r!r'�test_lookupAddress	sN�
�

���z*SecondaryAuthorityTests.test_lookupAddressN)r2r3r4r�rVrYrfrkr!r!r!r'rQ�s
rQsY$ORIGIN example.com.
$TTL    1w
example.com. IN SOA dns.example.com (
            2013120201 ; serial number of this zone file
            1d         ; slave refresh
            2h         ; slave retry time in case of a problem
            4w         ; slave expiration time
            1h         ; maximum caching time in case of failed lookups
            )

; A comment.
@                  IN AAAA 2001:db8:10::1
example.com.       IN A 10.0.0.1
no-in.example.com. A 10.0.0.2  ; technically wrong but used to work
not-fqdn           IN MX 10 mx.example.com
www                IN CNAME example.comc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�BindAuthorityTestsz=
    Tests for L{twisted.names.authority.BindAuthority}.
    cCs(t|���d��}|�|�t�|j�S)z�
        Create a new L{twisted.names.authority.BindAuthority} from C{s}.

        @param s: A string with BIND zone data.
        @type s: bytes

        @return: a new bind authority
        @rtype: L{twisted.names.authority.BindAuthority}
        �ascii)rr��encodeZ
setContentrZ
BindAuthority�path)r1�s�fpr!r!r'�loadBindStringQs

z!BindAuthorityTests.loadBindStringcCs|�t�|_dSr-)rr�sampleBindZoner�r�r!r!r'r}aszBindAuthorityTests.setUpcCs8|jj��D]&}|jj|D]}|�d|jk�qqdS)zG
        Loads the default $TTL and applies it to all records.
        �:	N)r�r0�keysr�rC)r1�domZrecr!r!r'�test_ttles
�zBindAuthorityTests.test_ttlcCs$|�d|jj�|�d|jj�dS)z,
        Loads the default $ORIGIN.
        sexample.com.�not-fqdn.example.comN)r�r��originZassertInr0r�r!r!r'�test_originFromFileps��z&BindAuthorityTests.test_originFromFilecCsBdD]8\}}|�|j�|��dd}|�t�|d�|j�qdS)z'
        A records are loaded.
        ))rgz10.0.0.1)sno-in.example.comz10.0.0.2rrtN)rr�r�r�rrr#)r1rvZipr'r!r!r'�
test_aRecords|s
�����z BindAuthorityTests.test_aRecordscCs4|�|j�d��dd}|�t�dd�|j�dS)z*
        AAAA records are loaded.
        rgrz2001:db8:10::1rtN)rr�r�r�rr�r#�r1r'r!r!r'�test_aaaaRecords�s
�����z#BindAuthorityTests.test_aaaaRecordscCs8|�|j�d��dd}|�tjdddd�|j�dS)z(
        MX records are loaded.
        rxrrMzmx.example.comrt)r�r�rCN)rr�r�r�rr�r#r|r!r!r'�test_mxRecords�s
�����z!BindAuthorityTests.test_mxRecordscCs6|�|j�d��dd}|�tjddd�|j�dS)z+
        CNAME records are loaded.
        swww.example.comrrIrtr�N)rr�r�r�rr�r#r|r!r!r'�test_cnameRecords�s
�����z$BindAuthorityTests.test_cnameRecordsc	Cs8|�t��}|�d�W5QRX|�d|jjd�dS)zO
        loadBindString raises NotImplementedError on invalid records.
        sexample.com. IN LOL 192.168.0.1zRecord type 'LOL' not supportedrN)�assertRaises�NotImplementedErrorrrr��	exceptionrA)r1�er!r!r'�test_invalidRecordClass�s�
�z*BindAuthorityTests.test_invalidRecordClassc
CsNdD]D}|�t��}|�|d�W5QRX|�t|d�|jjd�qdS)zC
        $INCLUDE and $GENERATE raise NotImplementedError.
        )s$INCLUDEs	$GENERATEs doesNotMatters directive not implementedrN)r�r�rrr�rr�rA)r1Z	directiver�r!r!r'�test_invalidDirectives�s

�z)BindAuthorityTests.test_invalidDirectivesN)r2r3r4r�rrr}rwrzr{r}r~rr�r�r!r!r!r'rlMs
rl)Zr�Z
__future__rrr�r�r��ior�	functoolsrrZstructrZ
twisted.trialrZtwisted.internetr	r
rZtwisted.internet.deferrZ
twisted.namesr
rrrrZtwisted.names.dnsrrrrrrZtwisted.names.errorrZtwisted.names.clientrZtwisted.names.secondaryrrZtwisted.python.compatrZtwisted.python.filepathrZtwisted.test.proto_helpersrrr r+Z
FileAuthorityr,r�Zreverse_soar�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rsr�rtruZTestCasernr�r�r�rr"r@rGrQrsrlr!r!r!r'�<module>s ���
�

�
�����	�	����5�������9
9s[%5l