%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/protocols/haproxy/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/protocols/haproxy/test/__pycache__/test_wrapper.cpython-312.pyc

�

Ϫ�f�6����dZddlmZddlmZddlmZddlmZm	Z	ddl
mZddlmZdd	l
mZGd
�de	�ZGd�d
ej �ZGd�dej �Zy)z>
Test cases for L{twisted.protocols.haproxy.HAProxyProtocol}.
�)�Optional)�mock)�address)�Factory�Protocol)� StringTransportWithDisconnection)�unittest�)�HAProxyWrappingFactoryc�(�eZdZdZdd�Zdeddfd�Zy)�StaticProtocolz6
    Protocol stand-in that maintains test state.
    �returnNc�<�d|_d|_d|_d|_y)N�F)�source�destination�data�disconnected)�selfs �M/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_wrapper.py�__init__zStaticProtocol.__init__s ��26���7;�����	�!��rrc���|jsJ�|jj�|_|jj�|_|xj
|z
c_y)N)�	transport�getPeerr�getHostrr)rrs  r�dataReceivedzStaticProtocol.dataReceivedsE���~�~��~��n�n�,�,�.����>�>�1�1�3����	�	�T��	r�rN)�__name__�
__module__�__qualname__�__doc__r�bytesr�rrr
r
s���"����4�rr
c�P�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd	�Z
dd
�Zy)�HAProxyWrappingFactoryV1Testsz]
    Test L{twisted.protocols.haproxy.HAProxyWrappingFactory} with v1 PROXY
    headers.
    Nc�0�ttjt��}|j	tjddd��}t�}||_|j|�|jd�|j|j�y)�J
        Test if invalid headers result in connectionLost events.
        �TCP�	127.1.1.1�sNOTPROXY anything can go here
N�
rr�forProtocolr
�
buildProtocolr�IPv4Addressr�protocol�makeConnectionr�assertFalse�	connected�r�factory�protors    r�test_invalidHeaderDisconnectsz;HAProxyWrappingFactoryV1Tests.test_invalidHeaderDisconnects)s~��)��)<�)<�^�)L�M���%�%�����{�D�9�
��5�6�	�"�	��
���Y�'�
���?�@�����,�,�-rc�R�ttjt��}|j	tjddd��}t�}||_|j|�|jd�|jd�|j|j�y)r'r(r)r*sPROXY TCP4 1.1.1.1
s2.2.2.2 8080
Nr+r3s    r�$test_invalidPartialHeaderDisconnectszBHAProxyWrappingFactoryV1Tests.test_invalidPartialHeaderDisconnects7s���)��)<�)<�^�)L�M���%�%�����{�D�9�
��5�6�	�"�	��
���Y�'�
���4�5�
���.�/�����,�,�-rc��ttjt��}|j	tjddd��}ttjjtjj��}|j|�|j|j�tjj�|j|j�tjj�y)z�
        Before any data is received the HAProxy protocol will return the same peer
        and host as the IP connection.
        r(�	127.0.0.1r*)�hostAddress�peerAddressN)rrr,r
