Ë
    #ïàj`:  ã                   óV  — d Z ddlZddlZddlZddlZddlmZ dZdZ	dZ
dZdZd	Zd
„ Z G d„ d«      Z G d„ dej                   «      Zd>d„Zej&                  d„ «       Zej&                  d„ «       Zej&                  d„ «       Zej&                  d„ «       Zd„ Zd„ Zd„ Zej6                  j9                  ddd dj:                   eej>                  j@                  d«      Ž f«      d„ «       Z!d„ Z"d„ Z#ej6                  j9                  dd«      d „ «       Z$d!„ Z%d"„ Z&d#„ Z'd$„ Z(d%„ Z)ej6                  jU                  d&d'¬(«      d)„ «       Z+ej6                  j9                  d*d+ed,fd-ed.fd/ed0fd1ed2ff«      d3„ «       Z,d4„ Z-d5„ Z.d6„ Z/d7„ Z0 G d8„ d9«      Z1 G d:„ d;«      Z2ej&                  d<„ «       Z3d=„ Z4y)?z9Tests for managing HTTP issues (malformed requests, etc).é    N)Úhelperi�  i›  i”  i�  éÈ   iù  c                 óB   — | j                  d«      j                  d«      S )z¤Encode PATH_INFO correctly depending on Python version.

    WSGI 1.0 is a mess around Unicode. Create endpoints
    that match the PATH_INFO that it produces.
    úutf-8úlatin-1)ÚencodeÚdecode)Ústrings    úE/srv/dav/.venv/lib/python3.12/site-packages/cheroot/test/test_core.pyÚ_munger      s   € ð �=‰=˜Ó!×(Ñ(¨Ó3Ð3ó    c                   óP   — e Zd ZdZed„ «       Zed„ «       Zed„ «       Zed„ «       Zy)ÚWSGICallablesú!Controller for serving WSGI apps.c                  ó   — y)zRender Hello world.úHello world!© ©ÚreqÚresps     r   ÚhellozWSGICallables.hello    s   € ð r   c                 óL   — | j                   j                  dd«      €d|_        yy)zRender Hello world or set 411.úContent-LengthNz411 Length Requiredr   )ÚenvironÚgetÚstatusr   s     r   Úbody_requiredzWSGICallables.body_required%   s'   € ð �;‰;�?‰?Ð+¨TÓ2Ð:Ø/ˆDŒKØØr   c                 ó:   — | j                   j                  dd«      S )zRender QUERY_STRING value.ÚQUERY_STRINGÚ ©r   r   r   s     r   Úquery_stringzWSGICallables.query_string-   s   € ð �{‰{�‰˜~¨rÓ2Ð2r   c                 óF   — | j                   j                  dd«      }d|› d�S )zRender request method value.ÚREQUEST_METHODzNO METHOD FOUNDzGot asterisk URI path with z methodr!   )r   r   Úmethods      r   ÚasteriskzWSGICallables.asterisk2   s)   € ð —‘—‘Ð!1Ð3DÓEˆØ,¨V¨H°GÐ<Ð<r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r"   r&   r   r   r   r   r      sS   „ Ù+àñó ðð ñó ðð ñ3ó ð3ð ñ=ó ñ=r   r   c                   óì   — e Zd ZdZdej
                  dej
                  dej                  dej                   ed«      ej
                   ed«      ej
                  dej
                  d	ej                  iZ
