
    tf                     h    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ej                  Zd	S )
z7
Test cases for L{twisted.protocols.haproxy.V1Parser}.
    )address)unittest   )	_v1parser)InvalidNetworkProtocolInvalidProxyHeaderMissingAddressDatac                   b    e Zd ZdZddZddZddZddZddZdd	Z	dd
Z
ddZddZddZdS )V1ParserTestsz?
    Test L{twisted.protocols.haproxy.V1Parser} behaviour.
    returnNc                 \    |                      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selfs    k/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/protocols/haproxy/test/test_v1parser.pytest_missingPROXYHeaderValuez*V1ParserTests.test_missingPROXYHeaderValue   s5     	$	
 	
 	
 	
 	
    c                 \    |                      t          t          j        j        d           dS )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   s    r   test_invalidNetworkProtocolz)V1ParserTests.test_invalidNetworkProtocol   s5     	"$	
 	
 	
 	
 	
r   c                 \    |                      t          t          j        j        d           dS )zU
        Test that an exception is raised when the proto has no source data.
        s   PROXY TCP4 Nr   r	   r   r   r   r   s    r   test_missingSourceDataz$V1ParserTests.test_missingSourceData'   s5     	$	
 	
 	
 	
 	
r   c                 \    |                      t          t          j        j        d           dS )zU
        Test that an exception is raised when the proto has no destination.
        s   PROXY TCP4 127.0.0.1 8080 8888Nr   r   s    r   test_missingDestDataz"V1ParserTests.test_missingDestData1   s5     	$-	
 	
 	
 	
 	
r   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   infos     r   test_fullParsingSuccessz%V1ParserTests.test_fullParsingSuccess;   s     !''7
 
 	dk7+>???$+w':;;;;;$*G,?@@@@@);777)4000).<<<).55555r   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 )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)   s     r   test_fullParsingSuccess_IPv6z*V1ParserTests.test_fullParsingSuccess_IPv6J   s     !''+
 
 	dk7+>???$+w':;;;;;$*G,?@@@@@)5111)4000).666).55555r   c                     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)   s     r   test_fullParsingSuccess_UNKNOWNz-V1ParserTests.test_fullParsingSuccess_UNKNOWNY   sT     !''3
 
 	$+&&&$*+++++r   c                 l   t          j                    }|                    d          \  }}|                     |           |                     |           |                    d          \  }}|                     |           |                     |           |                    d          \  }}|                     |           |J |J |                     |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 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*   	remainings       r   test_feedParsingzV1ParserTests.test_feedParsingc   s    #%% ++&HIIi### ++l33i### ++g..i###$$$dk7+>???$+w':;;;;;$*G,?@@@@@);777)4000).<<<).55555r   c                 v   t          j                    }|                    d          \  }}|                     |           |                     |           |                    d          \  }}|                     |           |                     |           |                     t
          |j        d           dS )zN
        Test that parsing fails if no newline is found in 108 bytes.
        r3   r4   sd                                                                                                       N)r   r   r5   r6   r   r   r7   s       r   test_feedParsingTooLongz%V1ParserTests.test_feedParsingTooLongz   s     #%% ++&HIIi### ++l33i###K	
 	
 	
 	
 	
r   c                     t          j                    }|                    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   r5   
assertTruer&   r6   bufferr7   s       r   test_feedParsingOverflowz&V1ParserTests.test_feedParsingOverflow   ss     #%% ++M
 
i 	$9:::'''''r   )r   N)__name__
__module____qualname____doc__r   r   r   r   r+   r.   r1   r:   r<   r@    r   r   r   r      s         
 
 
 

 
 
 

 
 
 

 
 
 
6 6 6 66 6 6 6, , , ,6 6 6 6.
 
 
 
"
( 
( 
( 
( 
( 
(r   r   N)rD   twisted.internetr   twisted.trialr    r   _exceptionsr   r   r	   TestCaser   rE   r   r   <module>rK      s     % $ $ $ $ $ " " " " " "       X X X X X X X X X XG( G( G( G( G(H% G( G( G( G( G(r   