+
    Dfj.                         R t ^ RIHt ^ RIHt ^RIHt ^RIHt Rt	]	RRRRR3R	 R
 llt
]	RRRRR3R R llt]	RRRR3R R llt ! R R]P                  4      tR# )z7
Test cases for L{twisted.protocols.haproxy.V2Parser}.
)address)unittest)	_v2parser)InvalidProxyHeaders   

 
QUIT
   !s    $s   "c                l    V ^8  d   QhR\         R\         R\         R\         R\         R\         R\         /#    sigverComfamProto
addrLengthaddrsportsreturnbytes)formats   "N/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_v2parser.py__annotate__r      W     #@ #@	#@#@ #@ 	#@
 #@ #@ #@    c                J    W,           V,           V,           V,           V,           # )a
  
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}
 r
   r   r   r   r   r   s   &&&&&&r   _makeHeaderIPv6r      !    F <("Z/%7%??r      s    s       c                l    V ^8  d   QhR\         R\         R\         R\         R\         R\         R\         /# r   r   )r   s   "r   r   r   6   r   r   c                J    W,           V,           V,           V,           V,           # )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_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   s   &&&&&&r   _makeHeaderIPv4r    6   r   r      1s    c                `    V ^8  d   QhR\         R\         R\         R\         R\         R\         /# )r	   r
   r   r   r   r   r   r   )r   s   "r   r   r   \   sD     #8 #8	#8#8 #8 	#8
 #8 #8r   c                <    W,           V,           V,           V,           # )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   s   &&&&&r   _makeHeaderUnixr$   \   s    F <("Z/%77r   c                     a  ] tR t^t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R  lR! ltV 3R" lR# ltV 3R$ lR% ltV 3R& lR' ltV 3R( lR) ltV 3R* lR+ ltV 3R, lR- ltV 3R. lR/ ltV 3R0 lR1 ltR2tV tR3# )4V2ParserTestsz7
Test L{twisted.protocols.haproxy.V2Parser} behaviour.
c                   < V ^8  d   QhRR/# r	   r   Nr   )r   __classdict__s   "r   r   V2ParserTests.__annotate__        : :D :r   c                v    \        4       pV P                  \        P                  P	                  V4      4       R# )z<
Test if a well formed IPv4 header is parsed without error.
N)r    
assertTruer   V2Parserparseselfheaders   & r   test_happyPathIPv4 V2ParserTests.test_happyPathIPv4   )     !"	**0089r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      r+   r   c                v    \        4       pV P                  \        P                  P	                  V4      4       R# )z<
Test if a well formed IPv6 header is parsed without error.
N)r   r-   r   r.   r/   r0   s   & r   test_happyPathIPv6 V2ParserTests.test_happyPathIPv6   r5   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      r+   r   c                v    \        4       pV P                  \        P                  P	                  V4      4       R# )z<
Test if a well formed UNIX header is parsed without error.
N)r$   r-   r   r.   r/   r0   s   & r   test_happyPathUnix V2ParserTests.test_happyPathUnix   r5   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      s     	
 	
t 	
r   c                |    \        RR7      pV P                  \        \        P                  P
                  V4       R# )z>
Test if an invalid signature block raises InvalidProxyError.
)r
   Ns               r    assertRaisesr   r   r.   r/   r0   s   & r   test_invalidSignature#V2ParserTests.test_invalidSignature   s1     !\2$$	
r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*           	
 	
T 	
r   c                |    \        RR7      pV P                  \        \        P                  P
                  V4       R# )z6
Test if an invalid version raises InvalidProxyError.
r   r   Nr@   r0   s   & r   test_invalidVersion!V2ParserTests.test_invalidVersion   1     !0$$	
r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      rE   r   c                |    \        RR7      pV P                  \        \        P                  P
                  V4       R# )z6
Test if an invalid command raises InvalidProxyError.
   #rG   Nr@   r0   s   & r   test_invalidCommand!V2ParserTests.test_invalidCommand   rJ   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      s     	
 	
D 	
r   c                |    \        RR7      pV P                  \        \        P                  P
                  V4       R# )z5
Test if an invalid family raises InvalidProxyError.
   @r   Nr@   r0   s   & r   test_invalidFamily V2ParserTests.test_invalidFamily   1     !'2$$	
r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      s     	
 	
4 	
r   c                |    \        RR7      pV P                  \        \        P                  P
                  V4       R# )z7
Test if an invalid protocol raises InvalidProxyError.
   $rS   Nr@   r0   s   & r   test_invalidProtoV2ParserTests.test_invalidProto   rV   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*           + +t +r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )zE
Test that local does not return endpoint data for IPv4 connections.
    rG   Nr    r   r.   r/   assertFalsesourcedestinationr1   r2   infos   &  r   test_localCommandIpv4#V2ParserTests.test_localCommandIpv4   J     !0!!''/%))*r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      r]   r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )zE
Test that local does not return endpoint data for IPv6 connections.
r_   rG   Nr   r   r.   r/   ra   rb   rc   rd   s   &  r   test_localCommandIpv6#V2ParserTests.test_localCommandIpv6   rh   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      r]   r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )zE
Test that local does not return endpoint data for UNIX connections.
r_   rG   Nr$   r   r.   r/   ra   rb   rc   rd   s   &  r   test_localCommandUnix#V2ParserTests.test_localCommandUnix   rh   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*           	E 	Et 	Er   c                p   \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P                  VP
                  \        P                  4       V P	                  VP                  4       V P                  VP                  \        P                  4       R# )z=
