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_srvconnect.cpython-38.pyc
U


W[�'�@s�dZddlmZmZddlZddlmZddlmZddl	m
Z
mZddlm
Z
mZddlmZdd	lmZmZmZdd
lmZddlmZddlmZdd
lmZGdd�de�ZGdd�dej�ZGdd�dej �Z!dS)z-
Test cases for L{twisted.names.srvconnect}.
�)�absolute_import�divisionN)�verifyObject)�unittest)�defer�protocol)�DNSLookupError�ServiceNameUnknownError)�
IConnector)�client�dns�
srvconnect)�ResolverBase)�DNSNameError)�nativeString)�
MemoryReactorc@s"eZdZdZddd�Zdd�ZdS)�FakeResolvera�
    Resolver that only gives out one given result.

    Either L{results} or L{failure} must be set and will be used for
    the return value of L{_lookup}

    @ivar results: List of L{dns.RRHeader} for the desired result.
    @type results: C{list}
    @ivar failure: Failure with an exception from L{twisted.names.error}.
    @type failure: L{Failure<twisted.python.failure.Failure>}
    NcCs||_||_g|_dS�N)�results�failure�lookups)�selfrr�r�D/usr/lib/python3/dist-packages/twisted/names/test/test_srvconnect.py�__init__'szFakeResolver.__init__cCs@|j�||||f�|jdk	r0t�|jggf�St�|j�SdS)z9
        Return the result or failure on lookup.
        N)r�appendrrZsucceedZfailr)r�name�clsZqtypeZtimeoutrrr�_lookup,s
zFakeResolver._lookup)NN)�__name__�
__module__�__qualname__�__doc__rrrrrrrs
rc@s eZdZdZdd�Zdd�ZdS)�DummyFactoryzL
    Dummy client factory that stores the reason of connection failure.
    cCs
d|_dSr��reason�rrrrr<szDummyFactory.__init__cCs
||_dSrr$)r�	connectorr%rrr�clientConnectionFailed?sz#DummyFactory.clientConnectionFailedN)rr r!r"rr(rrrrr#8sr#c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd S)!�SRVConnectorTestsz/
    Tests for L{srvconnect.SRVConnector}.
    cCsF|�tdt��t�|_t�|_t�|jdd|j�|_	g|_
g|_dS)N�theResolver�xmpp-server�example.org)�patchrrr�reactorr#�factoryr
�SRVConnectorr'�randIntArgs�randIntResultsr&rrr�setUpIs
�zSRVConnectorTests.setUpcCs|j�||f�|j�d�S)a�
        Fake randint.

        Returns the first element of L{randIntResults} and records the
        arguments passed to it in L{randIntArgs}.

        @param min: Lower bound of the random number.
        @type min: L{int}

        @param max: Higher bound of the random number.
        @type max: L{int}

        @return: Fake random number from L{randIntResults}.
        @rtype: L{int}
        r)r1rr2�pop)r�min�maxrrr�_randintSszSRVConnectorTests._randintcCstt|j�dS)zF
        L{srvconnect.SRVConnector} implements L{IConnector}.
        N)rr
r'r&rrr�test_interfacegsz SRVConnectorTests.test_interfacecCsftjdddd�}tjdtjtjd|d�gtj_|j�	�|�
|jj�|�
|jj��dd�d	�dS)
zS
        Test connectTCP gets called with the address from the SRV record.
        �}�host.example.org�<�Zport�target�ttlr,�r�typerr>�payloadN�)r:r9)r�
Record_SRV�RRHeader�SRV�INrr*rr'�connect�assertIsNoner/r%�assertEqualr.�
tcpClientsr4�rrArrr�test_SRVPresentns�
�z!SRVConnectorTests.test_SRVPresentcCsDtd�tj_|j��|�|jj�|�	|j
j��dd�d�dS)zS
        Test connectTCP gets called with fallback parameters on NXDOMAIN.
        r,NrB�r,r+)
rrr*rr'rGrHr/r%rIr.rJr4r&rrr�test_SRVNotPresent~s
�z$SRVConnectorTests.test_SRVNotPresentcCs@gtj_|j��|�|jj�|�|j	j
��dd�d�dS)zW
        Test connectTCP gets called with fallback parameters on empty result.
        NrBrM)rr*rr'rGrHr/r%rIr.rJr4r&rrr�test_SRVNoResult�s
