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 :  /usr/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 : /usr/lib/python3/dist-packages/twisted/names/test/__pycache__/test_names.cpython-310.pyc
o

�b^��@s�dZddlZddlZddlZddlmZmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZddlmZmZmZmZmZdd	lmZdd
lmZmZmZmZmZmZddl m!Z!ddl"m#Z#m$Z$dd
l%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,ddl-m.Z.dd�Z/Gdd�dej0�Z1ejddddddddd�Z2ejdddd d!d"d#d$d�Z3ejd%d&d'd(dd)dd*�Z4e1de2fe2e�d+�e�5d,�e�6d-�e�6d.d/�e�7d0d1�ej8d2d3d4�e�9d5�e�:d6�e�;d7�e�<d8d9�e�=dd:d;�e�=d<d=d>�e�=d?d@dA�e�<dB�e�>dC�ej?dDdEdF�ej@ddGdH�ejAdIdJdK�e�BdLejCdM�e�Ddd0dNdOdP�e�EdQ�ge�FdRdSdTdU�ge�dV�e�dW�ge�dX�e�dY�ge�9d�ge�dZ�gd[�d\�ZGe1de3fd]e�Hd^�e3gid\�ZIe1d_e4fd_e4ejdZd`da�ej5dbdcda�ej5dddeda�ejFdRdSdTdUdfda�gid\�ZJGdgdh�dhe.jK�ZLGdidj�dje.jK�ZMGdkdl�dle.jK�ZNGdmdn�dne.jK�ZOGdodp�dpe.jK�ZPGdqdr�dre.jK�ZQGdsdt�dte.jK�ZRGdudv�dve.jK�ZSGdwdx�dxe.jK�ZTdyZUGdzd{�d{e.jK�ZVd|ZWGd}d~�d~e.jK�ZXdS)z
Test cases for twisted.names.
�N)�partial�reduce)�BytesIO)�pack)�defer�error�reactor)�succeed)�	authority�client�common�dns�server)�Resolver)�SOA�Message�Query�Record_A�
Record_SOA�RRHeader)�DomainError)�SecondaryAuthority�SecondaryAuthorityService)�nativeString)�FilePath)�MemoryReactorClock�StringTransport�waitUntilAllDisconnected)�unittestcCsdd�|dD�S)NcSsg|]}|j�qS���payload��.0�rrr�?/usr/lib/python3/dist-packages/twisted/names/test/test_names.py�
<listcomp>"�zjustPayload.<locals>.<listcomp>rr��resultsrrr%�justPayload!sr*c@�eZdZdd�ZdS)�NoFileAuthoritycCstj�|�|||_|_dS�N)r�ResolverBase�__init__�soa�records)�selfr0r1rrr%r/&szNoFileAuthority.__init__N)�__name__�
__module__�__qualname__r/rrrr%r,%�r,�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@rArBrCrDs	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)r7shttp.tcp.test-domain.com�host.test-domain.comshost-two.test-domain.comscname.test-domain.comsanothertest-domain.com�r0r1s123.93.84.28.in-addr.arpastest.host-reverse.lookup.coms
my-domain.com�1S�rEs
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
}z
tj||dd�}Wn
tjy:Ynw|�
|j�nq||_||_tjd|fgd�|_dS)N�)�verboser<r�	127.0.0.1)�	interface��servers)r�DNSServerFactory�test_domain_com�reverse_domain�
my_domain_com�factoryr
�DNSDatagramProtocolr�	listenTCP�
addCleanup�
stopListening�getHost�port�	listenUDPr�CannotListenError�listenerTCP�listenerUDPrr�resolver)r2�pr�r�r�rrr%�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)r{�connections�	transport�loseConnectionrr)r2�connrrr%�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)�response�receivedRecords��expectedRecordsr2rr%�checkResults�sz.ServerDNSTests.namesTest.<locals>.checkResults)�addCallback)r2�queryingr�r�rr�r%�	namesTest�s
zServerDNSTests.namesTestcC� |�|j�d�tjddd�g�S)z"Test simple DNS 'A' record queries�test-domain.comrsr:rm�r�r��
lookupAddressr
r�r2rrr%�test_addressRecord1��
�z"ServerDNSTests.test_addressRecord1cC�,|�|j�d�tjddd�tjddd�g�S)z1Test DNS 'A' record queries with multiple answersrPz123.242.1.5r:rmz0.255.0.255r�r�rrr%�test_addressRecord2��
��z"ServerDNSTests.test_addressRecord2cCr�)z+Test DNS 'A' record queries with edge caseszhost-two.test-domain.comz255.255.255.254r:rm�0.0.0.0r�r�rrr%�test_addressRecord3�r�z"ServerDNSTests.test_addressRecord3cCs|�|j�d�tg�S)zTest DNS 'SOA' record queriesr�)r�r��lookupAuthority�
soa_recordr�rrr%�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.
        r7rOrjr:rmrhri)r�r��lookupMailExchanger
