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: //lib/python3/dist-packages/twisted/protocols/haproxy/test/__pycache__/test_v2parser.cpython-38.pyc
U


W[.�@s�dZddlmZddlmZddlmZddlmZdZ	e	ddd	d
dfdd
�Z
e	dddddfdd�Ze	ddddfdd�ZGdd�dej
�ZdS)z7
Test cases for L{twisted.protocols.haproxy.V2Parser}.
�)�unittest)�address�)�InvalidProxyHeader)�	_v2parsers


QUIT
�!s$s s�"�cCs||||||S)aV
    Construct a version 2 IPv6 header with custom bytes.

    @param sig: The protocol signature; defaults to valid L{V2_SIGNATURE}.
    @type sig: L{bytes}

    @param verCom: Protocol version and command.  Defaults to V2 PROXY.
    @type verCom: L{bytes}

    @param famProto: Address family and protocol.  Defaults to AF_INET6/STREAM.
    @type famProto: L{bytes}

    @param addrLength: Network-endian byte length of payload.  Defaults to
        description of default addrs/ports.
    @type addrLength: L{bytes}

    @param addrs: Address payload.  Defaults to C{::1} for source and
        destination.
    @type addrs: L{bytes}

    @param ports: Source and destination ports.  Defaults to 8080 for source
        8888 for destination.
    @type ports: L{bytes}

    @return: A packet with header, addresses, and ports.
    @rtype: L{bytes}
    ���sig�verCom�famProto�
addrLength�addrsZportsrr�N/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_v2parser.py�_makeHeaderIPv6sr�sscCs||||||S)aX
    Construct a version 2 IPv4 header with custom bytes.

    @param sig: The protocol signature; defaults to valid L{V2_SIGNATURE}.
    @type sig: L{bytes}

    @param verCom: Protocol version and command.  Defaults to V2 PROXY.
    @type verCom: L{bytes}

    @param famProto: Address family and protocol.  Defaults to AF_INET/STREAM.
    @type famProto: L{bytes}

    @param addrLength: Network-endian byte length of payload.  Defaults to
        description of default addrs/ports.
    @type addrLength: L{bytes}

    @param addrs: Address payload.  Defaults to 127.0.0.1 for source and
        destination.
    @type addrs: L{bytes}

    @param ports: Source and destination ports.  Defaults to 8080 for source
        8888 for destination.
    @type ports: L{bytes}

    @return: A packet with header, addresses, and ports.
    @rtype: L{bytes}
    rr	rrr�_makeHeaderIPv43sr�1s�s�/home/tests/mysockets/sock/home/tests/mysockets/sockcCs|||||S)a�
    Construct a version 2 IPv4 header with custom bytes.

    @param sig: The protocol signature; defaults to valid L{V2_SIGNATURE}.
    @type sig: L{bytes}

    @param verCom: Protocol version and command.  Defaults to V2 PROXY.
    @type verCom: L{bytes}

    @param famProto: Address family and protocol.  Defaults to AF_UNIX/STREAM.
    @type famProto: L{bytes}

    @param addrLength: Network-endian byte length of payload.  Defaults to 108
        bytes for 2 null terminated paths.
    @type addrLength: L{bytes}

    @param addrs: Address payload.  Defaults to C{/home/tests/mysockets/sock}
        for source and destination paths.
    @type addrs: L{bytes}

    @return: A packet with header, addresses, and8 ports.
    @rtype: L{bytes}
    r)r
rrr
rrrr�_makeHeaderUnixVsrc@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�Zd2S)3�
V2ParserTestsz?
    Test L{twisted.protocols.haproxy.V2Parser} behaviour.
    cCst�}|�tj�|��dS)zL
        Test if a well formed IPv4 header is parsed without error.
        N)r�
assertTruer�V2Parser�parse��self�headerrrr�test_happyPathIPv4{sz V2ParserTests.test_happyPathIPv4cCst�}|�tj�|��dS)zL
        Test if a well formed IPv6 header is parsed without error.
        N)rrrrrrrrr�test_happyPathIPv6�sz V2ParserTests.test_happyPathIPv6cCst�}|�tj�|��dS)zL
        Test if a well formed UNIX header is parsed without error.
        N)rrrrrrrrr�test_happyPathUnix�sz V2ParserTests.test_happyPathUnixcCs tdd�}|�ttjj|�dS)zN
        Test if an invalid signature block raises InvalidProxyError.
        s)r
N�r�assertRaisesrrrrrrrr�test_invalidSignature�s
�z#V2ParserTests.test_invalidSignaturecCs tdd�}|�ttjj|�dS)zF
        Test if an invalid version raises InvalidProxyError.
        r�rNrrrrr�test_invalidVersion�s
�z!V2ParserTests.test_invalidVersioncCs tdd�}|�ttjj|�dS)zF
        Test if an invalid command raises InvalidProxyError.
        �#r"Nrrrrr�test_invalidCommand�s
�z!V2ParserTests.test_invalidCommandcCs tdd�}|�ttjj|�dS)zE
        Test if an invalid family raises InvalidProxyError.
        �@�rNrrrrr�test_invalidFamily�s
