Ë
    `Qbj  ã                   óš   — d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 	  G d„ de j                  «      Zedk(  r e j                  «        yy)	é    N)ÚMockÚpatch)Ú_get_resp_headers)ÚWebSocketBadStatusException)ÚSSLErrorc                   ó$   — e Zd Zd„ Zd„ Zd„ Zd„ Zy)ÚHandshakeLargeResponseTestc           	      óÌ  ‡‡— t        «       }dddz  z   Šg Šˆˆfd„}t        d«      5 }ddt        t        ‰«      «      idf|_        t        d	|¬
«      5  | j                  t        «      5 }t        |«       ddd«       | j                  dt        j                  j                  d   t        «      r'|j                  j                  d   j                  «       n|j                  j                  d   «       | j                  t        ‰«      d«       | j                  t        d„ ‰D «       «      «       ddd«       ddd«       y# 1 sw Y   ŒÍxY w# 1 sw Y   ŒxY w# 1 sw Y   yxY w)zHTest that large HTTP error responses during handshake are read in chunkss   Error details: ó   Ai N  c                 óP   •— ‰j                  |«       |dkD  rt        d«      ‚‰d | S )Né @  z[SSL: BAD_LENGTH] unknown error)Úappendr   )ÚsockÚbufsizeÚlarge_responseÚ
recv_callss     €€ú`/var/www/html/venv/lib/python3.12/site-packages/websocket/tests/test_handshake_large_response.pyÚ	mock_recvzWHandshakeLargeResponseTest.test_large_error_response_chunked_reading.<locals>.mock_recv)   s1   ø€ Ø×Ñ˜gÔ&à˜ŠÜÐ@ÓAÐAØ! ( 7Ð+Ð+ó    ú!websocket._handshake.read_headersi�  úcontent-lengthzBad Requestúwebsocket._socket.recv©Úside_effectNs   Error details:r   é   c              3   ó&   K  — | ]	  }|d k  –— Œ y­w)r   N© )Ú.0Úcalls     r   ú	<genexpr>zWHandshakeLargeResponseTest.test_large_error_response_chunked_reading.<locals>.<genexpr>J   s   è ø€ Ò#I°d D¨E¥MÑ#Iùs   ‚)r   r   ÚstrÚlenÚreturn_valueÚassertRaisesr   r   ÚassertInÚ
isinstanceÚ	exceptionÚargsÚencodeÚassertGreaterÚ
assertTrueÚall)ÚselfÚ	mock_sockr   Úmock_read_headersÚcmr   r   s        @@r   Ú)test_large_error_response_chunked_readingzDHandshakeLargeResponseTest.test_large_error_response_chunked_reading   sT  ù€ ô “Fˆ	ð ,¨d°U©lÑ:ˆð ˆ
õ	,ô Ð6Ó7ð 	KÐ;LàØ!¤3¤s¨>Ó':Ó#;Ð<Øð.ÐÔ*ô Ð/¸YÔGñ Kà×&Ñ&Ô'BÓCð 1ÀrÜ% iÔ0÷1ð —‘Ø%ô & b§l¡l×&7Ñ&7¸Ñ&:¼CÔ@ð Ÿ™×)Ñ)¨!Ñ,×3Ñ3Ô5àŸ\™\×.Ñ.¨qÑ1ôð ×"Ñ"¤3 z£?°AÔ6Ø—‘¤Ñ#I¸jÔ#IÓ IÔJ÷#K÷	Kð 	K÷1ð 1ú÷Kð Kú÷	Kð 	Kús<   ¨,EÁEÁ*EÁ6B;EÄ1EÅEÅEÅE	ÅEÅE#c                 ó®  ‡‡— t        «       }ddz  ŠdŠˆˆfd„}t        d«      5 }ddt        t        ‰«      «      idf|_        t        d	|¬
«      5  | j                  t        «      5 }t        |«       ddd«       t        j                  «      }| j                  d|«       ddd«       ddd«       y# 1 sw Y   ŒAxY w# 1 sw Y   ŒxY w# 1 sw Y   yxY w)zATest that the fix prevents SSL BAD_LENGTH errors during handshakeó   Xi €  r   c                 óf   •— ‰dz  }t        ||z   t        ‰«      «      }‰|| }‰|rdz  Š|S dz  Š|S )Nr   r   r   )Úminr"   )r   r   Úchunk_startÚ	chunk_endÚresultÚchunks_returnedÚlarge_contents        €€r   Úmock_recv_chunkedzbHandshakeLargeResponseTest.test_handshake_ssl_large_response_protection.<locals>.mock_recv_chunkedV   sQ   ø€ ð *¨EÑ1ˆKÜ˜K¨'Ñ1´3°}Ó3EÓFˆIØ" ;¨yÐ9ˆFØ¡F˜qÑ1ˆOØˆMð 12Ñ1ˆOØˆMr   r   iô  r   zInternal Server Errorr   r   NÚXXXXX)
r   r   r!   r"   r#   r$   r   r   r'   r%   )r-   r.   r;   r/   r0   Úexception_strr9   r:   s         @@r   Ú,test_handshake_ssl_large_response_protectionzGHandshakeLargeResponseTest.test_handshake_ssl_large_response_protectionL   sÛ   ù€ ô “Fˆ	ð ˜u™ˆàˆõ	ô Ð6Ó7ð 	6Ð;LàØ!¤3¤s¨=Ó'9Ó#:Ð;Ø'ð.ÐÔ*ô Ð/Ð=NÔOñ 6à×&Ñ&Ô'BÓCð 1ÀrÜ% iÔ0÷1ô !$ B§L¡LÓ 1�à—‘˜g }Ô5÷6÷	6ð 	6÷1ð 1ú÷6ð 6ú÷	6ð 	6ús;   ¥,CÁB?Á'B3Á3/B?Â"CÂ3B<Â8B?Â?C	ÃCÃCc                 óœ  ‡— t        «       }dŠˆfd„}t        d«      5 }ddt        t        ‰«      «      idf|_        t        d|¬«      5  | j                  t        «      5 }t        |«       d	d	d	«       | j                  d
t        j                  «      «       d	d	d	«       d	d	d	«       y	# 1 sw Y   Œ?xY w# 1 sw Y   ŒxY w# 1 sw Y   y	xY w)z5Test that normal small responses still work correctlys   Small error messagec                 ó   •— ‰S )Nr   )r   r   Úsmall_responses     €r   r   zRHandshakeLargeResponseTest.test_handshake_normal_small_response.<locals>.mock_recvv   s	   ø€ Ø!Ð!r   r   i”  r   z	Not Foundr   r   NzSmall error message)
r   r   r!   r"   r#   r$   r   r   r%   r'   )r-   r.   r   r/   r0   rA   s        @r   Ú$test_handshake_normal_small_responsez?HandshakeLargeResponseTest.test_handshake_normal_small_responsep   sÔ   ø€ ô “Fˆ	Ø/ˆô	"ô Ð6Ó7ð 	HÐ;LàØ!¤3¤s¨>Ó':Ó#;Ð<Øð.ÐÔ*ô Ð/¸YÔGñ HØ×&Ñ&Ô'BÓCð 1ÀrÜ% iÔ0÷1ð —‘Ð3´S¸¿¹Ó5FÔG÷H÷	Hð 	H÷1ð 1ú÷Hð Hú÷	Hð 	Hús;   ž,CÁ
B6Á B*Á,-B6ÂCÂ*B3Â/B6Â6B?	Â;CÃCc                 óH  — t        «       }t        d«      5 }di df|_        | j                  t        «      5 }t        |«       ddd«       t        j                  «      }| j                  d|«       | j                  d|«       ddd«       y# 1 sw Y   ŒKxY w# 1 sw Y   yxY w)z;Test handshake error response without content-length headerr   i“  Ú	ForbiddenNÚ403)	r   r   r#   r$   r   r   r!   r'   r%   )r-   r.   r/   r0   r=   s        r   Ú test_handshake_no_content_lengthz;HandshakeLargeResponseTest.test_handshake_no_content_length‡   s¡   € ô “Fˆ	äÐ6Ó7ð 	6Ð;LàØØð.ÐÔ*ð ×"Ñ"Ô#>Ó?ð -À2Ü! )Ô,÷-ô   §¡Ó-ˆMØ�M‰M˜% Ô/Ø�M‰M˜+ }Ô5÷	6ð 	6÷-ð -ú÷	6ð 	6ús#   – B¶BÁABÂB	ÂBÂB!N)Ú__name__Ú
__module__Ú__qualname__r1   r>   rB   rF   r   r   r   r	   r	      s   „ ò-Kò^"6òHHó.6r   r	   Ú__main__)ÚunittestÚunittest.mockr   r   Úwebsocket._handshaker   Úwebsocket._exceptionsr   Úwebsocket._ssl_compatr   ÚTestCaser	   rG   Úmainr   r   r   ú<module>rR      sH   ðã ß %å 2Ý =Ý *ðô&~6 ×!2Ñ!2ô ~6ðB ˆzÒØ€H‡M�M…Oð r   