File: //lib/python3/dist-packages/twisted/protocols/haproxy/test/__pycache__/test_v2parser.cpython-38.pyc
U
W[. � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ dZ e ddd d
dfdd
�Z
e dddddfdd�Ze ddddfdd�ZG dd� dej
�ZdS )z7
Test cases for L{twisted.protocols.haproxy.V2Parser}.
� )�unittest)�address� )�InvalidProxyHeader)� _v2parsers
QUIT
� !s $s s �"�c C s | | | | | | 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�addrsZportsr r �N/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_v2parser.py�_makeHeaderIPv6 s r � s s c C s | | | | | | 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}
r r r r r �_makeHeaderIPv43 s r � 1s �s� /home/tests/mysockets/sock /home/tests/mysockets/sock c C s | | | | | 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
r r r
r r r r �_makeHeaderUnixV s r c @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� 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.
c C s t � }| �tj�|�� dS )zL
Test if a well formed IPv4 header is parsed without error.
N)r �
assertTruer �V2Parser�parse��self�headerr r r �test_happyPathIPv4{ s z V2ParserTests.test_happyPathIPv4c C s t � }| �tj�|�� dS )zL
Test if a well formed IPv6 header is parsed without error.
N)r r r r r r r r r �test_happyPathIPv6� s z V2ParserTests.test_happyPathIPv6c C s t � }| �tj�|�� dS )zL
Test if a well formed UNIX header is parsed without error.
N)r r r r r r r r r �test_happyPathUnix� s z V2ParserTests.test_happyPathUnixc C s t dd�}| �ttjj|� dS )zN
Test if an invalid signature block raises InvalidProxyError.
s )r
N�r �assertRaisesr r r r r r r r �test_invalidSignature� s
�z#V2ParserTests.test_invalidSignaturec C s t dd�}| �ttjj|� dS )zF
Test if an invalid version raises InvalidProxyError.
r �r Nr r r r r �test_invalidVersion� s
�z!V2ParserTests.test_invalidVersionc C s t dd�}| �ttjj|� dS )zF
Test if an invalid command raises InvalidProxyError.
� #r"