�z"SRVConnectorTests.test_SRVNoResultcCs\tj|jdd|jdd�|_t�tj_|j�	�|�
|jj�|�|jj
��dd�d�dS)zY
        connectTCP gets called with default port if the service is not defined.
        �thisbetternotexistr,�f)ZdefaultPortNrB)r,rQ)r
r0r.r/r'r	rr*rrGrHr%rIrJr4r&rrr�)test_SRVNoResultUnknownServiceDefaultPort�s�

�z;SRVConnectorTests.test_SRVNoResultUnknownServiceDefaultPortcCsBt�|jdd|j�|_t�tj_|j�	�|�
|jj�t��dS)zR
        Connect fails on no result, unknown service and no default port.
        rPr,N)
r
r0r.r/r'r	rr*rrGZ
assertTruer%Zcheckr&rrr�+test_SRVNoResultUnknownServiceNoDefaultPort�s�

z=SRVConnectorTests.test_SRVNoResultUnknownServiceNoDefaultPortcCsVtjdtjtjddd�gtj_|j��|�	|j
j�|�|j
j��dd�d�dS)zU
        Test connectTCP gets called with fallback parameters on bad result.
        r,r;Nr?rBrM)rrDZCNAMErFrr*rr'rGrHr/r%rIr.rJr4r&rrr�test_SRVBadResult�s�
�z#SRVConnectorTests.test_SRVBadResultcCshtjdddd�}tjdtjtjd|d�gtj_|j�	�|�
|jj�|jj�
t�|�|jjg�dS)zH
        Test that connecting fails when no service is present.
        i��.r;r<r,r?N)rrCrDrErFrr*rr'rGZassertIsNotNoner/r%ZtraprrIr.rJrKrrr�test_SRVNoService�s�
z#SRVConnectorTests.test_SRVNoServicecCs6gtj_|j��tjjdd}|�td�|�dS)zW
        The lookup name is a native string from service, protocol and domain.
        ���rz_xmpp-server._tcp.example.orgN)rr*rr'rGrrIr)rrrrr�test_SRVLookupName�s
z$SRVConnectorTests.test_SRVLookupNamecCs*t�|jdd|j�|_|�d|jj�dS)zq
        L{srvconnect.SRVConnector} automatically encodes unicode domain using
        C{idna} encoding.
        zxmpp-clientuéchec.example.orgzxn--chec-9oa.example.orgN)r
r0r.r/r'rIZdomainr&rrr�test_unicodeDomain�s�z$SRVConnectorTests.test_unicodeDomaincCs�t�dddd�}t�dddd�}||g|j_g|j_|�td|j�ddg|_|j�	�|�
|jdd	�|j�	�|�
|jd
d�ddg|_|j�	�|�
|jdd	�|j�	�|�
|jd
d�dS)a
        pickServer calculates running sum of weights and calls randint.

        This exercises the server selection algorithm specified in RFC 2782 by
        preparing fake L{random.randint} results and checking the values it was
        called with.
        �
rQ�host1.example.org��host2.example.org�randint�r)r��)rrZrB�)rr\N)rrCr'�orderedServers�serversr-�randomr7r2�
pickServerrIr1�rZrecord1Zrecord2rrr�test_pickServerWeights�s





z(SRVConnectorTests.test_pickServerWeightscCsvt�dddd�}t�dddd�}||g|j_g|j_|�td|j�ddg|_|�	d|j�
��|�	d	|j�
��d
S)zR
        Two records with equal priorities compare on weight (ascending).
        rZrQr[r\r]r^r�r[rQ�r]rQN�rrCr'rcrdr-rer7r2rIrfrgrrr�test_pickServerSamePrioritiess
��z/SRVConnectorTests.test_pickServerSamePrioritiescCsvt�dddd�}t�dddd�}||g|j_g|j_|�td|j�ddg|_|�	d|j�
��|�	d	|j�
��d
S)zX
        Two records with differing priorities compare on priority (ascending).
        rZrrQr[r\r]r^rirjNrkrgrrr�test_srvDifferentPrioritiess
��z-SRVConnectorTests.test_srvDifferentPrioritiesN)rr r!r"r3r7r8rLrNrOrRrSrTrVrXrYrhrlrmrrrrr)Ds 
"r))"r"Z
__future__rrreZzope.interface.verifyrZ
twisted.trialrZtwisted.internetrrZtwisted.internet.errorrr	Ztwisted.internet.interfacesr
Z
twisted.namesrrr
Ztwisted.names.commonrZtwisted.names.errorrZtwisted.python.compatrZtwisted.test.proto_helpersrrZ
ClientFactoryr#ZTestCaser)rrrr�<module>s