Test that proxy returns endpoint data for IPv4 connections.
r   rG   N)
r    r   r.   r/   r-   rb   assertIsInstancer   IPv4Addressrc   rd   s   &  r   test_proxyCommandIpv4#V2ParserTests.test_proxyCommandIpv4   |     !0!!''/$dkk7+>+>?(()d..0C0CDr   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*      rt   r   c                p   \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P                  VP
                  \        P                  4       V P	                  VP                  4       V P                  VP                  \        P                  4       R# )z=
Test that proxy returns endpoint data for IPv6 connections.
r   rG   N)
r   r   r.   r/   r-   rb   rv   r   IPv6Addressrc   rd   s   &  r   test_proxyCommandIpv6#V2ParserTests.test_proxyCommandIpv6   rz   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*     rt   r   c                p   \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P                  VP
                  \        P                  4       V P	                  VP                  4       V P                  VP                  \        P                  4       R# )z=
Test that proxy returns endpoint data for UNIX connections.
r   rG   N)
r$   r   r.   r/   r-   rb   rv   r   UNIXAddressrc   rd   s   &  r   test_proxyCommandUnix#V2ParserTests.test_proxyCommandUnix  rz   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*     r]   r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )F
Test that UNSPEC does not return endpoint data for IPv4 connections.
   rS   Nr`   rd   s   &  r   test_unspecFamilyIpv4#V2ParserTests.test_unspecFamilyIpv4  J     !'2!!''/%))*r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*     r]   r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )F
Test that UNSPEC does not return endpoint data for IPv6 connections.
r   rS   Nrk   rd   s   &  r   test_unspecFamilyIpv6#V2ParserTests.test_unspecFamilyIpv6  r   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   !  r]   r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )F
Test that UNSPEC does not return endpoint data for UNIX connections.
r   rS   Nrp   rd   s   &  r   test_unspecFamilyUnix#V2ParserTests.test_unspecFamilyUnix!  r   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   *       + +d +r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )r      rS   Nr`   rd   s   &  r   test_unspecProtoIpv4"V2ParserTests.test_unspecProtoIpv4*  r   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   3  r   r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )r   r_   rS   Nrk   rd   s   &  r   test_unspecProtoIpv6"V2ParserTests.test_unspecProtoIpv63  r   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   <  r   r   c                    \        RR7      p\        P                  P                  V4      pV P	                  VP
                  4       V P	                  VP                  4       R# )r      0rS   Nrp   rd   s   &  r   test_unspecProtoUnix"V2ParserTests.test_unspecProtoUnix<  r   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   E       	. 	.4 	.r   c                    Rp\        4       V,           p\        P                  ! 4       pVP                  V4      w  rEV P	                  V4       V P                  WQ4       R# )zE
Test that overflow bits are preserved during feed parsing for IPv4.
   TEST DATA

TEST DATAN)r    r   r.   feedr-   assertEqualr1   	testValuer2   parserre   overflows   &     r   test_overflowIpv4V2ParserTests.test_overflowIpv4E  N     2	 "Y.##%V,-r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   P  r   r   c                    Rp\        4       V,           p\        P                  ! 4       pVP                  V4      w  rEV P	                  V4       V P                  WQ4       R# )zE
Test that overflow bits are preserved during feed parsing for IPv6.
r   N)r   r   r.   r   r-   r   r   s   &     r   test_overflowIpv6V2ParserTests.test_overflowIpv6P  r   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   [  r   r   c                    Rp\        4       V,           p\        P                  ! 4       pVP                  V4      w  rEV P	                  V4       V P                  WQ4       R# )zE
Test that overflow bits are preserved during feed parsing for Unix.
r   N)r$   r   r.   r   r-   r   r   s   &     r   test_overflowUnixV2ParserTests.test_overflowUnix[  r   r   c                   < V ^8  d   QhRR/# r(   r   )r   r)   s   "r   r   r*   f  s     

 

d 

r   c                v    Rp\         P                  ! 4       pV P                  \        VP                  V4       R# )z;
Test that an initial payload of less than 16 bytes fails.
s   NEEDMOREDATAN)r   r.   rA   r   r   )r1   r   r   s   &  r   test_segmentTooSmall"V2ParserTests.test_segmentTooSmallf  s2     $	##%KK	
r   r   N)__name__
__module____qualname____firstlineno____doc__r3   r8   r<   rB   rH   rN   rT   rZ   rf   rl   rq   rx   r~   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classdictcell__)r)   s   @r   r&   r&      s     : :: :: :	
 	
	
 	
	
 	
	
 	
	
 	
+ ++ ++ +	E 	E	E 	E	E 	E+ ++ ++ ++ ++ ++ +	. 	.	. 	.	. 	.

 

r   r&   Ns                                  s   /home/tests/mysockets/sock                                                                                  /home/tests/mysockets/sock                                                                                  )r   twisted.internetr   twisted.trialr    r   _exceptionsr   V2_SIGNATUREr   r    r$   TestCaser&   r   r   r   <module>r      s    % "  ,B #1&#@N #6&#@N ##8Ln
H%% n
r   