�	Record_MXrr�rrr%�test_mailExchangeRecords
��z&ServerDNSTests.test_mailExchangeRecordcCr�)zTest DNS 'NS' record queriesr�z39.28.189.39r:rm)r�r��lookupNameserversr
�	Record_NSr�rrr%�test_nameserverr�zServerDNSTests.test_nameservercC�"|�|j�d�tjdddd�g�S)zTest DNS 'HINFO' record queriesr�rQrRr:)rSrTrE)r�r��lookupHostInfor
�Record_HINFOr�rrr%�
test_HINFO�
���zServerDNSTests.test_HINFOcCr�)zTest DNS 'PTR' record queriesz123.93.84.28.in-addr.arpaztest.host-reverse.lookup.comrGrm)r�r��
lookupPointerr
�
Record_PTRr�rrr%�test_PTR r�zServerDNSTests.test_PTRcCr�)zTest DNS 'CNAME' record queriesr�zcanonical.name.comr:rm)r�r��lookupCanonicalNamer
�Record_CNAMEr�rrr%�
test_CNAME'r�zServerDNSTests.test_CNAMEcCr�)zTest DNS 'MB' record queriesr�zmailbox.test-domain.comr:rm)r�r��
lookupMailBoxr
�	Record_MBr�rrr%�test_MB.r�zServerDNSTests.test_MBcCr�)zTest DNS 'MG' record queriesr�zmail.group.someplacer:rm)r�r��lookupMailGroupr
�	Record_MGr�rrr%�test_MG5r�zServerDNSTests.test_MGcCr�)zTest DNS 'MR' record queriesr�zmail.redirect.or.whateverr:rm)r�r��lookupMailRenamer
�	Record_MRr�rrr%�test_MR<r�zServerDNSTests.test_MRcCr�)zTest DNS 'MINFO' record queriesr�z
r mail boxz
e mail boxr:)r[r\rE)r�r��lookupMailboxInfor
�Record_MINFOr�rrr%�
test_MINFOCr�zServerDNSTests.test_MINFOc
Cs&|�|j�d�tjdddddd�g�S)zTest DNS 'SRV' record querieszhttp.tcp.test-domain.comrerfrg�some.other.place.foolr:rm)r�r��
lookupServicer
�
Record_SRVr�rrr%�test_SRVNs
�zServerDNSTests.test_SRVcCr�)zTest DNS 'AFSDB' record queriesr�r<zafsdb.test-domain.comr:)r]r^rE)r�r��lookupAFSDatabaser
�Record_AFSDBr�rrr%�
test_AFSDBUr�zServerDNSTests.test_AFSDBcCr�)zTest DNS 'RP' record queriesr�zwhatever.i.dunnozsome.more.textr:)r_r`rE)r�r��lookupResponsibilityr
�	Record_RPr�rrr%�test_RP`r�zServerDNSTests.test_RPcCs.|�|j�d�tjdddd�tjddd�g�S)zTest DNS 'TXT' record queriesr�rUrVr:rmrZ)r�r��
lookupTextr
�
Record_TXTr�rrr%�test_TXTks
����zServerDNSTests.test_TXTc	Cs.|�|j�d�tjddd�tjdddd�g�S)zH
        L{DNSServerFactory} can serve I{SPF} resource records.
        r�rLr:rmrMrN)r�r��lookupSenderPolicyr