�z V2ParserTests.test_invalidFamilycCs tdd�}|�ttjj|�dS)zG
        Test if an invalid protocol raises InvalidProxyError.
        �$r'Nrrrrr�test_invalidProto�s
�zV2ParserTests.test_invalidProtocCs2tdd�}tj�|�}|�|j�|�|j�dS)zU
        Test that local does not return endpoint data for IPv4 connections.
        � r"N�rrrr�assertFalse�source�destination�rr�inforrr�test_localCommandIpv4�s
z#V2ParserTests.test_localCommandIpv4cCs2tdd�}tj�|�}|�|j�|�|j�dS)zU
        Test that local does not return endpoint data for IPv6 connections.
        r+r"N�rrrrr-r.r/r0rrr�test_localCommandIpv6�s
z#V2ParserTests.test_localCommandIpv6cCs2tdd�}tj�|�}|�|j�|�|j�dS)zU
        Test that local does not return endpoint data for UNIX connections.
        r+r"N�rrrrr-r.r/r0rrr�test_localCommandUnix�s
z#V2ParserTests.test_localCommandUnixcCsRtdd�}tj�|�}|�|j�|�|jtj�|�|j	�|�|j	tj�dS)zM
        Test that proxy returns endpoint data for IPv4 connections.
        rr"N)
rrrrrr.�assertIsInstancerZIPv4Addressr/r0rrr�test_proxyCommandIpv4�s
z#V2ParserTests.test_proxyCommandIpv4cCsRtdd�}tj�|�}|�|j�|�|jtj�|�|j	�|�|j	tj�dS)zM
        Test that proxy returns endpoint data for IPv6 connections.
        rr"N)
rrrrrr.r7rZIPv6Addressr/r0rrr�test_proxyCommandIpv6�s
z#V2ParserTests.test_proxyCommandIpv6cCsRtdd�}tj�|�}|�|j�|�|jtj�|�|j	�|�|j	tj�dS)zM
        Test that proxy returns endpoint data for UNIX connections.
        rr"N)
rrrrrr.r7rZUNIXAddressr/r0rrr�test_proxyCommandUnixs
z#V2ParserTests.test_proxyCommandUnixcCs2tdd�}tj�|�}|�|j�|�|j�dS)�V
        Test that UNSPEC does not return endpoint data for IPv4 connections.
        �r'Nr,r0rrr�test_unspecFamilyIpv4s
z#V2ParserTests.test_unspecFamilyIpv4cCs2tdd�}tj�|�}|�|j�|�|j�dS)�V
        Test that UNSPEC does not return endpoint data for IPv6 connections.
        r<r'Nr3r0rrr�test_unspecFamilyIpv6s
z#V2ParserTests.test_unspecFamilyIpv6cCs2tdd�}tj�|�}|�|j�|�|j�dS)�V
        Test that UNSPEC does not return endpoint data for UNIX connections.
        r<r'Nr5r0rrr�test_unspecFamilyUnix%s
z#V2ParserTests.test_unspecFamilyUnixcCs2tdd�}tj�|�}|�|j�|�|j�dS)r;�r'Nr,r0rrr�test_unspecProtoIpv4/s
z"V2ParserTests.test_unspecProtoIpv4cCs2tdd�}tj�|�}|�|j�|�|j�dS)r>r+r'Nr3r0rrr�test_unspecProtoIpv69s
z"V2ParserTests.test_unspecProtoIpv6cCs2tdd�}tj�|�}|�|j�|�|j�dS)r@�0r'Nr5r0rrr�test_unspecProtoUnixCs
z"V2ParserTests.test_unspecProtoUnixcCs>d}t�|}t��}|�|�\}}|�|�|�||�dS)zU
        Test that overflow bits are preserved during feed parsing for IPv4.
        �TEST DATA

TEST DATAN)rrr�feedr�assertEqual�r�	testValuer�parserr1Zoverflowrrr�test_overflowIpv4Ms

zV2ParserTests.test_overflowIpv4cCs>d}t�|}t��}|�|�\}}|�|�|�||�dS)zU
        Test that overflow bits are preserved during feed parsing for IPv6.
        rGN)rrrrHrrIrJrrr�test_overflowIpv6Ys

zV2ParserTests.test_overflowIpv6cCs>d}t�|}t��}|�|�\}}|�|�|�||�dS)zU
        Test that overflow bits are preserved during feed parsing for Unix.
        rGN)rrrrHrrIrJrrr�test_overflowUnixes

zV2ParserTests.test_overflowUnixcCs d}t��}|�t|j|�dS)zK
        Test that an initial payload of less than 16 bytes fails.
        sNEEDMOREDATAN)rrr rrH)rrKrLrrr�test_segmentTooSmallqs�z"V2ParserTests.test_segmentTooSmallN)�__name__�
__module__�__qualname__�__doc__rrrr!r#r%r(r*r2r4r6r8r9r:r=r?rArCrDrFrMrNrOrPrrrrrvs2








rN)rTZ
twisted.trialrZtwisted.internetr�_exceptionsr�rZV2_SIGNATURErrrZTestCaserrrrr�<module>s(�
#�
#