r-rr.rr�sentinel�host_address�peer_addressr0�assertEqualrrr3s    r� test_preDataReceived_getPeerHostz>HAProxyWrappingFactoryV1Tests.test_preDataReceived_getPeerHostFs���
)��)<�)<�^�)L�M���%�%�����{�D�9�
��5��
�
�2�2��
�
�2�2�
�	�	���Y�'��������$�-�-�*D�*D�E��������$�-�-�*D�*D�Erc�,�ttjt��}|j	tjddd��}t�}|j|�|jd�|j|j�jd�|j|j�jd�|j|jjj�jd�|j|jjj�jd�|j|j!�jd�|j|j!�jd�|j|jjj!�jd�|j|jjj!�jd�y)	�P
        Test if IPv4 headers result in the correct host and peer data.
        r(r:r*s&PROXY TCP4 1.1.1.1 2.2.2.2 8080 8888
z1.1.1.1z2.2.2.2�"N)rrr,r
r-rr.rr0rr@r�host�port�wrappedProtocolrrr3s    r�(test_validIPv4HeaderResolves_getPeerHostzFHAProxyWrappingFactoryV1Tests.test_validIPv4HeaderResolves_getPeerHostWs���)��)<�)<�^�)L�M���%�%�����{�D�9�
��5�6�	�
���Y�'�
���F�G��������-�-�y�9��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
�	
�������-�-�y�9��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
rc�,�ttjt��}|j	tjddd��}t�}|j|�|jd�|j|j�jd�|j|j�jd�|j|jjj�jd�|j|jjj�jd�|j|j!�jd�|j|j!�jd�|j|jjj!�jd�|j|jjj!�jd�y)�P
        Test if IPv6 headers result in the correct host and peer data.
        r(�::1r*sPROXY TCP6 ::1 ::2 8080 8888
z::2rDN)rrr,r
r-r�IPv6Addressrr0rr@rrErFrGrrr3s    r�(test_validIPv6HeaderResolves_getPeerHostzFHAProxyWrappingFactoryV1Tests.test_validIPv6HeaderResolves_getPeerHostws���)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�
���Y�'�
���>�?��������-�-�u�5��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
�	
�������-�-�u�5��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
rc�8�ttjt��}|j	tjddd��}t�}|j|�|jd�|j|jjd�y)�N
        Test if non-header bytes are passed to the wrapped protocol.
        r(rKr*s,PROXY TCP6 ::1 ::2 8080 8888
HTTP/1.1 / GET�HTTP/1.1 / GETN�
rrr,r
r-rrLrr0rr@rGrr3s    r�'test_overflowBytesSentToWrappedProtocolzEHAProxyWrappingFactoryV1Tests.test_overflowBytesSentToWrappedProtocol�s��)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�
���Y�'�
���L�M�����.�.�3�3�5F�Grc�Z�ttjt��}|j	tjddd��}t�}|j|�|jd�|jd�|j|jjd�y)�K
        Test if header streaming passes extra data appropriately.
        r(rKr*�PROXY TCP6 ::1 ::2 �8080 8888
HTTP/1.1 / GETrPNrQr3s    r�-test_overflowBytesSentToWrappedProtocolChunkszKHAProxyWrappingFactoryV1Tests.test_overflowBytesSentToWrappedProtocolChunks�s���)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�
���Y�'�
���1�2�
���9�:�����.�.�3�3�5F�Grc�|�ttjt��}|j	tjddd��}t�}|j|�|jd�|jd�|jd�|j|jjd�y)	zT
        Test if wrapper writes all data to wrapped protocol after parsing.
        r(rKr*rUrVs

sHTTP/1.1 / GET

NrQr3s    r�,test_overflowBytesSentToWrappedProtocolAfterzJHAProxyWrappingFactoryV1Tests.test_overflowBytesSentToWrappedProtocolAfter�s���)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�
���Y�'�
���1�2�
���9�:�
���;�'�����.�.�3�3�5N�Orr)rrr r!r6r8rArHrMrRrWrYr#rrr%r%#s5���
.�
.�F�"
�@
�@H�H�
Prr%c�\�eZdZdZdZdZdZdezezZd
d�Zd
d�Z	d
d	�Z
d
d
�Zd
d�Zd
d�Z
y)�HAProxyWrappingFactoryV2Testsz]
    Test L{twisted.protocols.haproxy.HAProxyWrappingFactory} with v2 PROXY
    headers.
    s


QUIT
!�"�s4


QUIT
!!$�"�sl/home/tests/mysockets/socks