�
Record_SPFr�rrr%�test_spfys
���zServerDNSTests.test_spfc	Cs&|�|j�d�tjdtjddd�g�S)zTest DNS 'WKS' record queriesr�z12.54.78.12rar:rm)r�r��lookupWellKnownServicesr
�
Record_WKS�socket�IPPROTO_TCPr�rrr%�test_WKS�s
���zServerDNSTests.test_WKScCs^t�t�}tj|_|�|j�d�|tjddd�tj	ddd�tj	ddd�tj
d	d
ddd
d�g�S)NrJ�1.2.3.4rlrmz
ns1.domain�2Mz
ns2.domainrnrerfrgr�ro)�copy�my_soarCrEr�r��lookupAllRecordsr
rr�r�)r2�
result_soarrr%�test_someRecordsWithTTLs�s

��z'ServerDNSTests.test_someRecordsWithTTLscCr�)z%Test DNS 'AAAA' record queries (IPv6)r�z'AF43:5634:1294:AFCB:56AC:48EF:34C3:01FFr:rm)r�r��lookupIPV6Addressr
�Record_AAAAr�rrr%�	test_AAAA�r�zServerDNSTests.test_AAAAcCsD|�|j�d�tjddddd�tjddd	dd�tjd
dddd�g�S)
z#Test DNS 'A6' record queries (IPv6)r�rz
ABCD::4321�r:rmrXz	0:0069::0zsome.network.tldrYz$0:5634:1294:AFCB:56AC:48EF:34C3:01FFz
tra.la.la.net)r�r��lookupAddress6r
�	Record_A6r�rrr%�test_A6�s
���zServerDNSTests.test_A6cCsZtj}dd�ttjtj���D�}|D]
}|jdur||_q|�	|j
�d��dd��|�S)z9
        Test DNS 'AXFR' queries (Zone transfer)
        cSsg|]}t�|��qSr)r�r"rrr%r&�s
�z4ServerDNSTests.test_zoneTransfer.<locals>.<listcomp>Nr�cSs|ddd�fS)Nr���r)r$rrr%�<lambda>�r'z2ServerDNSTests.test_zoneTransfer.<locals>.<lambda>)
r�rCr�operator�addrxr1�valuesrEr�r��
lookupZoner�)r2�default_ttlr)r$rrr%�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�5ruzimpossible.invalid)r�
assertFailurer�r�DNSLookupError)r2r�rrr%� test_zoneTransferConnectionFails�s�z/ServerDNSTests.test_zoneTransferConnectionFailscCr�)z6Tests that unrelated zones don't mess with each other.zanothertest-domain.comr�r:rmr�r�rrr%�test_similarZonesDontInterfere�r�z-ServerDNSTests.test_similarZonesDontInterferecCs(|�|j�d�tjddddddd�g�S)	z2
        Test DNS 'NAPTR' record queries.
        r�r8rOrbrcrdr:rm)r�r��lookupNamingAuthorityPointerr
�Record_NAPTRr�rrr%�
test_NAPTR�s
���zServerDNSTests.test_NAPTRN)!r3r4r5�__doc__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�rrrr%rp�s>



rpc@r+)�HelperTestscCs@|��}t�|�}td�D]}t�|�}|�||k�|}q
dS)N�)�mktempr
�	getSerial�range�
assertTrue)r2�f�a�i�brrr%�test_serialGenerator�s

