Ϫf.dZddlmZddlmZddlmZddlmZdZ e ddd d d fd e d e de de de de de fdZ e ddddd fd e d e de de de de de fdZ e ddddfd e d e de de de de f dZ GddejZy)z7 Test cases for L{twisted.protocols.haproxy.V2Parser}. )address)unittest) _v2parser)InvalidProxyHeaders QUIT !s$s s"sigverComfamProto addrLengthaddrsportsreturnc$||z|z|z|z|zS)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} r r r r r rs N/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_v2parser.py_makeHeaderIPv6r#F <( "Z /% 7% ??s sc$||z|z|z|z|zS)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} rrs r_makeHeaderIPv4r6rr1ss/home/tests/mysockets/sock/home/tests/mysockets/sockc||z|z|z|zS)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\sF <( "Z /% 77rceZdZdZddZddZddZddZddZddZ dd Z dd Z dd Z dd Z dd ZddZddZddZddZddZddZddZddZddZddZddZddZddZy) V2ParserTestsz? Test L{twisted.protocols.haproxy.V2Parser} behaviour. Nctt}|jtjj |y)zL Test if a well formed IPv4 header is parsed without error. N)r assertTruerV2Parserparseselfheaders rtest_happyPathIPv4z V2ParserTests.test_happyPathIPv4)!"  **0089rctt}|jtjj |y)zL Test if a well formed IPv6 header is parsed without error. N)rr rr!r"r#s rtest_happyPathIPv6z V2ParserTests.test_happyPathIPv6r'rctt}|jtjj |y)zL Test if a well formed UNIX header is parsed without error. N)rr rr!r"r#s rtest_happyPathUnixz V2ParserTests.test_happyPathUnixr'rcztd}|jttjj |y)zN Test if an invalid signature block raises InvalidProxyError. s )r Nr assertRaisesrrr!r"r#s rtest_invalidSignaturez#V2ParserTests.test_invalidSignatures1!\2      $ $  rcztd}|jttjj |y)zF Test if an invalid version raises InvalidProxyError. rr Nr-r#s rtest_invalidVersionz!V2ParserTests.test_invalidVersion1!0      $ $  rcztd}|jttjj |y)zF Test if an invalid command raises InvalidProxyError. #r1Nr-r#s rtest_invalidCommandz!V2ParserTests.test_invalidCommandr3rcztd}|jttjj |y)zE Test if an invalid family raises InvalidProxyError. @r Nr-r#s rtest_invalidFamilyz V2ParserTests.test_invalidFamily1!'2      $ $  rcztd}|jttjj |y)zG Test if an invalid protocol raises InvalidProxyError. $r9Nr-r#s rtest_invalidProtozV2ParserTests.test_invalidProtor;rctd}tjj|}|j |j |j |j y)zU Test that local does not return endpoint data for IPv4 connections.  r1Nrrr!r" assertFalsesource destinationr$r%infos rtest_localCommandIpv4z#V2ParserTests.test_localCommandIpv4J!0!!''/ % ))*rctd}tjj|}|j |j |j |j y)zU Test that local does not return endpoint data for IPv6 connections. r@r1Nrrr!r"rBrCrDrEs rtest_localCommandIpv6z#V2ParserTests.test_localCommandIpv6rHrctd}tjj|}|j |j |j |j y)zU Test that local does not return endpoint data for UNIX connections. r@r1Nrrr!r"rBrCrDrEs rtest_localCommandUnixz#V2ParserTests.test_localCommandUnixrHrcntd}tjj|}|j |j |j |j tj|j |j|j |jtjy)zM Test that proxy returns endpoint data for IPv4 connections. rr1N) rrr!r"r rCassertIsInstancer IPv4AddressrDrEs rtest_proxyCommandIpv4z#V2ParserTests.test_proxyCommandIpv4|!0!!''/  $ dkk7+>+>? (() d..0C0CDrcntd}tjj|}|j |j |j |j tj|j |j|j |jtjy)zM Test that proxy returns endpoint data for IPv6 connections. rr1N) rrr!r"r rCrPr IPv6AddressrDrEs rtest_proxyCommandIpv6z#V2ParserTests.test_proxyCommandIpv6rSrcntd}tjj|}|j |j |j |j tj|j |j|j |jtjy)zM Test that proxy returns endpoint data for UNIX connections. rr1N) rrr!r"r rCrPr UNIXAddressrDrEs rtest_proxyCommandUnixz#V2ParserTests.test_proxyCommandUnixrSrctd}tjj|}|j |j |j |j y)V Test that UNSPEC does not return endpoint data for IPv4 connections. r9NrArEs rtest_unspecFamilyIpv4z#V2ParserTests.test_unspecFamilyIpv4J!'2!!''/ % ))*rctd}tjj|}|j |j |j |j y)V Test that UNSPEC does not return endpoint data for IPv6 connections. r\r9NrJrEs rtest_unspecFamilyIpv6z#V2ParserTests.test_unspecFamilyIpv6r^rctd}tjj|}|j |j |j |j y)V Test that UNSPEC does not return endpoint data for UNIX connections. r\r9NrMrEs rtest_unspecFamilyUnixz#V2ParserTests.test_unspecFamilyUnix!r^rctd}tjj|}|j |j |j |j y)r[r9NrArEs rtest_unspecProtoIpv4z"V2ParserTests.test_unspecProtoIpv4*r^rctd}tjj|}|j |j |j |j y)r`r@r9NrJrEs rtest_unspecProtoIpv6z"V2ParserTests.test_unspecProtoIpv63r^rctd}tjj|}|j |j |j |j y)rc0r9NrMrEs rtest_unspecProtoUnixz"V2ParserTests.test_unspecProtoUnix<r^rcd}t|z}tj}|j|\}}|j ||j ||y)zU Test that overflow bits are preserved during feed parsing for IPv4. TEST DATA TEST DATAN)rrr!feedr assertEqualr$ testValuer%parserrFoverflows rtest_overflowIpv4zV2ParserTests.test_overflowIpv4ER2  "Y.##%V,h  9-rcd}t|z}tj}|j|\}}|j ||j ||y)zU Test that overflow bits are preserved during feed parsing for IPv6. rnN)rrr!ror rprqs rtest_overflowIpv6zV2ParserTests.test_overflowIpv6Prvrcd}t|z}tj}|j|\}}|j ||j ||y)zU Test that overflow bits are preserved during feed parsing for Unix. rnN)rrr!ror rprqs rtest_overflowUnixzV2ParserTests.test_overflowUnix[rvrcrd}tj}|jt|j|y)zK Test that an initial payload of less than 16 bytes fails. s NEEDMOREDATAN)rr!r.rro)r$rrrss rtest_segmentTooSmallz"V2ParserTests.test_segmentTooSmallfs2$ ##%   KK  r)rN)__name__ __module__ __qualname____doc__r&r)r+r/r2r6r:r>rGrKrNrRrVrYr]rardrgrirlrurxrzr|rrrrrs:::          +++ E E E++++++ . . .  rrN)rtwisted.internetr twisted.trialrr _exceptionsr V2_SIGNATUREbytesrrrTestCaserrrrrsJ%",B #1& #@ #@ #@#@ #@  #@  #@ #@N#6& #@ #@ #@#@ #@  #@  #@ #@N# #8 #8 #8#8 #8  #8 #8Ln H%%n r