QUIT
!1�Nc�P�ttjt��}|j	tjddd��}t�}||_|j|�|jd|jddz�|j|j�y)r'r(rKr*��N)rrr,r
r-rrLrr/r0r�
IPV4HEADERr1r2r3s    rr6z;HAProxyWrappingFactoryV2Tests.test_invalidHeaderDisconnects�s���)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�"�	��
���Y�'�
���7�T�_�_�Q�R�%8�8�9�����,�,�-rc�@�ttjt��}|j	tjddd��}t�}|j|�|j|j�|j|j�jd�|j|j�jd�|j|jj j�jd�|j|jj j�jd�|j|j#�jd�|j|j#�jd�|j|jj j#�jd�|j|jj j#�jd�y)rCr(r:r*rDN)rrr,r
r-rr.rr0rr_r@rrErFrGrrr3s    rrHzFHAProxyWrappingFactoryV2Tests.test_validIPv4HeaderResolves_getPeerHosts���)��)<�)<�^�)L�M���%�%�����{�D�9�
��5�6�	�
���Y�'�
���4�?�?�+��������-�-�{�;��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
�	
�������-�-�{�;��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
rc�@�ttjt��}|j	tjddd��}t�}|j|�|j|j�|j|j�jd�|j|j�jd�|j|jj j�jd�|j|jj j�jd�|j|j#�jd�|j|j#�jd�|j|jj j#�jd�|j|jj j#�jd�y)rJr(rKr*z0:0:0:0:0:0:0:1rDN)rrr,r
r-rr.rr0r�
IPV6HEADERr@rrErFrGrrr3s    rrMzFHAProxyWrappingFactoryV2Tests.test_validIPv6HeaderResolves_getPeerHost(s���)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�
���Y�'�
���4�?�?�+��������-�-�/@�A��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
�	
�������-�-�/@�A��������-�-�t�4�����!�!�+�+�3�3�5�:�:��	
�	
����!�!�+�+�3�3�5�:�:��	
rc��ttjt��}|j	tjd��}t�}|j|�|j|j�|j|j�jd�|j|jjj�jd�|j|j!�jd�|j|jjj!�jd�y)zP
        Test if UNIX headers result in the correct host and peer data.
        s/home/test/sockets/server.socks/home/tests/mysockets/sockN)rrr,r
r-r�UNIXAddressrr0r�
UNIXHEADERr@r�namerGrrr3s    r�(test_validUNIXHeaderResolves_getPeerHostzFHAProxyWrappingFactoryV2Tests.test_validUNIXHeaderResolves_getPeerHostHs���)��)<�)<�^�)L�M���%�%���� A�B�
��5�6�	�
���Y�'�
���4�?�?�+��������-�-�/L�M�����!�!�+�+�3�3�5�:�:�)�	
�	
�������-�-�/L�M�����!�!�+�+�3�3�5�:�:�)�	
rc�R�ttjt��}|j	tjddd��}t�}|j|�|j|jdz�|j|jjd�y)rOr(rKr*rPN�rrr,r
r-rrLrr0rrbr@rGrr3s    rrRzEHAProxyWrappingFactoryV2Tests.test_overflowBytesSentToWrappedProtocol^s���)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�
���Y�'�
���4�?�?�->�>�?�����.�.�3�3�5F�Grc��ttjt��}|j	tjddd��}t�}|j|�|j|jdd�|j|jdddz�|j|jjd�y)rTr(rKr*N�rPrir3s    rrWzKHAProxyWrappingFactoryV2Tests.test_overflowBytesSentToWrappedProtocolChunksks���)��)<�)<�^�)L�M���%�%�����u�d�3�
��5�6�	�
���Y�'�
���4�?�?�3�B�/�0�
���4�?�?�2�3�/�2C�C�D�����.�.�3�3�5F�Grr)rrr r!r_rb�
_SOCK_PATHrer6rHrMrgrRrWr#rrr[r[�sf���
	�� 	��"	E��
��	��	�� .�
�@
�@
�,H�Hrr[N)r!�typingrr	r�twisted.internetr�twisted.internet.protocolrr�twisted.internet.testingr�
twisted.trial�_wrapperrr
�TestCaser%r[r#rr�<module>rtsZ�����$�7�E�"�-��X��$\P�H�$5�$5�\P�~uH�H�$5�$5�uHr

Zerion Mini Shell 1.0