�z HelperTests.test_serialGeneratorN)r3r4r5rrrrr%r��r6r�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.comr8��i,i�i�iX)r>r?r@rArDrCrBrE��name�type�clsrE�authr!��ns.twistedmatrix.com�rrErOz
mail.mv3d.com)�
preference�exchangerEz
64.123.27.105)�addressrE)r)r�Deferred�dr��_gotResultsr�AXFRController�
controllerr
rr�INrr0�NSr��MXr��Arr1r�rrr%r��s`
�����
�zAXFRTests.setUpcCstjdddddddddd�	S)N��r<r�	�id�answer�opCode�recDes�recAvr
�rCode�trunc�maxSize)r
rr�rrr%�_makeMessage2s�zAXFRTests._makeMessagecCsH|��}t�dtjtj�g|_|j|_|j�	|d�|�
|j|j�dS)Nr)r$r
r�AXFRr�queriesr1�answersr�messageReceivedr�r))r2�mrrr%�test_bindAndTNamesStyle@s
z!AXFRTests.test_bindAndTNamesStylecCs
||_dSr-r()r2�resultrrr%rHs
zAXFRTests._gotResultscCsT|jdd�}|r |��}g|_|�d�g|_|j�|d�|s	|�|j|j�dS�Nr)	r1r$r&�popr'rr(r�r))r2r1r)rrr%�
test_DJBStyleKs�zAXFRTests.test_DJBStyleN)r3r4r5r�r$r*rr.rrrr%r�s5rc@seZdZdd�Zdd�ZdS)�ResolvConfHandlingTestscCs2|��}tj|d�}|�|jdg�|j��dS)N��resolv�rsr�)r�rrr��
dynServers�
_parseCall�cancel�r2�
resolvConfr$rrr%�test_missingWsz$ResolvConfHandlingTests.test_missingcCs@|��}t|d���tj|d�}|�|jdg�|j��dS)N�wr0r2)	r��open�closerrr�r3r4r5r6rrr%�
test_empty]s
z"ResolvConfHandlingTests.test_emptyN)r3r4r5r8r<rrrr%r/Vsr/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)rxr0�failureResultOfr��assertIsInstance�valuer)r2�
testDomain�testDomainNamer�rrr%�'test_domainErrorForNameWithCommonSuffixksz6AuthorityTests.test_domainErrorForNameWithCommonSuffixc
Cs�ttjjtftjjtt�d�gid�}|�|�tjj��\}}}|�|g�|�|tj	tjjtj
tjtdd�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�rkT�rEr!r
N)r,r�r>rr
r��successResultOfr�r�r�TYPErC)r2r
r�
additionalrrr%�test_recordMissingxs0
���	
����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}.
        r>rr<�rrN)rxr0�maxr�typeToMethodr?�queryrr@rAr)r2rBrC�unknownTyper�rrr%�test_unknownTypeNXDOMAIN�s�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<rJrJN)rKrrLrFrzrMrr�)r2rNrr
rHrrr%�test_unknownTypeMissing�s

�z&AuthorityTests.test_unknownTypeMissingc
Cs�dtjj}t�d�}ttjjtf||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.
        sexample.r�rkFrEN)r�r>rr
r�r,�getattrrFr�rrrC)r2�method�	subdomain�
nameserverr
rrrHrrr%�
_referralTest�s0

������zAuthorityTests._referralTestcC�|�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�rUr�rrr%�
test_referral�szAuthorityTests.test_referralcCrV)zT
        A referral is also generated for a request of type C{ALL_RECORDS}.
        r�NrWr�rrr%�test_allRecordsReferral�sz&AuthorityTests.test_allRecordsReferralN)r3r4r5r�rDrIrOrPrUrXrYrrrr%r=es
"
!	r=c@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}.
        rk)r,r>rrQr�)r2rRr0�
makeRecord�target�	addressesr
rrr%�_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)�rrrrr%r�$sz>AdditionalProcessingTests.assertRecordsMatch.<locals>.<lambda>)�keyN)r��sorted)r2�expected�computedr`rrr%�assertRecordsMatchs z,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	�$g|]}tj�|jtj|dd��qS�TrE�r
rrGr�rC�r#r�r\rr%r&=����z=AdditionalProcessingTests._additionalTest.<locals>.<listcomp>N)r�r>rr^rFrd)r2rRr[r]rrr
rHrrir%�_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�rON)rkrr
r��r2r]rrr%�_additionalMXTestJs�z+AdditionalProcessingTests._additionalMXTestcC�|�|jg�dS)z�
        If the name of the MX response has A records, they are included in the
        additional section of the response.
        N)rm�_Ar�rrr%�test_mailExchangeAdditionalAU�z6AdditionalProcessingTests.test_mailExchangeAdditionalAcCrn)z�
        If the name of the MX response has AAAA records, they are included in
        the additional section of the response.
        N)rm�_AAAAr�rrr%�test_mailExchangeAdditionalAAAA\rqz9AdditionalProcessingTests.test_mailExchangeAdditionalAAAAcC�|�|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)rmrorrr�rrr%�test_mailExchangeAdditionalBothc�z9AdditionalProcessingTests.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)rkr