y
)ÚHelloControllerr   ú/helloú/no_bodyú/body_requiredz/query_stringu   /Ð¿Ñ€Ð¸Ð²Ñ–Ñ‚u   /Ð®Ñ…Ñ…ÑƒÑƒÑƒõ   /Â Ã�blah key 0 900 4 dataz/*N)r'   r(   r)   r*   r   r   r   r"   r   r&   Úhandlersr   r   r   r-   r-   :   sr   „ Ù+ð 	�-×%Ñ%Ø�M×'Ñ'Ø˜-×5Ñ5Ø˜×3Ñ3ñ 	ˆÓ ×!4Ñ!4áˆÓ ×!4Ñ!4Ø&¨×(;Ñ(;Øˆm×$Ñ$ð�Hr   r-   c                 ó<   — | j                  | j                  |¬«      S )N©r%   )Úresponse_classÚsock)Ú
connectionr%   s     r   Ú_get_http_responser8   O   s   € Ø×$Ñ$ Z§_¡_¸VÐ$ÓDÐDr   c                 óX   — | j                   }t        «       |_        d|_        | |_        |S ©ú:Attach a WSGI app to the given server and preconfigure it.i€ÃÉ)Úserver_instancer-   Úwsgi_appÚmax_request_body_sizeÚserver_client©Úwsgi_server_clientÚwsgi_servers     r   Útesting_serverrC   S   ó0   € ð %×4Ñ4€KÜ*Ó,€KÔØ(0€KÔ%Ø 2€KÔØÐr   c                 ó   — | j                   S ©z5Get and return a test client out of the given server.©r?   )rC   s    r   Útest_clientrH   ]   s   € ð ×'Ñ'Ð'r   c                 óJ   — | j                   }t        «       |_        | |_        |S )r;   )r<   r-   r=   r?   r@   s     r   Útesting_server_with_defaultsrJ   c   s(   € ð %×4Ñ4€KÜ*Ó,€KÔØ 2€KÔØÐr   c                 ó   — | j                   S rF   rG   )rJ   s    r   Útest_client_with_defaultsrL   l   s   € ð (×5Ñ5Ð5r   c                 óV   — | j                  d«      d   }t        |dd «      }|dk(  sJ ‚y)z>Check that CONNECT query results in Method Not Allowed status.z	/anythingr   Né   i•  )ÚconnectÚint)rH   Ústatus_lineÚactual_statuss      r   Útest_http_connect_requestrS   r   s5   € à×%Ñ% kÓ2°1Ñ5€KÜ˜ B Q˜Ó(€MØ˜CÒÐÑr   c                 ón   — | j                  d«      \  }}}t        |dd «      }|t        k(  sJ ‚|dk(  sJ ‚y)z%Check that normal GET query succeeds.r.   NrN   ó   Hello world!©r   rP   ÚHTTP_OK©rH   rQ   Ú_Úactual_resp_bodyrR   s        r   Útest_normal_requestr[   y   sD   € à'2§¡°xÓ'@Ñ$€K�Ð$Ü˜ B Q˜Ó(€MØœGÒ#Ð#Ð#Ø˜Ò.Ð.Ñ.r   c                 ón   — | j                  d«      \  }}}t        |dd «      }|t        k(  sJ ‚|dk(  sJ ‚y)z(Check that GET parameter is parsed well.ú/query_string?test=TrueNrN   s	   test=TruerV   rX   s        r   Útest_query_string_requestr^   �   sI   € à'2§¡Ø!ó(Ñ$€K�Ð$ô ˜ B Q˜Ó(€MØœGÒ#Ð#Ð#Ø˜|Ò+Ð+Ñ+r   Úurir.   r]   z/{0}?{1}={2})u   Ð®Ñ…Ñ…ÑƒÑƒÑƒu   Ñ—u   Ð¹Ð¾c                 ó^   — | j                  |«      d   }t        |dd «      }|t        k(  sJ ‚y)z8Check that server responds with OK to valid GET queries.r   NrN   rV   )rH   r_   rQ   rR   s       r   Útest_parse_acceptable_urira   ‹   s5   € ð —/‘/ #Ó& qÑ)€KÜ˜ B Q˜Ó(€MØœGÒ#Ð#Ñ#r   c                 óÖ  — | j                  «       }dj                  d«      }t        j                  j	                  |«      }|dk(  sJ ‚ dj
                  di t        «       ¤Ž}|j                  |j                  d«      «       |j                  «        t        |d¬«      }|j                  «        |j                  t        k(  sJ ‚|j                  d«      d	k(  sJ ‚|j                  «        y
)a#  Test that malicious URI does not allow HTTP injection.

    This effectively checks that sending GET request with URL

    /%A0%D0blah%20key%200%20900%204%20data

    is not converted into

    GET /
    blah key 0 900 4 data
    HTTP/1.1

    which would be a security issue otherwise.
    r1   r   z&/%A0%D0blah%20key%200%20900%204%20datazGET {quoted} HTTP/1.1r   ÚGETr4   é   rU   Nr   )Úget_connectionr   ÚurllibÚparseÚquoteÚformatÚlocalsÚ_outputÚ_send_outputr8   Úbeginr   rW   ÚreadÚclose)rH   ÚcÚresourceÚquotedÚrequestÚresponses         r   Útest_parse_uri_unsafe_uriru   œ   sÄ   € ð 	×"Ñ"Ó$€AØ-×4Ñ4°YÓ?€HÜ�\‰\×Ñ Ó)€FØÐ=Ò=Ð=Ð=Ø,Ð%×,Ñ,Ñ8¬v«xÑ8€GØ‡I�Iˆg�n‰n˜WÓ%Ô&Ø‡N�NÔÜ! !¨EÔ2€HØ‡N�NÔØ�?‰?œgÒ%Ð%Ð%Ø�=‰=˜Ó Ò/Ð/Ð/Ø‡G�G…Ir   c                 ó2  — | j                  «       }|j                  dj                  «       «       |j                  «        t	        |d¬«      }|j                  «        |j                  t        k(  sJ ‚|j                  d«      dk(  sJ ‚|j                  «        y)zŽCheck that server responds with Bad Request to invalid GET queries.

    Invalid request line test case: it should only contain US-ASCII.
    u   GET /Ð¹Ð¾Ð¿Ñ‚Ð°! HTTP/1.1rc   r4   é   s   Malformed Request-URIN)
re   rk   r   rl   r8   rm   r   ÚHTTP_BAD_REQUESTrn   ro   )rH   rp   rt   s      r   Útest_parse_uri_invalid_uriry   ¹   s|   € ð
 	×"Ñ"Ó$€AØ‡I�IÐ)×0Ñ0Ó2Ô3Ø‡N�NÔÜ! !¨EÔ2€HØ‡N�NÔØ�?‰?Ô.Ò.Ð.Ð.Ø�=‰=˜ÓÐ 8Ò8Ð8Ð8Ø‡G�G…Ir   )r   u   Ð¿Ñ€Ð¸Ð²Ñ–Ñ‚c                 ó¦   — | j                  t        j                  j                  |«      «      \  }}}t	        |dd «      }|t
        k(  sJ ‚d|v sJ ‚y)z™Check that server responds with Bad Request to invalid GET queries.

    Invalid request line test case: it should have leading slash (be absolute).
    NrN   s   starting with a slash)r   rf   rg   rh   rP   rx   )rH   r_   rQ   rY   rZ   rR   s         r   Ú#test_parse_no_leading_slash_invalidr{   È   s\   € ð (3§¡Ü�‰×Ñ˜3Óó(Ñ$€K�Ð$ô ˜ B Q˜Ó(€MØÔ,Ò,Ð,Ð,Ø#Ð'7Ñ7Ð7Ñ7r   c                 ór   — | j                  d«      \  }}}t        |dd «      }|t        k(  sJ ‚d}||k(  sJ ‚y)zlCheck that server responds with Bad Request to Absolute URI.

    Only proxy servers should allow this.
    zhttp://google.com/NrN   s2   Absolute URI not allowed if server is not a proxy.©r   rP   rx   ©rH   rQ   rY   rZ   rR   Úexpected_bodys         r   Útest_parse_uri_absolute_urir€   Ü   sM   € ð
 (3§¡Ð7KÓ'LÑ$€K�Ð$Ü˜ B Q˜Ó(€MØÔ,Ò,Ð,Ð,ØI€MØ˜}Ò,Ð,Ñ,r   c                 ór   — | j                  d«      \  }}}t        |dd «      }|t        k(  sJ ‚d}||k(  sJ ‚y)zDCheck that server responds with OK to OPTIONS with "*" Absolute URI.Ú*NrN   s)   Got asterisk URI path with OPTIONS method)ÚoptionsrP   rW   r~   s         r   Útest_parse_uri_asterisk_urir„   è   sK   € à'2×':Ñ':¸3Ó'?Ñ$€K�Ð$Ü˜ B Q˜Ó(€MØœGÒ#Ð#Ð#Ø@€MØ˜}Ò,Ð,Ñ,r   c                 ór   — | j                  d«      \  }}}t        |dd «      }|t        k(  sJ ‚d}||k(  sJ ‚y)zACheck that server responds with Bad Request to URI with fragment.z/hello?test=something#fakeNrN   s!   Illegal #fragment in Request-URI.r}   r~   s         r   Útest_parse_uri_fragment_urir†   ñ   sO   € à'2§¡Ø$ó(Ñ$€K�Ð$ô ˜ B Q˜Ó(€MØÔ,Ò,Ð,Ð,Ø8€MØ˜}Ò,Ð,Ñ,r   c                 óä   — | j                  «       }|j                  dd«       |j                  «       }|j                  «       }|j                  }|t
        k(  sJ ‚|dk(  sJ ‚|j                  «        y)z4Test POST query with an empty body being successful.ÚPOSTr/   rU   N)re   rs   Úgetresponsern   r   rW   ro   )rH   rp   rt   rZ   rR   s        r   Útest_no_content_lengthrŠ   ü   se   € ð 	×"Ñ"Ó$€AØ‡I�Iˆf�jÔ!Ø�}‰}‹€HØ—}‘}“ÐØ—O‘O€MØœGÒ#Ð#Ð#Ø˜Ò.Ð.Ð.à‡G�G…Ir   c                 óÖ   — | j                  «       }|j                  dd«       |j                  «       }|j                  «        |j                  }|t
        k(  sJ ‚|j                  «        y)zDTest POST query with body failing because of missing Content-Length.rˆ   r0   N)re   rs   r‰   rn   r   ÚHTTP_LENGTH_REQUIREDro   )rH   rp   rt   rR   s       r   Útest_content_length_requiredr�     sV   € ð 	×"Ñ"Ó$€AØ‡I�IˆfÐ&Ô'Ø�}‰}‹€HØ‡M�M„Oà—O‘O€MØÔ0Ò0Ð0Ð0à‡G�G…Ir   z.https://github.com/cherrypy/cheroot/issues/106F)ÚreasonÚstrictc                 óì   — | j                  «       }|j                  dd«       |j                  dt        d«      «       |j	                  «        |j                  «       }|j                  }|t        k(  sJ ‚y)z5Test GET query with maliciously large Content-Length.rc   r.   r   l            N)re   Ú
putrequestÚ	putheaderÚstrÚ
endheadersr‰   r   ÚHTTP_REQUEST_ENTITY_TOO_LARGE)rL   rp   rt   rR   s       r   Útest_large_requestr–     s_   € ð 	"×0Ñ0Ó2€AØ‡L�L�˜Ô!Ø‡K�KÐ ¤# e£*Ô-Ø‡L�L„Nà�}‰}‹€HØ—O‘O€MàÔ9Ò9Ð9Ñ9r   )Úrequest_lineÚstatus_coder   s   GET /ó   Malformed Request-Lines   GET / HTTPS/1.1s$   Malformed Request-Line: bad protocols   GET / HTTP/1s#   Malformed Request-Line: bad versions   GET / HTTP/2.15s   Cannot fulfill requestc                 ó   — | j                  «       }|j                  |«       |j                  «        t        |d¬«      }|j	                  «        |j
                  |k(  sJ ‚|j                  t        |«      «      |k(  sJ ‚|j                  «        y)z5Test missing or invalid HTTP version in Request-Line.rc   r4   N)	re   rk   rl   r8   rm   r   rn   Úlenro   )rH   r—   r˜   r   rp   rt   s         r   Útest_malformed_request_linerœ   5  sv   € ð@ 	×"Ñ"Ó$€AØ‡I�IˆlÔØ‡N�NÔÜ! !¨EÔ2€HØ‡N�NÔØ�?‰?˜kÒ)Ð)Ð)Ø�=‰=œ˜]Ó+Ó,°Ò=Ð=Ð=Ø‡G�G…Ir   c                 ó*  — | j                  «       }|j                  dd«       |j                  dd«       |j                  «        |j	                  «       }|j
                  }|t        k(  sJ ‚|j                  d«      }|dk(  sJ ‚|j                  «        y)zTest non-uppercase HTTP method.ÚGeTz/malformed_method_caseúContent-Typeú
text/plainrw   s   Malformed method nameN)	re   r‘   r’   r”   r‰   r   rx   rn   ro   ©rH   rp   rt   rR   rZ   s        r   Útest_malformed_http_methodr¢   _  s€   € à×"Ñ"Ó$€AØ‡L�L�Ð0Ô1Ø‡K�K� Ô-Ø‡L�L„Nà�}‰}‹€HØ—O‘O€MØÔ,Ò,Ð,Ð,Ø—}‘} RÓ(ÐØÐ7Ò7Ð7Ð7à‡G�G…Ir   c                 óL  — | j                  «       }|j                  dd«       |j                  dd«       |j                  d«       |j	                  «        |j                  «       }|j                  }|t        k(  sJ ‚|j                  d«      }|dk(  sJ ‚|j                  «        y)	z5Check that broken HTTP header results in Bad Request.rc   ú/rŸ   r    s   Re, 1.2.3.4#015#012é   s   Illegal header line.N)
re   r‘   r’   rk   r”   r‰   r   rx   rn   ro   r¡   s        r   Útest_malformed_headerr¦   o  sŒ   € à×"Ñ"Ó$€AØ‡L�L�˜ÔØ‡K�K� Ô-à‡I�IÐ$Ô%Ø‡L�L„Nà�}‰}‹€HØ—O‘O€MØÔ,Ò,Ð,Ð,Ø—}‘} RÓ(ÐØÐ6Ò6Ð6Ð6à‡G�G…Ir   c                 ód   — d}t        d|z  «      dk(  sJ ‚| j                  |«      d   }|dk(  sJ ‚y)z?Check that HTTP request line of exactly 256 chars length is OK.zñ/hello?intervenant-entreprise-evenement_classaction=evenement-mailremerciements&_path=intervenant-entreprise-evenement&intervenant-entreprise-evenement_action-id=19404&intervenant-entreprise-evenement_id=19404&intervenant-entreprise_id=28092zGET %s HTTP/1.1
é   é   rU   N)r›   r   )rH   ÚRequest_URIrZ   s      r   Ú"test_request_line_split_issue_1220r«   �  sI   € ð	+ð ô Ð$ {Ñ2Ó3°sÒ:Ð:Ð:à"—‘ {Ó3°AÑ6ÐØ˜Ò.Ð.Ñ.r   c                 ó¼  — | j                  «       }|j                  d«       |j                  «        |j                  |j                  d¬«      }	 |j                  «        |j                  }|t        k(  sJ ‚|j                  d«      }|dk(  sJ ‚|j                  «        y# t        j                  $ r(}|j                  t        j                  k7  r‚ Y d}~yd}~ww xY w)z>Test that server sends an error for garbage received over TCP.s   gjkgjklsgjklsgjkljklsgrc   r4   é   r™   N)re   rk   rl   r5   r6   rm   r   rx   rn   ro   ÚsocketÚerrorÚerrnoÚ
ECONNRESET)rH   rp   rt   rR   rZ   Úexs         r   Útest_garbage_inr³   ’  s¾   € ð 	×"Ñ"Ó$€AØ‡I�IÐ'Ô(Ø‡N�NÔØ×Ñ §¡¨uÐÓ5€Hð
Ø�‰ÔØ Ÿ™ˆØÔ 0Ò0Ð0Ð0Ø#Ÿ=™=¨Ó,ÐØÐ#<Ò<Ð<Ð<Ø	�‰�	øÜ�<‰<ò à�8‰8”u×'Ñ'Ò'Øô (ûðús   ÁAB  Â CÂ3CÃCc                   ó   — e Zd ZdZd„ Zd„ Zy)ÚCloseControllerz*Controller for testing the close callback.c                 ó¼   — |j                   j                  | _        t        | j                  «      } ||j                  |j
                  j                  «       «       |S )z'Get the req to know header sent status.)Ú__self__r   ÚCloseResponsero   r   ÚheadersÚitems)Úselfr   Ústart_responser   s       r   Ú__call__zCloseController.__call__ª  sC   € à!×*Ñ*×.Ñ.ˆŒÜ˜TŸZ™ZÓ(ˆÙ�t—{‘{ D§L¡L×$6Ñ$6Ó$8Ô9Øˆr   c                 ó:   — | j                   j                  d«       y)zClose, writing hello.ó   helloN)r   Úwrite©r»   s    r   ro   zCloseController.close±  s   € à�‰�‰�xÕ r   N)r'   r(   r)   r*   r½   ro   r   r   r   rµ   rµ   §  s   „ Ù4òó!r   rµ   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)r¸   z3Dummy empty response to trigger the no body status.c                 ó2   — d| _         ddi| _        || _        y)z-Use some defaults to ensure we have a header.z200 OKrŸ   z	text/htmlN)r   r¹   ro   )r»   ro   s     r   Ú__init__zCloseResponse.__init__¹  s   € àˆŒØ&¨Ð4ˆŒØˆ�
r   c                 ó   — t         ‚)zEnsure we don't have a body.)Ú
IndexError)r»   Úindexs     r   Ú__getitem__zCloseResponse.__getitem__¿  s   € äÐr   c                 ó   — | S )z%Return self to hook the close method.r   rÁ   s    r   ÚoutputzCloseResponse.outputÃ  s   € àˆr   N)r'   r(   r)   r*   rÄ   rÈ   rÊ   r   r   r   r¸   r¸   ¶  s   „ Ù=òòór   r¸   c                 óX   — | j                   }t        «       |_        d|_        | |_        |S r:   )r<   rµ   r=   r>   r?   r@   s     r   Útesting_server_closerÌ   È  rD   r   c                 óP   — | j                   j                  d«      \  }}}|dk(  sJ ‚y)z@Test we are actually sending the headers before calling 'close'.r¤   r¿   N)r?   r   )rÌ   rY   Ú	resp_bodys      r   Útest_send_header_before_closingrÏ   Ò  s,   € à*×8Ñ8×<Ñ<¸SÓA�O€A€qˆ)Ø˜Ò Ð Ñ r   )rc   )5r*   r°   r®   Úurllib.parserf   ÚpytestÚcheroot.testr   rx   rŒ   ÚHTTP_NOT_FOUNDr•   rW   ÚHTTP_VERSION_NOT_SUPPORTEDr   r   Ú
Controllerr-   r8   ÚfixturerC   rH   rJ   rL   rS   r[   r^   ÚmarkÚparametrizeri   Úmaprg   rh   ra   ru   ry   r{   r€   r„   r†   rŠ   r�   Úxfailr–   rœ   r¢   r¦   r«   r³   rµ   r¸   rÌ   rÏ   r   r   r   ú<module>rÛ      sS  ðÙ ?ã Û Û ã å ð Ð ØÐ Ø€Ø #Ð Ø
€Ø Ð ò4÷=ñ =ô:�f×'Ñ'ô ó*Eð ‡�ñó ðð ‡�ñ(ó ð(ð
 ‡�ñó ðð ‡�ñ6ó ð6ò
 ò/ò,ð ‡�×ÑØ	àØ!Øˆ×ÑÙ�—‘×#Ñ#Ð%CÓDð	
ðó	ñ$ó	ð$òò:ð ‡�×ÑØ	ðóñ
8óð
8ò	-ò-ò-òò$ð" ‡�×ÑØ;Øð ó ñ:ó	ð:ð$ ‡�×ÑØ4ð ØØ%ð	
ð ØØ3ð	
ð ØØ2ð	
ð Ø&Ø%ð	
ð!óñ2ó3ð2ò"ò ò$/ò"÷*!ñ !÷ñ ð$ ‡�ñó ðó!r   