o
    bJ                     @   sR   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 G dd dejZd	S )
z7
Test cases for L{twisted.protocols.haproxy.V1Parser}.
    )address)unittest   )	_v1parser)InvalidNetworkProtocolInvalidProxyHeaderMissingAddressDatac                   @   st   e Zd ZdZdddZdddZddd	Zdd
dZdddZdddZ	dddZ
dddZdddZdddZdS )V1ParserTestsz?
    Test L{twisted.protocols.haproxy.V1Parser} behaviour.
    returnNc                 C      |  ttjjd dS )zT
        Test that an exception is raised when the PROXY header is missing.
        s	   NOTPROXY N)assertRaisesr   r   V1Parserparseself r   N/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_v1parser.pytest_missingPROXYHeaderValue   
   z*V1ParserTests.test_missingPROXYHeaderValuec                 C   r   )zX
        Test that an exception is raised when the proto is not TCP or UNKNOWN.
        s   PROXY WUTPROTO N)r   r   r   r   r   r   r   r   r   test_invalidNetworkProtocol   r   z)V1ParserTests.test_invalidNetworkProtocolc                 C   r   )zU
        Test that an exception is raised when the proto has no source data.
        s   PROXY TCP4 Nr   r   r   r   r   r   r   r   r   test_missingSourceData'   r   z$V1ParserTests.test_missingSourceDatac                 C   r   )zU
        Test that an exception is raised when the proto has no destination.
        s   PROXY TCP4 127.0.0.1 8080 8888Nr   r   r   r   r   test_missingDestData1   r   z"V1ParserTests.test_missingDestDatac                 C      t jd}| |jtj t|jtjsJ t|jtjs J | 	|jj
d | 	|jjd | 	|jj
d | 	|jjd dS )zE
        Test that parsing is successful for a PROXY header.
        s(   PROXY TCP4 127.0.0.1 127.0.0.1 8080 8888	127.0.0.1  "  N)r   r   r   assertIsInstancesourcer   IPv4Address
isinstancedestinationassertEqualhostportr   infor   r   r   test_fullParsingSuccess;      z%V1ParserTests.test_fullParsingSuccessc                 C   r   )zK
        Test that parsing is successful for an IPv6 PROXY header.
        s   PROXY TCP6 ::1 ::1 8080 8888z::1r   r   N)r   r   r   r   r   r   IPv6Addressr    r!   r"   r#   r$   r%   r   r   r   test_fullParsingSuccess_IPv6J   r(   z*V1ParserTests.test_fullParsingSuccess_IPv6c                 C   s(   t jd}| |j | |j dS )zM
        Test that parsing is successful for a UNKNOWN PROXY header.
        s$   PROXY UNKNOWN anything could go hereN)r   r   r   assertIsNoner   r!   r%   r   r   r   test_fullParsingSuccess_UNKNOWNY   s
   z-V1ParserTests.test_fullParsingSuccess_UNKNOWNc                 C   s   t  }|d\}}| | | | |d\}}| | | | |d\}}| | |dus8J |dus>J | |jtj t|jtjsOJ t|j	tjsXJ | 
|jjd | 
|jjd | 
|j	jd | 
|j	jd dS )zE
        Test that parsing happens when fed a complete line.
           PROXY TCP4 127.0.0.1 127.0.0.1 	   8080 8888s   
Nr   r   r   )r   r   feedassertFalser   r   r   r   r    r!   r"   r#   r$   r   parserr&   	remainingr   r   r   test_feedParsingc   s$   




zV1ParserTests.test_feedParsingc                 C   s`   t  }|d\}}| | | | |d\}}| | | | | t|jd dS )zN
        Test that parsing fails if no newline is found in 108 bytes.
        r-   r.   sd                                                                                                       N)r   r   r/   r0   r   r   r1   r   r   r   test_feedParsingTooLongz   s   



z%V1ParserTests.test_feedParsingTooLongc                 C   s<   t  }|d\}}| | | |d | |j dS )zH
        Test that parsing leaves overflow bytes in the buffer.
        s:   PROXY TCP4 127.0.0.1 127.0.0.1 8080 8888
HTTP/1.1 GET /
s   HTTP/1.1 GET /
N)r   r   r/   
assertTruer"   r0   bufferr1   r   r   r   test_feedParsingOverflow   s   
z&V1ParserTests.test_feedParsingOverflow)r
   N)__name__
__module____qualname____doc__r   r   r   r   r'   r*   r,   r4   r5   r8   r   r   r   r   r	      s    













r	   N)r<   twisted.internetr   twisted.trialr    r   _exceptionsr   r   r   TestCaser	   r   r   r   r   <module>   s   