r�rlrrr%�_additionalNSTestjsz+AdditionalProcessingTests._additionalNSTestcCrn)z�
        If the name of the NS response has A records, they are included in the
        additional section of the response.
        N)rwror�rrr%�test_nameserverAdditionalAsrqz4AdditionalProcessingTests.test_nameserverAdditionalAcCrn)z�
        If the name of the NS response has AAAA records, they are included in
        the additional section of the response.
        N)rwrrr�rrr%�test_nameserverAdditionalAAAAzrqz7AdditionalProcessingTests.test_nameserverAdditionalAAAAcCrt)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)rwrorrr�rrr%�test_nameserverAdditionalBoth�rvz7AdditionalProcessingTests.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�TrEc	rerfrgrhrirr%r&�rjz>AdditionalProcessingTests._answerCNAMETest.<locals>.<listcomp>N)r�r>rr^r
r�rFr�CNAMErCrd)r2r]rrr
rH�aliasrrir%�_answerCNAMETest�s(��
�
��z*AdditionalProcessingTests._answerCNAMETestcCrn)z�
        If the name of the CNAME response has A records, they are included in
        the answer section of the response.
        N)r}ror�rrr%�test_canonicalNameAnswerA�rqz3AdditionalProcessingTests.test_canonicalNameAnswerAcCrn)z�
        If the name of the CNAME response has AAAA records, they are included
        in the answer section of the response.
        N)r}rrr�rrr%�test_canonicalNameAnswerAAAA�rqz6AdditionalProcessingTests.test_canonicalNameAnswerAAAAcCrt)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}rorrr�rrr%�test_canonicalNameAnswerBoth�rvz6AdditionalProcessingTests.test_canonicalNameAnswerBothN)r3r4r5r�r
rror�rrr^rdrkrmrprsrurwrxryrzr}r~rr�rrrr%rZ�s&

&#	#rZc@r+)�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-)r2�args��messagesrr%rM�sz3NoInitialResponseTests.test_noAnswer.<locals>.queryc_st�t�d��S)NzCouldn't connect)r�failr��gaierror)r2r��kwargsrrr%�
queryProtocol��z;NoInitialResponseTests.test_noAnswer.<locals>.queryProtocol)r�rrurMz	fooba.comrFrr
rrr<rrr)r�_query�patchr
r|rrrr�rr'�appendr��
getHostByNamer�r�)r2rMr�r�r1r)rr�r%�
test_noAnswer�s:��
�
z$NoInitialResponseTests.test_noAnswerN)r3r4r5r�rrrr%r��r6r�c@s(eZdZdZdd�Zdd�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<sexample.orgN)rr��primary�_port�domains�domain�r2r��servicerrr%�test_constructAuthorityFromHost�sz>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.
        �192.168.1.3i�zexample.net�example.edur�example.netr<N)r�fromServerAddressAndDomainsr�r�r�r�r�)r2r�r�r�rrr%�&test_constructAuthorityFromHostAndPorts�zESecondaryAuthorityServiceTests.test_constructAuthorityFromHostAndPortcCsxd}t|��ddg�}|�|j|�|�|jdj|�|�|jdjd�|�|jdj|�|�|jdjd�dS)aQ
        L{SecondaryAuthorityService.fromServerAddressAndDomains} constructs a
        new L{SecondaryAuthorityService} from a C{bytes} 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 given
        DNS port.
        r�r�zexample.edurr<r�N)r�encoder�r�r�r�r�rrr%� test_constructAuthorityFromBytes#s�z?SecondaryAuthorityServiceTests.test_constructAuthorityFromBytesN)r3r4r5r�r�r�r�rrrr%r��s
r�c@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��
inside.comN)rr�r�r�r��r2�	secondaryrrr%�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.
        )r���r�r�r�r�N)r�fromServerAddressAndDomainr�r�r�r�r�rrr%�test_explicitPortIs�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.
        �r�r9�example.comrr�r9rqN)rr�r�_reactor�transfer�
tcpClientsr-r��
buildProtocolr�makeConnectionr�decoderrAr
rr%rr&)r2r�r�hostr�r{�timeout�bindAddress�protor��msgrrr%�
test_transferUs�
"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.
        r�r�rr<)rr
rqNsns1.example.comzadmin.example.comi@�ii�i i�%i�.r=s192.168.1.2rm)rrr
)rr!r z!Hr�T)r!r
)rr�rr�r�r�r-r�rr�rr�rrArrrr'�extendrr�toStr�dataReceivedr�lenrFr�r�)r2r�rr�r�r{r�r�r�r�rMr0r�r�datar+rrr%�test_lookupAddressssF�
�

���z*SecondaryAuthorityTests.test_lookupAddressN)r3r4r5r�r�r�r�r�rrrr%r�9s
r�sY$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�r��
setContentr
�
BindAuthority�path)r2�s�fprrr%�loadBindString�s

z!BindAuthorityTests.loadBindStringcC�|�t�|_dSr-)r��sampleBindZoner
r�rrr%r��r�zBindAuthorityTests.setUpcCs8|jj��D]}|jj|D]
}|�d|jk�qqdS)zG
        Loads the default $TTL and applies it to all records.
        �:	N)r
r1�keysr�rE)r2�dom�recrrr%�test_ttl�s
��zBindAuthorityTests.test_ttlcCs$|�d|jj�|�d|jj�dS)z,
        Loads the default $ORIGIN.
        sexample.com.�not-fqdn.example.comN)r�r
�origin�assertInr1r�rrr%�test_originFromFile�s��z&BindAuthorityTests.test_originFromFilecCsBdD]\}}|�|j�|��\\}\\|�t�|d�|j�qdS)�'
        A records are loaded.
        �)r�z10.0.0.1)�no-in.example.comz10.0.0.2r�N�rFr
r�r�r
rr!�r2r��ipr_rrr%�
test_aRecords�s���z BindAuthorityTests.test_aRecordscCs4|�|j�d��\\}\\|�t�dd�|j�dS)�*
        AAAA records are loaded.
        r��2001:db8:10::1r�N�rFr
r�r�r
r�r!�r2r_rrr%�test_aaaaRecords�s
���z#BindAuthorityTests.test_aaaaRecordscCs8|�|j�d��\\}\\|�tjdddd�|j�dS)�(
        MX records are loaded.
        r�rOzmx.example.comr�)rrrEN�rFr
r�r�r
r�r!r�rrr%�test_mxRecordss
���z!BindAuthorityTests.test_mxRecordscCs<|�|j�d��\}\\|d}|�tjddd�|j�dS)�+
        CNAME records are loaded.
        �www.example.comrr�r�r
N�rFr
r�r�r
r�r!�r2r'r_rrr%�test_cnameRecordss

���z$BindAuthorityTests.test_cnameRecordscCsL|�t��
}|�d�Wd�n1swY|�d|jjd�dS)zO
        loadBindString raises NotImplementedError on invalid records.
        sexample.com. IN LOL 192.168.0.1NzRecord type 'LOL' not supportedr)�assertRaises�NotImplementedErrorr�r��	exceptionr�)r2�errr%�test_invalidRecordClass%s�z*BindAuthorityTests.test_invalidRecordClassc	CsbdD],}|�t��}|�|d�Wd�n1swY|�t|d�|jjd�qdS)zC
        $INCLUDE and $GENERATE raise NotImplementedError.
        )s$INCLUDEs	$GENERATEs doesNotMatterNs directive not implementedr)r�r�r�r�rr�r�)r2�	directiver�rrr%�test_invalidDirectives-s�

��z)BindAuthorityTests.test_invalidDirectivesN)r3r4r5r�r�r�r�r�r�r�r�r�r�r�rrrr%r��s
r�a�zone = [
    SOA(
        # For whom we are the authority
        'example.com',

        # This nameserver's name
        mname = "dns.example.com",

        # Mailbox of individual who handles this
        rname = "root.example.com",

        # Unique serial identifying this SOA data
        serial = 86400,

        # Time interval before zone should be refreshed
        refresh = "2H",

        # Interval before failed refresh should be retried
        retry = "1H",

        # Upper limit on time interval before expiry
        expire = "1H",

        # Minimum TTL
        minimum = "3H"

    ),

    AAAA('example.com', '2001:db8:10::1'),
    A('example.com', '10.0.0.1'),
    NS('example.com', 'dns.example.com'),
    A('no-in.example.com', '10.0.0.2'),
    PTR('2.0.0.10.in-addr.arpa', 'no-in.example.com'),

    CNAME('www.example.com', 'example.com'),
    CNAME('ftp.example.com', 'example.com'),

    MX('not-fqdn.example.com', 10, 'mail.example.com'),
]
c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�PySourceAuthorityTestszA
    Tests for L{twisted.names.authority.PySourceAuthority}.
    cCsNt|���}t|jd��
}|�|�Wd�n1swYt�|j�S)a
        Create a new L{twisted.names.authority.PySourceAuthority} from C{s}.

        @param s: A string with BIND zone data in a Python source file.
        @type s: L{str}

        @return: a new bind authority
        @rtype: L{twisted.names.authority.PySourceAuthority}
        r9N)rr�r:r��writer
�PySourceAuthority)r2r�r�r�rrr%�loadPySourceStringjs

�z)PySourceAuthorityTests.loadPySourceStringcCr�r-)r��samplePySourcer
r�rrr%r�zr�zPySourceAuthorityTests.setUpcCs@dD]\}}|�|j�|��\\}\\|�t�|�|j�qdS)r�r�Nr�r�rrr%r�}s��z$PySourceAuthorityTests.test_aRecordscCs2|�|j�d��\\}\\|�t�d�|j�dS)r�r�r�Nr�r�rrr%r��s
��z'PySourceAuthorityTests.test_aaaaRecordscCs6|�|j�d��\\}\\|�tjddd�|j�dS)r�r�rOzmail.example.com)rrNr�r�rrr%r��s
���z%PySourceAuthorityTests.test_mxRecordscC�:|�|j�d��\}\\|d}|�tjdd�|j�dS)r�r�rr��rNr�r�rrr%r���

���z(PySourceAuthorityTests.test_cnameRecordscCr�)z)
        PTR records are loaded.
        s2.0.0.10.in-addr.arparr�r�N)rFr
r�r�r
r�r!r�rrr%r��r�zPySourceAuthorityTests.test_PTRcCsd}|�t|j|�dS)z1
        Input file has no zone variable
        znothing = []N)r��
ValueErrorr�)r2�badPySourcerrr%�test_badInputNoZone�sz*PySourceAuthorityTests.test_badInputNoZoneN)r3r4r5r�r�r�r�r�r�r�r�r�rrrr%r�esr�)Yr�r�r�r��	functoolsrr�ior�structr�twisted.internetrrr�twisted.internet.deferr	�
twisted.namesr
rrr
r�twisted.names.clientr�twisted.names.dnsrrrrrr�twisted.names.errorr�twisted.names.secondaryrr�twisted.python.compatr�twisted.python.filepathr�twisted.test.proto_helpersrrr�
twisted.trialrr*�
FileAuthorityr,r��reverse_soar�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rxr�ryrz�TestCaserpr�rr/r=rZr�r�r�r�r�r�r�rrrr%�<module>s� ���



�
����	�

��3������\
Z~_0Hm+

Anon7 - 2022
AnonSec Team